Skip to content

Conversation

@lllamnyp
Copy link
Member

@lllamnyp lllamnyp commented Jul 10, 2025

What this PR does

This patch adds a new version field to the kubernetes chart, letting end-users specify the version of kubernetes they want to deploy.

Release note

[kubernetes] Let users specify desired version of tenant k8s cluster.

Summary by CodeRabbit

  • New Features
    • Added a configurable Kubernetes version parameter, allowing selection of specific minor versions for cluster deployments.
    • Introduced a version mapping system to ensure clusters use precise Kubernetes patch versions.
  • Bug Fixes
    • Ensured only supported Kubernetes versions can be selected, reducing configuration errors.
  • Documentation
    • Updated documentation to describe the new version parameter and its usage.
  • Tests
    • Enhanced end-to-end tests to cover deployments with both the latest and previous Kubernetes versions.
  • Chores
    • Consolidated version references for multiple packages to streamline version management.

@lllamnyp lllamnyp requested review from klinch0 and kvaps as code owners July 10, 2025 12:53
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 10, 2025

Walkthrough

This change updates Kubernetes app versions and introduces a new configurable version parameter with validation and mapping to full patch versions via a YAML file. It enhances Helm templates, Makefile automation, documentation, and end-to-end tests to support multiple Kubernetes minor versions dynamically.

Changes

Files/Paths Change Summary
packages/apps/kubernetes/Chart.yaml Updated chart version to 0.26.0 and app version to 1.32.6.
packages/apps/kubernetes/Makefile Added dynamic update of version enum in values.schema.json from files/versions.yaml using yq.
packages/apps/kubernetes/README.md Added new version parameter to Kubernetes cluster configuration parameters table.
packages/apps/kubernetes/templates/_versions.tpl Added Helm template helper kubernetes.versionMap to map and validate Kubernetes versions from files/versions.yaml.
packages/apps/kubernetes/templates/cluster.yaml Changed version fields to use kubernetes.versionMap helper instead of static app version.
packages/apps/kubernetes/values.schema.json, values.yaml Added version property with enum and default value for Kubernetes version.
packages/apps/kubernetes/files/versions.yaml Added YAML file mapping minor Kubernetes versions to full patch versions.
packages/apps/versions_map Updated commit references for several packages including Kubernetes 0.26.0 pointing to HEAD.
hack/e2e-apps/kubernetes.bats Refactored test into parameterized function; added tests for latest and previous Kubernetes versions; removed old test.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HelmChart
    participant _versions_tpl
    participant versions_yaml

    User->>HelmChart: Set .Values.version (e.g., v1.32)
    HelmChart->>_versions_tpl: include "kubernetes.versionMap"
    _versions_tpl->>versions_yaml: Load version map from file
    _versions_tpl-->>HelmChart: Return full patch version (e.g., v1.32.4)
    HelmChart-->>User: Deploy cluster with resolved version
Loading

Suggested labels

size:L, lgtm

Suggested reviewers

  • lllamnyp

Poem

🐇 Hop, hop, hooray! A version to choose,
From v1.28 to v1.33, no more to lose!
Mapping and tests, all neat and tight,
Kubernetes clusters now shine bright.
With a twitch of my nose, your deploys take flight! ✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b87d55 and 5b6ebbc.

📒 Files selected for processing (1)
  • packages/apps/kubernetes/templates/_versions.tpl (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/apps/kubernetes/templates/_versions.tpl

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (7)
packages/apps/kubernetes/values.yaml (1)

6-10: Consider a less generic key than version

The top-level field name version can easily be confused with the chart’s own .Chart.Version inside templates and with Helm’s built-in Version concept. A more explicit key such as kubernetesVersion would remove that ambiguity without affecting UX (end-users still type one extra word).

packages/apps/kubernetes/values.schema.json (1)

130-142: Schema update correct, but keep it DRY with Makefile/_versions.tpl

The enum/default match the values file – good. However, as pointed out in the Makefile review, maintaining the same list in three locations will quickly drift. Please refactor to source the list from a single definition.

packages/apps/kubernetes/README.md (1)

84-90: Clarify allowed values and patch-level resolution for version.

The description only states “vMAJOR.MINOR”. Because the chart silently expands that value to a full patch version through templates/_versions.tpl, users might be confused why v1.32 becomes v1.32.6, or why v1.27 is rejected.
Consider adding a short note such as:

Only v1.28v1.33 are currently supported and will automatically be resolved to the latest patch (see _versions.tpl).

This keeps the docs self-contained and avoids a support round-trip.

packages/apps/kubernetes/templates/_versions.tpl (2)

1-7: Externalise the hard-coded map to ease future upgrades.

Keeping the map inside the template means every patch bump requires editing this file, regenerating the schema enum, and bumping chart/app versions.
A tiny refactor would pull the map into values.yaml (or a dedicated values.versions.yaml) and iterate over it here. The Makefile could then read the same source of truth when regenerating the JSON schema.

Advantages:
• single place to update
• no Helm diff noise in rendered manifests
• easier to back-port security patch versions

Not blocking, but worth considering as version cadence accelerates.


3-5: Minor UX: sort supported versions in the failure message.

keys $versionMap returns a random order. A deterministic, sorted list is nicer for the user.

-{{- printf `Kubernetes version %s is not supported, allowed versions are %s` . (keys $versionMap) | fail }}
+{{- $allowed := keys $versionMap | sortAlpha }}
+{{- printf `Kubernetes version %s is not supported, allowed versions are %s` . $allowed | fail }}
packages/apps/kubernetes/templates/cluster.yaml (2)

150-155: Quote the rendered version to appease YAML/Helm linters.

Unquoted plain scalars like v1.32.6 are technically legal YAML, yet several linters flag them as ambiguous. Quoting avoids future CI noise.

-  version: {{ include "kubernetes.versionMap" $.Values.version }}
+  version: "{{ include "kubernetes.versionMap" $.Values.version }}"

289-294: Repeat the quoting fix for worker templates.

Same rationale as above – keep manifest style consistent.

-      version: {{ include "kubernetes.versionMap" $.Values.version }}
+      version: "{{ include "kubernetes.versionMap" $.Values.version }}"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b7a597 and 1434c18.

📒 Files selected for processing (8)
  • packages/apps/kubernetes/Chart.yaml (1 hunks)
  • packages/apps/kubernetes/Makefile (1 hunks)
  • packages/apps/kubernetes/README.md (1 hunks)
  • packages/apps/kubernetes/templates/_versions.tpl (1 hunks)
  • packages/apps/kubernetes/templates/cluster.yaml (2 hunks)
  • packages/apps/kubernetes/values.schema.json (1 hunks)
  • packages/apps/kubernetes/values.yaml (1 hunks)
  • packages/apps/versions_map (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/apps/kubernetes/Makefile (1)
Learnt from: NickVolynkin
PR: cozystack/cozystack#1117
File: packages/apps/mysql/Makefile:8-8
Timestamp: 2025-06-26T04:29:24.830Z
Learning: The cozystack project uses yq v4+ on their CI runner, so yq v4 syntax (-o json --indent 4) is compatible and version checks are not needed.
🔇 Additional comments (2)
packages/apps/kubernetes/Chart.yaml (1)

19-25: Chart & app version bump looks good

The semantic-version bump (0.25.0 → 0.26.0) together with the appVersion patch upgrade is consistent with the new user-visible feature. No further issues spotted here.

packages/apps/versions_map (1)

57-58: Pinned commit verified & HEAD pointer is correct
The 70f82667 commit exists in the repo (no errors from git cat-file -e). Keeping kubernetes 0.26.0 at HEAD follows our current convention—just remember to freeze it to a specific commit hash when the chart is officially released.

Comment on lines 8 to 10
readme-generator -v values.yaml -s values.schema.json -r README.md
yq -o json -i '.properties.version.enum = ["v1.28","v1.29","v1.30","v1.31","v1.32","v1.33"]' values.schema.json
yq -o json -i '.properties.addons.properties.ingressNginx.properties.exposeMethod.enum = ["Proxied","LoadBalancer"]' values.schema.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Version list duplicated in multiple places – centralise it

The hard-coded enum appears here, in values.schema.json, and again inside _versions.tpl. This triple duplication is error-prone. Instead, store the list once (e.g. in a YAML fragment or variable) and have:

  • _versions.tpl read it via required/include.
  • yq pull it from the same source when patching the schema.

Benefit: one-line change to add v1.34 in the future.

- yq -o json -i '.properties.version.enum = ["v1.28","v1.29","v1.30","v1.31","v1.32","v1.33"]' values.schema.json
+ # Example: pull enum from a dedicated file to avoid duplication
+ yq -o json -i '.properties.version.enum = load("k8s_versions.yaml")' values.schema.json

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/apps/kubernetes/Makefile around lines 8 to 10, the version list is
duplicated in the Makefile, values.schema.json, and _versions.tpl, which is
error-prone. To fix this, centralize the version list by storing it once in a
YAML fragment or variable. Modify _versions.tpl to read the version list using
required/include functions, and update the yq command in the Makefile to pull
the version enum from this centralized source instead of hardcoding it. This
will allow adding new versions by changing only one place.

Copy link
Member

@kvaps kvaps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,7 @@
{{- define "kubernetes.versionMap" }}
{{- $versionMap := dict `v1.28` `v1.28.15` `v1.29` `v1.29.15` `v1.30` `v1.30.14` `v1.31` `v1.31.10` `v1.32` `v1.32.6` `v1.33` `v1.33.2` }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It would be nice to support upgrading this via make update

@lllamnyp lllamnyp assigned lllamnyp and IvanHunters and unassigned lllamnyp and IvanHunters Jul 11, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
hack/e2e-apps/kubernetes.bats (1)

66-66: Enhanced test validation - good improvement.

The updated wait condition now properly validates that the specified version "v1.30" appears in the kamajicontrolplane status, ensuring the version selection feature is working correctly. This is a more robust test than simply checking for resource existence.

Consider adding a comment explaining what the grep is looking for, to improve test maintainability:

+  # Wait for the control plane to show the specified version
   timeout 10 sh -ec 'until kubectl get kamajicontrolplane -n tenant-test kubernetes-test | grep -q "v1.30"; do sleep 1; done'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1434c18 and b917bdd.

📒 Files selected for processing (1)
  • hack/e2e-apps/kubernetes.bats (1 hunks)
🔇 Additional comments (1)
hack/e2e-apps/kubernetes.bats (1)

63-63: LGTM! Version field addition aligns with feature requirements.

The addition of the version field with value "v1.30" correctly implements the user-selectable cluster version feature in the test manifest, following the expected vMAJOR.MINOR format.

@IvanHunters IvanHunters force-pushed the feat/selectable-k8s-version branch from b917bdd to f6cb69e Compare July 11, 2025 20:17
EOF
kubectl wait namespace tenant-test --timeout=20s --for=jsonpath='{.status.phase}'=Active
timeout 10 sh -ec 'until kubectl get kamajicontrolplane -n tenant-test kubernetes-test; do sleep 1; done'
timeout 10 sh -ec 'until kubectl get kamajicontrolplane -n tenant-test kubernetes-test | grep -q "v1.30"; do sleep 1; done'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line checks that a KamajiControlPlane was created with a specific value in the spec.version field. What's needed is a check that you have a functional Kubernetes API that reports its version as the one requested.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/apps/kubernetes/templates/_versions.tpl (1)

3-3: Consider caching the version map for better performance.

The files/versions.yaml file is loaded and parsed every time this template is called. If this template is invoked multiple times within the same chart render, this could lead to redundant file I/O operations.

Consider caching the parsed version map in a variable at the chart level or documenting that this template should only be called once per render.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6cb69e and 7ac0d9b.

📒 Files selected for processing (4)
  • packages/apps/kubernetes/Makefile (1 hunks)
  • packages/apps/kubernetes/files/versions.yaml (1 hunks)
  • packages/apps/kubernetes/templates/_versions.tpl (1 hunks)
  • packages/apps/kubernetes/templates/cluster.yaml (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/apps/kubernetes/files/versions.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/apps/kubernetes/Makefile
  • packages/apps/kubernetes/templates/cluster.yaml
🔇 Additional comments (3)
packages/apps/kubernetes/templates/_versions.tpl (3)

1-2: LGTM: Template definition and context capture.

The template definition follows Helm best practices with proper naming and context capture using the $ := . pattern.


4-6: Excellent error handling with helpful user feedback.

The validation logic properly checks for version existence and provides a clear error message that includes all available versions. This greatly improves the user experience when an invalid version is specified.


7-7: LGTM: Clean version lookup implementation.

The index function correctly retrieves the mapped version value from the version map.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
hack/e2e-apps/kubernetes-latest-version.bats (3)

4-4: Version extraction assumes ordered keys in YAML file.

The yq 'keys | .[-1]' command assumes that the keys in versions.yaml are ordered and that the last key represents the latest version. This approach is fragile if the YAML file structure changes or if keys are not semantically ordered.

Consider using a more explicit version selection approach:

-LATEST_K8S_VERSION=$(yq 'keys | .[-1]' ../packages/apps/kubernetes/files/versions.yaml)
+LATEST_K8S_VERSION=$(yq 'keys | sort_by(.) | .[-1]' ../packages/apps/kubernetes/files/versions.yaml)

Or better yet, if the versions.yaml file has a specific field for the latest version, use that instead of relying on key ordering.


93-93: Port forwarding runs in background without proper cleanup.

The port forwarding command runs in the background with a 40-second timeout, but there's no explicit cleanup of the background process. This could lead to port conflicts in subsequent test runs.

Consider adding explicit cleanup for the port forwarding process:

# Set up port forwarding to the Kubernetes API server for a 40 second timeout
-bash -c 'timeout 40s kubectl port-forward service/kubernetes-test-latest -n tenant-test '"${TEMPORAL_TENANT_PORT}"':6443 > /dev/null 2>&1 &'
+PORT_FORWARD_PID=$(bash -c 'timeout 40s kubectl port-forward service/kubernetes-test-latest -n tenant-test '"${TEMPORAL_TENANT_PORT}"':6443 > /dev/null 2>&1 & echo $!')

And add cleanup before the final resource deletion:

+# Clean up port forwarding
+kill $PORT_FORWARD_PID 2>/dev/null || true
+
# Clean up by deleting the Kubernetes resource

96-96: Version verification could be more robust.

The version verification uses grep to match the server version, but this approach might be fragile if the output format changes. Consider using more specific JSON output parsing.

-timeout 20 sh -ec 'until kubectl --kubeconfig tenantkubeconfig version 2>/dev/null | grep "Server Version: $LATEST_K8S_VERSION"; do sleep 5; done'
+timeout 20 sh -ec 'until kubectl --kubeconfig tenantkubeconfig version -o json 2>/dev/null | jq -r ".serverVersion.gitVersion" | grep -q "^$LATEST_K8S_VERSION"; do sleep 5; done'
hack/e2e-apps/kubernetes-previous-version.bats (2)

4-5: Misleading comment about version extraction.

The comment states "Get latest version of k8s from gcr" but the code actually extracts the previous version (second-to-last key) from the local versions.yaml file.

-# Get latest version of k8s from gcr
-PREVIOUS_K8S_VERSION=$(yq 'keys | .[-2]' ../packages/apps/kubernetes/files/versions.yaml)
+# Get previous version of k8s from versions.yaml
+PREVIOUS_K8S_VERSION=$(yq 'keys | .[-2]' ../packages/apps/kubernetes/files/versions.yaml)

5-5: Version extraction assumes at least two versions exist.

The yq 'keys | .[-2]' command assumes there are at least two versions in the versions.yaml file. This could fail if only one version is defined.

Consider adding validation to ensure at least two versions exist:

-PREVIOUS_K8S_VERSION=$(yq 'keys | .[-2]' ../packages/apps/kubernetes/files/versions.yaml)
+VERSION_COUNT=$(yq 'keys | length' ../packages/apps/kubernetes/files/versions.yaml)
+if [ "$VERSION_COUNT" -lt 2 ]; then
+  echo "Error: At least two versions required in versions.yaml for previous version test"
+  exit 1
+fi
+PREVIOUS_K8S_VERSION=$(yq 'keys | sort_by(.) | .[-2]' ../packages/apps/kubernetes/files/versions.yaml)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ac0d9b and 53485bc.

📒 Files selected for processing (3)
  • hack/e2e-apps/kubernetes-latest-version.bats (1 hunks)
  • hack/e2e-apps/kubernetes-previous-version.bats (1 hunks)
  • hack/e2e-apps/kubernetes.bats (0 hunks)
💤 Files with no reviewable changes (1)
  • hack/e2e-apps/kubernetes.bats

roles:
- ingress-nginx
storageClass: replicated
version: "$LATEST_K8S_VERSION"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify version variable expansion in YAML.

The version: "$LATEST_K8S_VERSION" line relies on shell variable expansion within the here-doc. Ensure this expands correctly and consider adding validation.


🏁 Script executed:

#!/bin/bash
# Verify that the version variable expansion works correctly in the YAML manifest
echo "Testing version variable expansion..."
LATEST_K8S_VERSION="v1.32.0"
echo "version: \"$LATEST_K8S_VERSION\"" | grep -E '^version: "v[0-9]+\.[0-9]+\.[0-9]+"$'

Length of output: 209


Version variable expansion verified; add validation

  • Confirmed that version: "$LATEST_K8S_VERSION" expands correctly (e.g. v1.32.0).
  • Still recommend guarding against empty or malformed values before rendering the manifest.

Suggested fix (in hack/e2e-apps/kubernetes-latest-version.bats around line 66):

# Ensure LATEST_K8S_VERSION is set and follows vMAJOR.MINOR.PATCH
if [[ -z "$LATEST_K8S_VERSION" || ! "$LATEST_K8S_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  echo "Error: LATEST_K8S_VERSION must be a non-empty semver string (got '$LATEST_K8S_VERSION')" >&2
  exit 1
fi

cat <<EOF >k8s-manifest.yaml
apiVersion: v1
kind: Pod
metadata:
  name: example
spec:
  version: "$LATEST_K8S_VERSION"
EOF

This will fail fast on invalid or missing versions.

🤖 Prompt for AI Agents
In hack/e2e-apps/kubernetes-latest-version.bats at line 66, add a validation
check before rendering the manifest to ensure the LATEST_K8S_VERSION variable is
set and matches the semantic version pattern vMAJOR.MINOR.PATCH. Implement a
conditional that exits with an error message if LATEST_K8S_VERSION is empty or
malformed, preventing the script from proceeding with invalid version data.

Comment on lines 1 to 104
#!/usr/bin/env bats

@test "Create a previous version tenant Kubernetes control plane" {
# Get latest version of k8s from gcr
PREVIOUS_K8S_VERSION=$(yq 'keys | .[-2]' ../packages/apps/kubernetes/files/versions.yaml)
TEMPORAL_TENANT_PORT=59992

kubectl apply -f - <<EOF
apiVersion: apps.cozystack.io/v1alpha1
kind: Kubernetes
metadata:
name: test-previous
namespace: tenant-test
spec:
addons:
certManager:
enabled: false
valuesOverride: {}
cilium:
valuesOverride: {}
fluxcd:
enabled: false
valuesOverride: {}
gatewayAPI:
enabled: false
gpuOperator:
enabled: false
valuesOverride: {}
ingressNginx:
enabled: true
hosts: []
valuesOverride: {}
monitoringAgents:
enabled: false
valuesOverride: {}
verticalPodAutoscaler:
valuesOverride: {}
controlPlane:
apiServer:
resources: {}
resourcesPreset: small
controllerManager:
resources: {}
resourcesPreset: micro
konnectivity:
server:
resources: {}
resourcesPreset: micro
replicas: 2
scheduler:
resources: {}
resourcesPreset: micro
host: ""
nodeGroups:
md0:
ephemeralStorage: 20Gi
gpus: []
instanceType: u1.medium
maxReplicas: 10
minReplicas: 0
resources:
cpu: ""
memory: ""
roles:
- ingress-nginx
storageClass: replicated
version: "$PREVIOUS_K8S_VERSION"
EOF
# Wait for the tenant-test namespace to be active
kubectl wait namespace tenant-test --timeout=20s --for=jsonpath='{.status.phase}'=Active

# Wait for the Kamaji control plane to be created (retry for up to 10 seconds)
timeout 10 sh -ec 'until kubectl get kamajicontrolplane -n tenant-test kubernetes-test-previous; do sleep 1; done'

# Wait for the tenant control plane to be fully created (timeout after 4 minutes)
kubectl wait --for=condition=TenantControlPlaneCreated kamajicontrolplane -n tenant-test kubernetes-test-previous --timeout=4m

# Wait for Kubernetes resources to be ready (timeout after 2 minutes)
kubectl wait tcp -n tenant-test kubernetes-test-previous --timeout=2m --for=jsonpath='{.status.kubernetesResources.version.status}'=Ready

# Wait for all required deployments to be available (timeout after 4 minutes)
kubectl wait deploy --timeout=4m --for=condition=available -n tenant-test kubernetes-test-previous kubernetes-test-previous-cluster-autoscaler kubernetes-test-previous-kccm kubernetes-test-previous-kcsi-controller

# Wait for the machine deployment to scale to 2 replicas (timeout after 1 minute)
kubectl wait machinedeployment kubernetes-test-previous-md0 -n tenant-test --timeout=1m --for=jsonpath='{.status.replicas}'=2

# Get the admin kubeconfig and save it to a file
kubectl get secret kubernetes-test-previous-admin-kubeconfig -ojsonpath='{.data.super-admin\.conf}' -n tenant-test | base64 -d > tenantkubeconfig

# Update the kubeconfig to use localhost for the API server
yq -i ".clusters[0].cluster.server = \"https://localhost:${TEMPORAL_TENANT_PORT}\"" tenantkubeconfig

# Set up port forwarding to the Kubernetes API server for a 40 second timeout
bash -c 'timeout 40s kubectl port-forward service/kubernetes-test-previous -n tenant-test '"${TEMPORAL_TENANT_PORT}"':6443 > /dev/null 2>&1 &'

# Verify the Kubernetes version matches what we expect (retry for up to 20 seconds)
timeout 20 sh -ec 'until kubectl --kubeconfig tenantkubeconfig version 2>/dev/null | grep "Server Version: $PREVIOUS_K8S_VERSION"; do sleep 5; done'

# Wait for all machine deployment replicas to be ready (timeout after 10 minutes)
kubectl wait machinedeployment kubernetes-test-previous-md0 -n tenant-test --timeout=10m --for=jsonpath='{.status.v1beta2.readyReplicas}'=2

# Clean up by deleting the Kubernetes resource
kubectl -n tenant-test delete kuberneteses.apps.cozystack.io test-previous
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Significant code duplication between test files.

Both test files contain nearly identical code with only minor differences in variable names, ports, and resource names. This makes maintenance difficult and increases the risk of inconsistencies.

Consider refactoring to use a shared function or parameterized approach:

#!/usr/bin/env bats

run_kubernetes_test() {
    local version_expr="$1"
    local test_name="$2"
    local port="$3"
    
    local k8s_version=$(yq "$version_expr" ../packages/apps/kubernetes/files/versions.yaml)
    
    # Rest of the test logic using variables
    # kubectl apply with parameterized resource name and version
    # kubectl wait commands with parameterized resource names
    # Version verification with parameterized version
    # Cleanup with parameterized resource name
}

@test "Create a tenant Kubernetes control plane with latest version" {
    run_kubernetes_test 'keys | sort_by(.) | .[-1]' 'test-latest' '59991'
}

@test "Create a tenant Kubernetes control plane with previous version" {
    run_kubernetes_test 'keys | sort_by(.) | .[-2]' 'test-previous' '59992'
}
🤖 Prompt for AI Agents
In hack/e2e-apps/kubernetes-previous-version.bats lines 1 to 104, the test code
is duplicated with only minor differences in variables like version, test name,
and port. Refactor by extracting the common logic into a reusable function that
accepts parameters for version expression, test name, and port. Replace
hardcoded values with these parameters throughout the test steps, then create
separate @test blocks that call this function with appropriate arguments for
latest and previous Kubernetes versions. This will reduce duplication and
improve maintainability.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
hack/e2e-apps/kubernetes.bats (1)

98-98: Potential shell escaping issue with version string in grep.

The version string ${k8s_version} could contain characters that have special meaning in grep patterns. Consider using grep -F (fixed string) or fgrep for literal matching.

Apply this improvement:

-  timeout 20 sh -ec 'until kubectl --kubeconfig tenantkubeconfig version 2>/dev/null | grep -q "Server Version: ${k8s_version}"; do sleep 5; done'
+  timeout 20 sh -ec 'until kubectl --kubeconfig tenantkubeconfig version 2>/dev/null | grep -Fq "Server Version: ${k8s_version}"; do sleep 5; done'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 636fb2f and be7350f.

📒 Files selected for processing (1)
  • hack/e2e-apps/kubernetes.bats (2 hunks)
🔇 Additional comments (6)
hack/e2e-apps/kubernetes.bats (6)

3-8: Function implementation looks good with proper parameter handling.

The function correctly accepts the necessary parameters and uses yq to dynamically retrieve the Kubernetes version from the versions.yaml file. The approach of using a version expression parameter allows for flexible version selection.


70-87: Comprehensive resource readiness checks implemented.

The sequential wait operations properly ensure that all components are ready before proceeding. The timeouts are reasonable and the conditions being checked are appropriate for each resource type.


88-96: Kubeconfig setup and port forwarding implemented correctly.

The approach of extracting the admin kubeconfig, modifying it for localhost access, and setting up port forwarding is sound. The 40-second timeout for port forwarding should be sufficient for the test duration.


98-98: Version verification addresses the past review comment effectively.

This implementation correctly verifies that the Kubernetes API server reports the expected version, which directly addresses the past review comment about checking for "a functional Kubernetes API that reports its version as the one requested."


108-117: Well-structured test cases with clear differentiation.

The two test cases effectively test different Kubernetes versions using descriptive names and different ports. The delimiter output helps with test result clarity.


104-104: Fix the resource name typo in cleanup.

The resource name appears to have a typo: kuberneteses.apps.cozystack.io should be kubernetes.apps.cozystack.io.

Apply this fix:

-  kubectl -n tenant-test delete kuberneteses.apps.cozystack.io $test_name
+  kubectl -n tenant-test delete kubernetes.apps.cozystack.io $test_name
⛔ Skipped due to learnings
Learnt from: lllamnyp
PR: cozystack/cozystack#1130
File: hack/e2e-apps/kubernetes.bats:101-101
Timestamp: 2025-07-11T06:11:25.438Z
Learning: In cozystack, the plural form for the Kubernetes custom resource is `kuberneteses.apps.cozystack.io`, not `kubernetes.apps.cozystack.io`. This is defined in the API schema even though it's not grammatically perfect.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (9)
packages/apps/postgres/values.yaml (2)

90-95: Remove trailing whitespace & align example indentation

Line 95 has trailing spaces flagged by yamllint and should be trimmed.
While touching the block, consider indenting the example keys two more spaces so they are siblings of cpu/memory under resources: (current comment implies that but indentation shows them as top-level).

 # resources:
-#   cpu: 4000m
-#   memory: 4Gi␠
+#   cpu: 4000m
+#   memory: 4Gi

96-97: Ensure allowed preset values are schema-validated

The comment now enumerates the permitted presets. Double-check that values.schema.json (or _helpers.tpl validation) constrains resourcesPreset to the same list to prevent typos sneaking through Helm.
If such validation does not yet exist, consider adding it.

packages/apps/mysql/values.yaml (1)

58-65: Remove trailing whitespace to satisfy YAMLlint
The blank line after the commented example (current line 63) contains stray spaces flagged by YAMLlint (trailing-spaces).

- #   memory: 4Gi␠␠
+ #   memory: 4Gi
+
.github/workflows/tags.yaml (3)

115-121: Prefer using the built-in GITHUB_TOKEN or disable credential persistence when injecting a PAT

Embedding ${GH_PAT} directly in the remote URL works, but it introduces a second long-lived secret into the workflow.
Unless you need scopes that the short-lived GITHUB_TOKEN cannot provide (e.g. pushing to protected branches), you can drop the PAT entirely and rely on GITHUB_TOKEN with the already-declared contents: write permission.

If keeping the PAT is truly required, add persist-credentials: false to the earlier actions/checkout step so the default token isn’t written to .git/config, avoiding accidental credential mix-ups:

-      - name: Checkout code
+      - name: Checkout code
         if: steps.check_release.outputs.skip == 'false'
         uses: actions/checkout@v4
         with:
           fetch-depth: 0
           fetch-tags:  true
+          persist-credentials: false   # avoid storing the default token

195-201: Duplicate git-config boilerplate – consider a reusable composite action

The user name / email configuration and the remote-URL overwrite are repeated here and in the “Commit release artifacts” step.
Encapsulating this into a small composite action (or at least a reusable YAML step via uses: ./.github/actions/git-bot-setup) removes duplication and keeps future updates in one place.


210-211: PAT scopes check

Switching the github-token input to ${{ secrets.GH_PAT }} gives the script full PAT permissions.
Double-check that the token is repository-scoped and limited to the minimal scopes required for PR creation (repo, workflow if needed) to reduce blast radius if it leaks.

packages/apps/vpn/README.md (3)

3-4: Add missing article for grammatical correctness

The phrase “deployment and management of VPN server” is missing the article “a”.

-Managed VPN Service simplifies the deployment and management of VPN server, enabling you to establish secure connections with ease.
+Managed VPN Service simplifies the deployment and management of a VPN server, enabling you to establish secure connections with ease.

6-6: Replace bare URL with a Markdown link

Stops the markdown-lint MD034 warning and keeps formatting consistent.

-- VPN client applications: https://shadowsocks5.github.io/en/download/clients.html
+- [VPN client applications](https://shadowsocks5.github.io/en/download/clients.html)

10-13: Consolidate sentences and add canonical link to Outline Server

The four short sentences read a bit staccato. Merging them, adding a link to the upstream project, and removing the redundant “Internally known as” clause improves flow and clarity.

-The VPN Service is powered by the Outline Server, an advanced and user-friendly VPN solution.
-Internally known as "Shadowbox", which simplifies the process of setting up and sharing Shadowsocks servers.
-It operates by launching Shadowsocks instances on demand.
-Furthermore, Shadowbox is compatible with standard Shadowsocks clients, providing flexibility and ease of use for your VPN requirements.
+The VPN service is powered by [Outline Server](https://github.com/Jigsaw-Code/outline-server) (internally called **Shadowbox**).  
+Shadowbox spins up Shadowsocks instances on demand and is fully compatible with any standard Shadowsocks client, giving you maximum flexibility.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66f35db and 33b6de2.

📒 Files selected for processing (63)
  • .github/workflows/pull-requests.yaml (2 hunks)
  • .github/workflows/tags.yaml (3 hunks)
  • hack/e2e-apps/kubernetes.bats (2 hunks)
  • packages/apps/clickhouse/README.md (2 hunks)
  • packages/apps/clickhouse/images/clickhouse-backup.tag (1 hunks)
  • packages/apps/clickhouse/values.schema.json (1 hunks)
  • packages/apps/clickhouse/values.yaml (1 hunks)
  • packages/apps/ferretdb/README.md (2 hunks)
  • packages/apps/ferretdb/values.schema.json (4 hunks)
  • packages/apps/ferretdb/values.yaml (4 hunks)
  • packages/apps/http-cache/README.md (2 hunks)
  • packages/apps/http-cache/images/nginx-cache.tag (1 hunks)
  • packages/apps/http-cache/values.schema.json (2 hunks)
  • packages/apps/http-cache/values.yaml (1 hunks)
  • packages/apps/kafka/README.md (1 hunks)
  • packages/apps/kafka/values.schema.json (2 hunks)
  • packages/apps/kafka/values.yaml (1 hunks)
  • packages/apps/kubernetes/Chart.yaml (1 hunks)
  • packages/apps/kubernetes/Makefile (1 hunks)
  • packages/apps/kubernetes/README.md (2 hunks)
  • packages/apps/kubernetes/files/versions.yaml (1 hunks)
  • packages/apps/kubernetes/images/cluster-autoscaler.tag (1 hunks)
  • packages/apps/kubernetes/images/kubevirt-cloud-provider.tag (1 hunks)
  • packages/apps/kubernetes/images/kubevirt-csi-driver.tag (1 hunks)
  • packages/apps/kubernetes/templates/_versions.tpl (1 hunks)
  • packages/apps/kubernetes/templates/cluster.yaml (2 hunks)
  • packages/apps/kubernetes/values.schema.json (5 hunks)
  • packages/apps/kubernetes/values.yaml (3 hunks)
  • packages/apps/mysql/README.md (3 hunks)
  • packages/apps/mysql/images/mariadb-backup.tag (1 hunks)
  • packages/apps/mysql/values.schema.json (2 hunks)
  • packages/apps/mysql/values.yaml (2 hunks)
  • packages/apps/nats/README.md (1 hunks)
  • packages/apps/nats/values.schema.json (1 hunks)
  • packages/apps/nats/values.yaml (1 hunks)
  • packages/apps/postgres/README.md (4 hunks)
  • packages/apps/postgres/values.schema.json (1 hunks)
  • packages/apps/postgres/values.yaml (1 hunks)
  • packages/apps/rabbitmq/README.md (1 hunks)
  • packages/apps/rabbitmq/values.schema.json (1 hunks)
  • packages/apps/rabbitmq/values.yaml (1 hunks)
  • packages/apps/redis/README.md (1 hunks)
  • packages/apps/redis/values.schema.json (1 hunks)
  • packages/apps/redis/values.yaml (1 hunks)
  • packages/apps/tcp-balancer/README.md (1 hunks)
  • packages/apps/tcp-balancer/values.schema.json (1 hunks)
  • packages/apps/tcp-balancer/values.yaml (1 hunks)
  • packages/apps/versions_map (1 hunks)
  • packages/apps/vpn/README.md (2 hunks)
  • packages/apps/vpn/values.schema.json (2 hunks)
  • packages/apps/vpn/values.yaml (3 hunks)
  • packages/core/installer/values.yaml (1 hunks)
  • packages/core/testing/values.yaml (1 hunks)
  • packages/extra/bootbox/images/matchbox.tag (1 hunks)
  • packages/extra/monitoring/images/grafana.tag (1 hunks)
  • packages/system/bucket/images/s3manager.tag (1 hunks)
  • packages/system/cozystack-api/values.yaml (1 hunks)
  • packages/system/cozystack-controller/values.yaml (1 hunks)
  • packages/system/dashboard/charts/kubeapps/templates/dashboard/configmap.yaml (1 hunks)
  • packages/system/dashboard/values.yaml (2 hunks)
  • packages/system/kamaji/values.yaml (1 hunks)
  • packages/system/kubeovn-webhook/values.yaml (1 hunks)
  • packages/system/kubeovn/values.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (45)
  • packages/apps/http-cache/images/nginx-cache.tag
  • packages/apps/clickhouse/images/clickhouse-backup.tag
  • .github/workflows/pull-requests.yaml
  • packages/extra/monitoring/images/grafana.tag
  • packages/system/kubeovn-webhook/values.yaml
  • packages/apps/mysql/images/mariadb-backup.tag
  • packages/system/kamaji/values.yaml
  • packages/core/testing/values.yaml
  • packages/system/dashboard/charts/kubeapps/templates/dashboard/configmap.yaml
  • packages/system/cozystack-controller/values.yaml
  • packages/apps/kubernetes/images/kubevirt-cloud-provider.tag
  • packages/extra/bootbox/images/matchbox.tag
  • packages/apps/kubernetes/images/kubevirt-csi-driver.tag
  • packages/apps/kubernetes/images/cluster-autoscaler.tag
  • packages/apps/http-cache/README.md
  • packages/core/installer/values.yaml
  • packages/apps/postgres/values.schema.json
  • packages/apps/rabbitmq/values.schema.json
  • packages/system/cozystack-api/values.yaml
  • packages/apps/tcp-balancer/values.schema.json
  • packages/apps/tcp-balancer/values.yaml
  • packages/apps/nats/values.schema.json
  • packages/system/kubeovn/values.yaml
  • packages/apps/nats/README.md
  • packages/apps/clickhouse/values.schema.json
  • packages/apps/ferretdb/values.schema.json
  • packages/apps/ferretdb/README.md
  • packages/apps/kafka/values.schema.json
  • packages/apps/kafka/README.md
  • packages/apps/http-cache/values.yaml
  • packages/apps/tcp-balancer/README.md
  • packages/apps/vpn/values.yaml
  • packages/apps/redis/README.md
  • packages/apps/postgres/README.md
  • packages/apps/rabbitmq/README.md
  • packages/apps/mysql/README.md
  • packages/apps/clickhouse/README.md
  • packages/apps/http-cache/values.schema.json
  • packages/apps/clickhouse/values.yaml
  • packages/system/bucket/images/s3manager.tag
  • packages/apps/redis/values.schema.json
  • packages/system/dashboard/values.yaml
  • packages/apps/kafka/values.yaml
  • packages/apps/vpn/values.schema.json
  • packages/apps/ferretdb/values.yaml
🚧 Files skipped from review as they are similar to previous changes (10)
  • packages/apps/versions_map
  • packages/apps/kubernetes/files/versions.yaml
  • packages/apps/kubernetes/Chart.yaml
  • packages/apps/kubernetes/templates/_versions.tpl
  • packages/apps/kubernetes/templates/cluster.yaml
  • packages/apps/kubernetes/Makefile
  • packages/apps/kubernetes/values.schema.json
  • packages/apps/kubernetes/values.yaml
  • packages/apps/kubernetes/README.md
  • hack/e2e-apps/kubernetes.bats
🧰 Additional context used
🧠 Learnings (1)
packages/apps/nats/values.yaml (1)
Learnt from: NickVolynkin
PR: cozystack/cozystack#1120
File: packages/apps/clickhouse/README.md:60-67
Timestamp: 2025-07-03T05:54:51.264Z
Learning: The `cozy-lib.resources.sanitize` function in packages/library/cozy-lib/templates/_resources.tpl supports both standard Kubernetes resource format (with limits:/requests: sections) and flat format (direct resource specifications). The flat format takes priority over nested values. CozyStack apps include cozy-lib as a chart dependency through symlinks in packages/apps/*/charts/cozy-lib directories.
🪛 YAMLlint (1.37.1)
packages/apps/mysql/values.yaml

[error] 63-63: trailing spaces

(trailing-spaces)

packages/apps/nats/values.yaml

[error] 70-70: trailing spaces

(trailing-spaces)

packages/apps/postgres/values.yaml

[error] 95-95: trailing spaces

(trailing-spaces)

packages/apps/rabbitmq/values.yaml

[error] 48-48: trailing spaces

(trailing-spaces)

packages/apps/redis/values.yaml

[error] 20-20: trailing spaces

(trailing-spaces)

🪛 markdownlint-cli2 (0.17.2)
packages/apps/vpn/README.md

6-6: Bare URL used

(MD034, no-bare-urls)

🔇 Additional comments (9)
packages/apps/nats/values.yaml (2)

65-66: Documentation tweak looks good

The re-phrased description clearly explains fallback behaviour when resources is empty. No functional impact.


71-72: Preset list clarification approved

Enumerating the allowed values without parentheses improves readability and matches other charts. 👍

packages/apps/redis/values.yaml (1)

21-22: Documentation tweak looks good

Clearer wording and the explicit enumeration of allowed preset values improves usability.

packages/apps/rabbitmq/values.yaml (2)

43-44: Clearer parameter description looks good

The re-worded comment now unambiguously explains the interaction between resources and resourcesPreset.


49-50: Confirm the preset list stays in sync with chart helpers

The allowed values list in the comment is helpful, but please double-check that the actual helper template (usually resources-preset.tpl) and schema still include the new none option and the full set shown here.

packages/apps/mysql/values.yaml (1)

40-48: Typo fix in backup description is correct
pereiodicperiodic improves documentation accuracy and consistency with other charts.

packages/apps/mysql/values.schema.json (2)

28-32: Description correction looks good
The backup.enabled description now reads “Enable periodic backups”, eliminating the typo and matching the values file.


70-78: Resource-related description improvements acknowledged
Clarifications for resources and resourcesPreset enhance user understanding; no schema changes required.

packages/apps/vpn/README.md (1)

25-25: Double-check that the default replica count matches values.yaml

The table states a default of 2 replicas. If the Helm chart’s values.yaml (or preset) still defaults to 1, this will confuse users.

Please verify and align the documentation or chart default accordingly.

# resources:
# cpu: 4000m
# memory: 4Gi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove trailing whitespace to satisfy yamllint

yamllint flags an error on this blank line due to stray spaces. Helm chart CI pipelines often treat lint failures as blocking.

-
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 48-48: trailing spaces

(trailing-spaces)

🤖 Prompt for AI Agents
In packages/apps/rabbitmq/values.yaml at line 48, remove any trailing whitespace
characters on the blank line to comply with yamllint rules and prevent linting
errors in the Helm chart CI pipeline.

lllamnyp and others added 4 commits July 15, 2025 12:48
This patch adds a new version field to the kubernetes chart, letting
end-users specify the version of kubernetes they want to deploy.

[kubernetes] Let users specify desired version of tenant k8s cluster.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
…ubectl

Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
…rabbit

Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
@IvanHunters IvanHunters force-pushed the feat/selectable-k8s-version branch from 33b6de2 to d63aac7 Compare July 15, 2025 09:54
IvanHunters and others added 6 commits July 15, 2025 12:56
Signed-off-by: IvanHunters <49371933+IvanHunters@users.noreply.github.com>
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
hack/e2e-apps/kubernetes.bats (1)

70-106: Comprehensive test implementation addressing past feedback.

The implementation addresses the previous review comment by verifying that the Kubernetes API reports the correct version (line 98). The test includes proper wait conditions, timeouts, and cleanup.

However, consider these improvements:

  1. Error handling: The test could benefit from better error handling for the port forwarding and version verification steps.
  2. Resource cleanup: Consider adding cleanup in a trap to ensure resources are cleaned up even if the test fails.
+ # Add cleanup trap
+ cleanup() {
+   kubectl -n tenant-test delete kuberneteses.apps.cozystack.io $test_name --ignore-not-found=true
+ }
+ trap cleanup EXIT
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6fdde29 and 168a9ae.

📒 Files selected for processing (2)
  • hack/e2e-apps/kubernetes.bats (2 hunks)
  • packages/apps/versions_map (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/apps/versions_map
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build
  • GitHub Check: pre-commit
🔇 Additional comments (4)
hack/e2e-apps/kubernetes.bats (4)

3-8: Good refactoring for version parameterization.

The function parameters are well-designed to support testing multiple Kubernetes versions. The use of yq with a version expression allows for flexible version selection from the YAML file.


13-13: Appropriate test name parameterization.

Using the test name parameter in the metadata ensures unique resource names for concurrent test execution.


68-68: Correct version specification implementation.

The version field now properly uses the dynamically resolved k8s_version from the versions.yaml file, enabling user-selectable cluster versions as intended.


108-113: Well-structured test cases for version validation.

The two test cases effectively validate both latest and previous Kubernetes versions with distinct names and ports to avoid conflicts. The use of yq expressions (keys | sort_by(.) | .[-1] and keys | sort_by(.) | .[-2]) is clever for dynamic version selection.

Comment on lines 2 to 15
{{- $ := . }}

{{- if not (hasKey $ "cachedVersionMap") }}
{{- $versionMap := $.Files.Get "files/versions.yaml" | fromYaml }}
{{- $_ := set $ "cachedVersionMap" $versionMap }}
{{- end }}

{{- $versionMap := $.cachedVersionMap }}

{{- if not (hasKey $versionMap $.Values.version) }}
{{- printf `Kubernetes version %s is not supported, allowed versions are %s` $.Values.version (keys $versionMap) | fail }}
{{- end }}

{{- index $versionMap $.Values.version }}
Copy link
Member Author

@lllamnyp lllamnyp Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it simple.

Suggested change
{{- $ := . }}
{{- if not (hasKey $ "cachedVersionMap") }}
{{- $versionMap := $.Files.Get "files/versions.yaml" | fromYaml }}
{{- $_ := set $ "cachedVersionMap" $versionMap }}
{{- end }}
{{- $versionMap := $.cachedVersionMap }}
{{- if not (hasKey $versionMap $.Values.version) }}
{{- printf `Kubernetes version %s is not supported, allowed versions are %s` $.Values.version (keys $versionMap) | fail }}
{{- end }}
{{- index $versionMap $.Values.version }}
{{- $versionMap := .Files.Get "files/versions.yaml" | fromYaml }}
{{- if not (hasKey $versionMap .Values.version) }}
{{- printf `Kubernetes version %s is not supported, allowed versions are %s` $.Values.version (keys $versionMap) | fail }}
{{- end }}
{{- index $versionMap .Values.version }}

@kvaps kvaps closed this Jul 16, 2025
@kvaps kvaps reopened this Jul 16, 2025
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/apps/kubernetes/templates/_versions.tpl (2)

2-2: Consider removing unnecessary empty lines for cleaner formatting.

The empty lines at lines 2 and 7 don't add significant value and could be removed for more compact formatting.

 {{- define "kubernetes.versionMap" }}
-
 {{- $versionMap := .Files.Get "files/versions.yaml" | fromYaml }}
 {{- if not (hasKey $versionMap .Values.version) }}
     {{- printf `Kubernetes version %s is not supported, allowed versions are %s` $.Values.version (keys $versionMap) | fail }}
 {{- end }}
-
 {{- index $versionMap .Values.version }}
 {{- end }}

Also applies to: 7-7


5-5: Verify the error message format for readability.

The error message concatenates the version list directly, which may not be very readable for users. Consider formatting the allowed versions as a comma-separated list.

-    {{- printf `Kubernetes version %s is not supported, allowed versions are %s` $.Values.version (keys $versionMap) | fail }}
+    {{- printf `Kubernetes version %s is not supported, allowed versions are: %s` $.Values.version (keys $versionMap | join ", ") | fail }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 168a9ae and 7b87d55.

📒 Files selected for processing (1)
  • packages/apps/kubernetes/templates/_versions.tpl (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/apps/kubernetes/templates/_versions.tpl (1)
Learnt from: lllamnyp
PR: cozystack/cozystack#1160
File: packages/system/hetzner-robotlb/charts/robotlb/templates/role.yaml:6-8
Timestamp: 2025-07-11T06:28:13.696Z
Learning: In Helm templates, the `{{-` directive chomps all leading whitespace including newlines back to the previous content, so `{{- toYaml .Values.something | nindent 2 }}` will render correctly even with apparent indentation issues. However, for better style, it's cleaner to put the template directive on the same line as the parent key (e.g., `rules: {{- toYaml .Values.serviceAccount.permissions | nindent 2 }}`).
🔇 Additional comments (1)
packages/apps/kubernetes/templates/_versions.tpl (1)

1-10: Implementation matches the suggested approach from past reviews.

The template implementation is exactly what was suggested in the past review comments and follows Helm best practices. The logic correctly:

  • Reads and parses the version mapping file
  • Validates the requested version exists
  • Provides informative error messages
  • Returns the mapped version value

Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
@lllamnyp lllamnyp merged commit f2a8c3d into main Jul 16, 2025
18 checks passed
@lllamnyp lllamnyp deleted the feat/selectable-k8s-version branch July 16, 2025 18:12
NickVolynkin added a commit that referenced this pull request Jul 17, 2025
Follow-up to #1191

Signed-off-by: Nick Volynkin <nick.volynkin@gmail.com>
kvaps added a commit that referenced this pull request Jul 17, 2025
Follow-up to #1191

Signed-off-by: Nick Volynkin <nick.volynkin@gmail.com>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Documentation**
* Updated documentation to clarify that users can select Kubernetes
patch versions ranging from 1.28 to 1.33 for tenant clusters.
* Revised descriptions and comments to explicitly specify the supported
Kubernetes version range (1.28–1.33) in relevant documentation and
configuration files.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants