Skip to content

Conversation

kvaps
Copy link
Member

@kvaps kvaps commented Jul 24, 2025

Signed-off-by: Andrei Kvapil kvapss@gmail.com

What this PR does

Release note

[kubernetes] Add dependency for snapshot CRD and migration to latest version

Summary by CodeRabbit

  • New Features
    • Added a migration script to automatically update Kubernetes custom resources to app version 0.26.1 and track migration status.
  • Bug Fixes
    • Improved HelmRelease dependency management by adding a required dependency for volume snapshot CRDs.
  • Chores
    • Updated Kubernetes app version to 0.26.1.
    • Refreshed version mapping to reflect the latest release.

…version

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
@kvaps kvaps requested review from lllamnyp and klinch0 as code owners July 24, 2025 18:27
Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

Walkthrough

This change increments the Kubernetes app chart version from 0.26.0 to 0.26.1, updates the version mapping to reflect the new release, adds a dependency on the volumesnapshot CRD HelmRelease in the CSI HelmRelease template, and introduces a migration script to update custom resources to appVersion 0.26.1.

Changes

File(s) Change Summary
packages/apps/kubernetes/Chart.yaml Incremented chart version from 0.26.0 to 0.26.1.
packages/apps/kubernetes/templates/helmreleases/csi.yaml Added dependency on volumesnapshot CRD HelmRelease in the dependsOn section.
packages/apps/versions_map Updated version mapping: 0.26.0 now points to a commit hash, 0.26.1 marked as HEAD.
scripts/migrations/17 Added migration script to patch kuberneteses resources to appVersion 0.26.1 and update version ConfigMap.

Sequence Diagram(s)

sequenceDiagram
    participant MigrationScript
    participant KubernetesAPI
    participant ConfigMap

    MigrationScript->>KubernetesAPI: List all kuberneteses.apps.cozystack.io (all namespaces)
    loop For each resource
        MigrationScript->>KubernetesAPI: Patch appVersion to "0.26.1"
    end
    MigrationScript->>ConfigMap: Create/Update cozystack-version ConfigMap (version=18)
Loading
sequenceDiagram
    participant HelmReleaseCSI
    participant HelmReleaseVolumeSnapshotCRD

    HelmReleaseCSI->>HelmReleaseVolumeSnapshotCRD: dependsOn (wait for CRD HelmRelease readiness)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Suggested labels

enhancement, size:S

Suggested reviewers

  • lllamnyp

Poem

A hop, a skip, a version bump,
New dependencies in a clump!
Chart and map now freshly spun,
Migrations patched, the job is done.
HelmRelease waits, the CRD’s here—
0.26.1, let’s all cheer! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-k8s

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 generate unit tests to generate unit tests for 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

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @kvaps, 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 updates the Kubernetes application chart to version 0.26.1. The primary goal is to establish a critical dependency on the volume snapshot Custom Resource Definition (CRD) for the CSI components, ensuring proper deployment order. Additionally, it includes a new migration script to facilitate the upgrade of existing Kubernetes application instances to this updated version.

Highlights

  • Kubernetes Chart Version Update: The Kubernetes application chart version has been incremented from 0.26.0 to 0.26.1 in Chart.yaml.
  • Volume Snapshot CRD Dependency: A new dependsOn entry has been added to the CSI HelmRelease in templates/helmreleases/csi.yaml. This ensures that the volumesnapshot-crd-for-tenant-k8s resource is available before the CSI components are deployed, establishing a crucial dependency.
  • New Migration Script: A new migration script, scripts/migrations/17, has been introduced. This script is designed to automatically update existing kuberneteses.apps.cozystack.io resources by patching their appVersion to 0.26.1 and incrementing the cozystack-version configmap to 18.
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-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 may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey 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.

@kvaps kvaps added the backport Should change be backported on previus release label Jul 24, 2025
Copy link

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

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 updates the kubernetes app, introduces a dependency on the volume snapshot CRD, and adds a migration script. The chart and version map changes are correct. However, the new migration script has a critical error handling vulnerability that could lead to silent failures, and a potential issue in the kubectl patch command that needs verification to ensure the migration is effective.

@@ -0,0 +1,10 @@
#!/bin/sh

Choose a reason for hiding this comment

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

critical

The script lacks robust error handling, which can lead to silent failures and leave the system in an inconsistent state. I strongly recommend adding set -eo pipefail at the beginning of the script to ensure that the script exits immediately if any command fails and that the pipeline's exit code reflects the failure of any command in the pipeline, not just the last one.

#!/bin/sh
set -eo pipefail


# Upgrade kubernetes.apps to new chart version
kubectl get kuberneteses.apps.cozystack.io -A --no-headers --output=custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' | while read NAMESPACE NAME; do
kubectl patch kuberneteses.apps.cozystack.io -n "$NAMESPACE" "$NAME" --type merge -p '{"appVersion":"0.26.1"}'

Choose a reason for hiding this comment

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

high

The patch '-p '{\"appVersion\":\"0.26.1\"}' targets a top-level appVersion field. Please verify the structure of the kuberneteses.apps.cozystack.io CRD. If the appVersion field is under spec, the patch will not work as intended and could either fail or be ignored, leaving existing resources un-migrated. The patch should be updated to target the correct path, which is likely spec.appVersion.

  kubectl patch kuberneteses.apps.cozystack.io -n "$NAMESPACE" "$NAME" --type merge -p '{"spec":{"appVersion":"0.26.1"}}'

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: 4

🧹 Nitpick comments (1)
scripts/migrations/17 (1)

9-10: Race condition: ConfigMap may already exist at version 18
kubectl create … | kubectl apply is idempotent, but if multiple installers run concurrently there is still a chance of conflict. Consider using kubectl patch or kubectl label --overwrite with a retry loop to make this bullet-proof.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 68a4709 and 02436f3.

📒 Files selected for processing (4)
  • packages/apps/kubernetes/Chart.yaml (1 hunks)
  • packages/apps/kubernetes/templates/helmreleases/csi.yaml (1 hunks)
  • packages/apps/versions_map (1 hunks)
  • scripts/migrations/17 (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common 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.
scripts/migrations/17 (1)

Learnt from: lllamnyp
PR: #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.

packages/apps/versions_map (1)

Learnt from: kvaps
PR: #1206
File: packages/apps/versions_map:30-31
Timestamp: 2025-07-16T13:17:07.580Z
Learning: In packages/apps/versions_map, using HEAD for certain versions (like ferretdb 1.0.0) is intentional and part of the core logic, not an oversight that needs to be fixed for reproducibility.

🧬 Code Graph Analysis (2)
scripts/migrations/17 (1)
scripts/installer.sh (1)
  • run_migrations (8-20)
packages/apps/kubernetes/templates/helmreleases/csi.yaml (1)
internal/controller/tenant_helm_reconciler.go (2)
  • annotateTenantRootNs (132-158)
  • Reconcile (27-106)
⏰ 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
🔇 Additional comments (1)
packages/apps/kubernetes/Chart.yaml (1)

19-19: Chart version bump looks correct but remember to update accompanying docs/release-notes
The Semantic-Version bump is fine; however, without a matching entry in CHANGELOG / release-notes, downstream operators will not know what changed between 0.26.0 and 0.26.1.

Comment on lines +38 to 40
- name: {{ .Release.Name }}-volumesnapshot-crd-for-tenant-k8s
namespace: {{ .Release.Namespace }}
{{- if lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" .Release.Namespace .Release.Name }}
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

Unconditional dependency can dead-lock the HelmRelease
dependsOn will block reconciliation until the referenced HelmRelease exists and is ready. Because the new VolumeSnapshot CRD release is not created by this template and has no safeguard (unlike the next item wrapped in lookup), Flux will wait forever on a missing object.

Add the same guard or move CRD creation into this chart.

-  - name: {{ .Release.Name }}-volumesnapshot-crd-for-tenant-k8s
-    namespace: {{ .Release.Namespace }}
+  {{- if lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" .Release.Namespace (printf "%s-volumesnapshot-crd-for-tenant-k8s" .Release.Name) }}
+  - name: {{ .Release.Name }}-volumesnapshot-crd-for-tenant-k8s
+    namespace: {{ .Release.Namespace }}
+  {{- end }}
🤖 Prompt for AI Agents
In packages/apps/kubernetes/templates/helmreleases/csi.yaml around lines 38 to
40, the dependsOn reference to the VolumeSnapshot CRD HelmRelease is
unconditional, causing potential deadlocks if the referenced HelmRelease does
not exist. To fix this, add a conditional guard using the lookup function to
check for the existence of the HelmRelease before depending on it, similar to
the pattern used for the next item, or alternatively move the CRD creation into
this chart to ensure it is managed and available.

Comment on lines +64 to +65
kubernetes 0.26.0 9584e5f5
kubernetes 0.26.1 HEAD
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

❓ Verification inconclusive

Confirm the pinned commit hash exists and is immutable
9584e5f5 must be an existing commit in the repo; otherwise consumers relying on reproducible builds will break.

If this command fails, fix the hash before merging.


🏁 Script executed:

#!/bin/bash
git cat-file -e 9584e5f5^{commit}

Length of output: 86


Ensure the pinned commit hash is valid

The commit 9584e5f5 referenced in packages/apps/versions_map (lines 64–65) does not exist in this repository, which will break reproducible builds. Please update it to a valid, immutable commit:

• File: packages/apps/versions_map
Lines: 64–65

Current snippet:

kubernetes 0.26.0 9584e5f5
kubernetes 0.26.1 HEAD

Please replace 9584e5f5 with an existing commit hash (e.g., from the kubernetes submodule or upstream tag) and verify with:

git cat-file -e <new-hash>^{commit}
🤖 Prompt for AI Agents
In packages/apps/versions_map at lines 64 to 65, the commit hash '9584e5f5' for
kubernetes 0.26.0 is invalid and will break reproducible builds. Replace this
hash with a valid, immutable commit hash from the kubernetes repository that
corresponds to version 0.26.0. Verify the new hash exists by running 'git
cat-file -e <new-hash>^{commit}' before updating the file.

Comment on lines +1 to +3
#!/bin/sh
# Migration 17 --> 18

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

Add strict error handling to avoid half-applied migrations
Use set -euo pipefail so the script stops on the first failure instead of silently continuing.

-#!/bin/sh
+#!/bin/sh
+set -euo pipefail
📝 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
#!/bin/sh
# Migration 17 --> 18
#!/bin/sh
set -euo pipefail
# Migration 17 --> 18
🤖 Prompt for AI Agents
In scripts/migrations/17 at the beginning of the file (lines 1 to 3), add the
line `set -euo pipefail` right after the shebang (`#!/bin/sh`). This will enable
strict error handling, causing the script to exit immediately if any command
fails, if any variable is unset, or if any part of a pipeline fails, preventing
partial or half-applied migrations.

Comment on lines +5 to +7
kubectl get kuberneteses.apps.cozystack.io -A --no-headers --output=custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' | while read NAMESPACE NAME; do
kubectl patch kuberneteses.apps.cozystack.io -n "$NAMESPACE" "$NAME" --type merge -p '{"appVersion":"0.26.1"}'
done
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

Patch path likely wrong – field is inside .spec
Most Cozystack CRDs store the application version under spec.appVersion, not root level. If that’s the case, this patch is a no-op.

-  kubectl patch kuberneteses.apps.cozystack.io -n "$NAMESPACE" "$NAME" --type merge -p '{"appVersion":"0.26.1"}'
+  kubectl patch kuberneteses.apps.cozystack.io -n "$NAMESPACE" "$NAME" --type merge -p '{"spec":{"appVersion":"0.26.1"}}'

Please verify the CRD schema before running the migration.

📝 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
kubectl get kuberneteses.apps.cozystack.io -A --no-headers --output=custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' | while read NAMESPACE NAME; do
kubectl patch kuberneteses.apps.cozystack.io -n "$NAMESPACE" "$NAME" --type merge -p '{"appVersion":"0.26.1"}'
done
kubectl get kuberneteses.apps.cozystack.io -A --no-headers --output=custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' | while read NAMESPACE NAME; do
kubectl patch kuberneteses.apps.cozystack.io -n "$NAMESPACE" "$NAME" --type merge -p '{"spec":{"appVersion":"0.26.1"}}'
done
🤖 Prompt for AI Agents
In scripts/migrations/17 around lines 5 to 7, the patch command incorrectly
targets the appVersion field at the root level, but it should be inside the spec
object. Update the patch JSON to set "spec.appVersion" instead of "appVersion"
by changing the patch to '{"spec":{"appVersion":"0.26.1"}}' to correctly update
the field according to the CRD schema.

@kvaps kvaps merged commit 0feeaad into main Jul 25, 2025
34 of 35 checks passed
@kvaps kvaps deleted the fix-k8s branch July 25, 2025 15:11
Copy link

kvaps added a commit that referenced this pull request Jul 25, 2025
…and migration to latest version (#1279)

# Description
Backport of #1275 to `release-0.34`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Should change be backported on previus release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant