Skip to content

[kubernetes] User-selectable cluster version - #1202

Closed
Timofei Larkin (lllamnyp) wants to merge 10 commits into
mainfrom
feat/select-k8s-fix-conflict
Closed

[kubernetes] User-selectable cluster version#1202
Timofei Larkin (lllamnyp) wants to merge 10 commits into
mainfrom
feat/select-k8s-fix-conflict

Conversation

@lllamnyp

@lllamnyp Timofei Larkin (lllamnyp) commented Jul 15, 2025

Copy link
Copy Markdown
Member

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 support for specifying the Kubernetes version via a new configuration parameter, with selectable versions from v1.28 to v1.33.
    • Introduced a version mapping mechanism to ensure only supported Kubernetes versions are used.
    • Updated documentation to describe the new version parameter.
    • Added a new YAML file listing supported Kubernetes versions and their patch releases.
  • Bug Fixes

    • Improved validation and error handling for unsupported Kubernetes versions during deployment.
  • Tests

    • Enhanced end-to-end tests to cover multiple Kubernetes versions using a reusable test function.
  • Chores

    • Updated Helm chart and application versions.
    • Refreshed version mappings for multiple packages.

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>
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This change introduces a version selection mechanism for the Kubernetes Helm chart, allowing users to specify the Kubernetes minor version via a new version parameter. Supporting files, documentation, and schema are updated. The Helm templates now map the selected minor version to a full patch version using a new YAML mapping and helper template. End-to-end tests and version metadata are updated accordingly.

Changes

Files / Groups Change Summary
hack/e2e-apps/kubernetes.bats Refactored test into a reusable function for versioned testing; added two tests for latest and previous Kubernetes versions.
packages/apps/kubernetes/Chart.yaml, packages/apps/versions_map Updated Helm chart and application version metadata; advanced and consolidated version mappings and commit hashes.
packages/apps/kubernetes/Makefile Enhanced schema generation to update allowed version values from the new versions YAML file.
packages/apps/kubernetes/README.md, packages/apps/kubernetes/values.yaml, packages/apps/kubernetes/values.schema.json Added and documented new version parameter for Kubernetes minor version selection; updated schema and default values.
packages/apps/kubernetes/files/versions.yaml Added YAML file mapping minor versions (e.g., v1.32) to full patch versions (e.g., v1.32.6).
packages/apps/kubernetes/templates/_versions.tpl Introduced Helm helper template to map user-specified minor version to a supported full version, with validation and error handling.
packages/apps/kubernetes/templates/cluster.yaml Modified templates to use the new version mapping helper instead of direct version references.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Helm Chart
    participant versions.yaml
    participant _versions.tpl

    User->>Helm Chart: Set .Values.version (e.g., "v1.32")
    Helm Chart->>_versions.tpl: include "kubernetes.versionMap" $
    _versions.tpl->>versions.yaml: Load version map
    _versions.tpl->>_versions.tpl: Validate .Values.version exists
    alt Version valid
        _versions.tpl-->>Helm Chart: Return mapped patch version (e.g., "v1.32.6")
        Helm Chart-->>User: Deploys resources with selected version
    else Version invalid
        _versions.tpl-->>User: Fail with error listing allowed versions
    end
Loading

Possibly related PRs

Suggested labels

enhancement, size:L, lgtm

Poem

In the garden of versions, a bunny hops,
Mapping Kubernetes from minor to tops.
With YAML and Helm, the chart’s now precise,
Pick your own version—no need to think twice!
Patch or minor, the choice is yours,
This fluffy release opens new doors.
🐰✨


📜 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 0de9a0a and 19b79b7.

📒 Files selected for processing (5)
  • packages/apps/kubernetes/Makefile (1 hunks)
  • packages/apps/kubernetes/README.md (1 hunks)
  • packages/apps/kubernetes/values.schema.json (1 hunks)
  • packages/apps/kubernetes/values.yaml (1 hunks)
  • packages/apps/versions_map (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/apps/kubernetes/Makefile
  • packages/apps/kubernetes/README.md
  • packages/apps/kubernetes/values.yaml
  • packages/apps/versions_map
  • packages/apps/kubernetes/values.schema.json
⏰ 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). (1)
  • GitHub Check: Build

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary of Changes

Hello Timofei Larkin (@lllamnyp), I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the flexibility of deploying tenant Kubernetes clusters by allowing users to specify the desired Kubernetes version. It establishes a robust version management system within the Helm chart, backed by dynamic schema generation and comprehensive E2E tests for different Kubernetes versions. This change provides better control over the deployed environment and improves test coverage.

Highlights

  • Kubernetes Version Selection: I've introduced the capability to explicitly select the Kubernetes version (e.g., v1.28, v1.32) when deploying a tenant Kubernetes cluster. This is achieved by adding a new version parameter to the Helm chart's values.yaml.
  • Centralized Version Management: A new files/versions.yaml has been added to centralize the mapping of major.minor Kubernetes versions to their specific patch versions. This file is used by the Helm chart to resolve the full version and by the Makefile to dynamically update the values.schema.json enum.
  • Enhanced E2E Testing: The E2E tests for Kubernetes cluster creation have been refactored into a reusable function and expanded to include tests for deploying clusters with both the latest and previous supported Kubernetes versions, ensuring robust validation of the new version selection mechanism.
  • Helm Chart and Application Version Updates: The Kubernetes Helm chart version has been bumped to 0.26.0, and the underlying application version (Kubernetes) has been updated to 1.32.6.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a feature to select the Kubernetes version for a tenant cluster, moving away from a hardcoded version tied to the chart's appVersion. This is achieved by introducing a versions.yaml file as the source of truth, updating Helm templates to use it, and exposing a version parameter in values.yaml.

The e2e tests have been refactored to validate this new functionality by testing both the latest and previous supported Kubernetes versions.

My review focuses on improving the robustness and correctness of the updated e2e test script, and validating the version increments in Chart.yaml.

kubectl wait machinedeployment kubernetes-${test_name}-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_name}-admin-kubeconfig -ojsonpath='{.data.super-admin\.conf}' -n tenant-test | base64 -d > tenantkubeconfig

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The test writes to a hardcoded filename tenantkubeconfig in the current directory. While bats typically runs tests sequentially, this could lead to race conditions if tests are ever configured to run in parallel. For better robustness, consider using a temporary file created with mktemp and a trap to ensure cleanup.

  local tenant_kubeconfig
  tenant_kubeconfig=$(mktemp)
  trap 'rm -f "${tenant_kubeconfig}"' RETURN

  kubectl get secret kubernetes-${test_name}-admin-kubeconfig -ojsonpath='{.data.super-admin\.conf}' -n tenant-test | base64 -d > "${tenant_kubeconfig}"
  yq -i ".clusters[0].cluster.server = \"https://localhost:${port}\"" "${tenant_kubeconfig}"

kubectl wait machinedeployment kubernetes-${test_name}-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_name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The $test_name variable is not quoted. It's a shell scripting best practice to always quote variable expansions (e.g., "${test_name}") to prevent unexpected behavior from word splitting and filename expansion (globbing), especially if the variable's value could contain spaces or special characters.

  kubectl -n tenant-test delete kuberneteses.apps.cozystack.io "${test_name}"

# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.25.2
version: 0.26.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The chart version has been incremented. Ensure that this increment follows Semantic Versioning conventions.

# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: 1.32.4
appVersion: 1.32.6

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The app version has been incremented. Verify that this increment aligns with the application's versioning scheme.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (7)
packages/apps/kubernetes/files/versions.yaml (2)

1-6: Add a brief header comment to explain how this file is consumed.

A one-liner YAML comment (e.g. # Kubernetes minor→patch version map - consumed by _versions.tpl & Makefile) will make the intent clear for future maintainers skimming the repo.


1-6: Guard against accidental unsorted or duplicate keys.

yq’s keys preserves the original order; human edits might introduce disorder or duplicates that later leak into the generated enum list.
Consider validating this file in CI (e.g. a yq + sort -u check) or load it via a helper that asserts uniqueness and ascending minor order.

packages/apps/kubernetes/Chart.yaml (1)

19-25: Automate appVersion & chart patch bumps from files/versions.yaml.

appVersion: 1.32.6 currently mirrors the mapped patch for the default v1.32.
When the mapping or default changes, humans must remember to bump both appVersion and the chart version. A tiny Go/Make task that:

  1. Reads the default from values.yaml
  2. Maps it through files/versions.yaml
  3. Updates appVersion and bumps version following SemVer rules

would prevent drift.

packages/apps/kubernetes/Makefile (1)

9-10: Unify yq CLI style for readability.

Line 9 uses -o=json, while subsequent lines use -o json. Pick one form (the dash or space) consistently to avoid cognitive noise.

-	yq -o=json -i '.properties.version.enum = (load("files/versions.yaml") | keys)' values.schema.json
+	yq -o json -i '.properties.version.enum = (load("files/versions.yaml") | keys)' values.schema.json
packages/apps/kubernetes/README.md (1)

89-90: Mention the allowed values or link to the source list.

The version row lists a default but not the valid range. Add “Allowed values: v1.28 – v1.33 (see files/versions.yaml)” so users aren’t forced to open the repo to discover supported versions.

hack/e2e-apps/kubernetes.bats (2)

89-89: Consider adding explicit cleanup for temporary files!

The function creates a tenantkubeconfig file but doesn't explicitly clean it up. While the function does clean up the Kubernetes resource, consider adding explicit cleanup for temporary files to prevent accumulation during test runs.

  # Clean up by deleting the Kubernetes resource
  kubectl -n tenant-test delete kuberneteses.apps.cozystack.io $test_name
+ 
+ # Clean up temporary files
+ rm -f tenantkubeconfig

Also applies to: 104-104


95-95: Port forwarding cleanup could be more robust!

The background port forwarding process uses a 40-second timeout but may not be reliably cleaned up if the function exits early due to failures. Consider adding a trap or explicit cleanup to ensure the background process is terminated.

+ # Set up trap to clean up port forwarding on exit
+ trap 'pkill -f "kubectl port-forward.*kubernetes-'"${test_name}"'"' EXIT
+
  # Set up port forwarding to the Kubernetes API server for a 40 second timeout
  bash -c 'timeout 40s kubectl port-forward service/kubernetes-'"${test_name}"' -n tenant-test '"${port}"':6443 > /dev/null 2>&1 &'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a619d8 and 0de9a0a.

📒 Files selected for processing (10)
  • hack/e2e-apps/kubernetes.bats (2 hunks)
  • packages/apps/kubernetes/Chart.yaml (1 hunks)
  • packages/apps/kubernetes/Makefile (1 hunks)
  • packages/apps/kubernetes/README.md (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)
  • packages/apps/kubernetes/values.schema.json (1 hunks)
  • packages/apps/kubernetes/values.yaml (1 hunks)
  • packages/apps/versions_map (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/apps/kubernetes/Makefile (2)
Learnt from: NickVolynkin
PR: cozystack/cozystack#1196
File: packages/apps/http-cache/Makefile:24-27
Timestamp: 2025-07-14T16:23:12.758Z
Learning: In the cozystack repository, the `readme-generator` tool removes enum contents from values.schema.json files during its operation. Therefore, when using readme-generator in Makefiles, any enum values need to be injected back into the schema using yq commands after readme-generator has run, not before.
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 (10)
packages/apps/kubernetes/Makefile (1)

9-9: Keys order in enum will follow YAML insertion order. Confirm that’s wanted.

(load(...) | keys) keeps original order; JSON-schema consumers treat enum as an unordered set, so order is cosmetic, but docs generated from the schema may list versions as they appear here.
If you prefer “latest first” or ascending order regardless of edit sequence, pipe through sort. Example:

... | keys | sort`
packages/apps/kubernetes/values.yaml (1)

6-11: Validate that the default minor (v1.32) always exists in files/versions.yaml.

Today it maps to v1.32.6, but if editors forget to bump values.yaml when pruning old minors the chart will break at render time.
A simple test in CI could compare values.version against the keys of files/versions.yaml.

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

130-142: Well-structured version parameter addition!

The new version property is properly defined with clear documentation, sensible defaults, and appropriate enum constraints. The vMAJOR.MINOR format is intuitive and the supported version range from v1.28 to v1.33 covers both current and future Kubernetes releases.

packages/apps/kubernetes/templates/cluster.yaml (2)

154-154: Consistent version mapping integration!

The replacement of direct Chart.AppVersion usage with the kubernetes.versionMap helper provides better version management flexibility and consistency across the cluster deployment.


293-293: Consistent version mapping in MachineDeployment!

Good consistency applying the same version mapping approach to both control plane and worker node specifications.

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

1-16: Robust version mapping template implementation!

This template helper demonstrates excellent practices:

  • Efficient caching mechanism prevents repeated file reads
  • Comprehensive validation with informative error messages
  • Clear logic flow and proper error handling
  • Well-structured template function following Helm conventions

The approach of loading versions from a YAML file and mapping them through a template provides flexible version management.

packages/apps/versions_map (2)

58-58: Appropriate version bump for Kubernetes package!

The update to version 0.26.0 HEAD correctly reflects the new version management features introduced in the Kubernetes Helm chart.


140-140: Routine version updates!

The commit hash updates for tenant, virtual-machine, and vm-instance packages appear to be standard maintenance updates.

Also applies to: 159-159, 177-177

hack/e2e-apps/kubernetes.bats (2)

3-106: Excellent test refactoring with parameterization!

The conversion to a reusable function with dynamic version selection greatly improves test maintainability and coverage. The use of yq to select versions from the versions.yaml file is clever and ensures tests stay synchronized with supported versions.


108-113: Great test coverage with multiple versions!

Testing both the latest and previous versions provides excellent coverage of the version mapping functionality. The port differentiation (59991 vs 59992) prevents conflicts when tests run concurrently.

@NickVolynkin Nick Volynkin (NickVolynkin) changed the title Feat/select k8s fix conflict Enable users to select Kubernetes versions in tenant clusters Jul 16, 2025
@kvaps Andrei Kvapil (kvaps) changed the title Enable users to select Kubernetes versions in tenant clusters [kubernetes] User-selectable cluster version Jul 16, 2025
@kvaps

Copy link
Copy Markdown
Member

Closed in favor #1191

@github-actions github-actions Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants