fix(migrations): handle missing rabbitmq CRD in migration 34#2168
fix(migrations): handle missing rabbitmq CRD in migration 34#2168kvaps merged 1 commit intocozystack:mainfrom
Conversation
Migration 34 fails when rabbitmqs.apps.cozystack.io CRD does not exist, which happens when RabbitMQ was never installed on the cluster. Add a check for CRD presence before attempting to list resources. Signed-off-by: IvanHunters <[email protected]>
Summary of ChangesHello, 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 resolves a critical issue in migration 34, which previously caused the migration script to fail if the RabbitMQ Custom Resource Definition (CRD) was not found. By introducing a pre-check for the CRD's presence, the migration can now intelligently determine if RabbitMQ is installed. If not, it will gracefully skip its operations and mark itself as completed, preventing unnecessary errors and ensuring smoother deployments in diverse cluster configurations. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe 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 by creating a comment using either
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughMigration 34 adds a pre-check for the presence of the rabbitmqs CRD; if missing, it logs a message, dry-runs a patch to set Changes
Sequence Diagram(s)sequenceDiagram
actor Operator
rect rgba(135,206,235,0.5)
participant MigrationScript
end
participant K8sAPI as "Kubernetes API"
participant CRD as "rabbitmqs CRD"
participant Resources as "rabbitmqs resources"
Operator ->> MigrationScript: run migration 34
MigrationScript ->> K8sAPI: check if CRD (rabbitmqs) exists
alt CRD missing
K8sAPI -->> MigrationScript: CRD not found
MigrationScript ->> K8sAPI: dry-run patch ConfigMap(cozystack-version)=version:35
MigrationScript ->> Operator: log "CRD missing, stamped version=35 and exiting"
else CRD present
K8sAPI -->> MigrationScript: CRD exists
MigrationScript ->> K8sAPI: list rabbitmqs resources
K8sAPI -->> Resources: return resources
MigrationScript ->> Resources: patch missing spec.version -> v3.13
MigrationScript ->> K8sAPI: stamp cozystack-version to next version
MigrationScript ->> Operator: complete migration
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue with migration 34 failing when the RabbitMQ CRD is not present. The approach of checking for the CRD is correct. However, the current implementation for detecting the CRD is brittle. I've suggested a more robust method. Additionally, I've noted an opportunity to refactor the script to improve its structure and reduce code duplication. Please see the detailed comments below.
| DEFAULT_VERSION="v3.13" | ||
|
|
||
| # Skip if the CRD does not exist (rabbitmq was never installed) | ||
| if ! kubectl api-resources --api-group=apps.cozystack.io -o name 2>/dev/null | grep -q '^rabbitmqs\.'; then |
There was a problem hiding this comment.
Using kubectl api-resources and grep to check for CRD existence can be brittle, as the output format of api-resources has changed across kubectl versions. A more direct and reliable way to check if a CRD exists is to use kubectl get crd <crd-name>. This command's exit code directly indicates whether the CRD was found.
| if ! kubectl api-resources --api-group=apps.cozystack.io -o name 2>/dev/null | grep -q '^rabbitmqs\.'; then | |
| if ! kubectl get crd rabbitmqs.apps.cozystack.io >/dev/null 2>&1; then |
| kubectl create configmap -n cozy-system cozystack-version \ | ||
| --from-literal=version=35 --dry-run=client -o yaml | kubectl apply -f- | ||
| exit 0 |
There was a problem hiding this comment.
This version stamping logic is duplicated at the end of the script (lines 45-46). To avoid code duplication and improve clarity, consider restructuring the script to have a single version stamping operation at the end. The main migration logic (lines 25-42) could be wrapped in an if block that executes only when the CRD exists. The version stamping would then happen unconditionally at the end of the script.
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin release-1.0
git worktree add -d .worktree/backport-2168-to-release-1.0 origin/release-1.0
cd .worktree/backport-2168-to-release-1.0
git switch --create backport-2168-to-release-1.0
git cherry-pick -x 21f293ace583ad3e4a49a119d072dc70d3971a6d |
|
Successfully created backport PR for |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin release-1.0
git worktree add -d .worktree/backport-2168-to-release-1.0 origin/release-1.0
cd .worktree/backport-2168-to-release-1.0
git switch --create backport-2168-to-release-1.0
git cherry-pick -x 21f293ace583ad3e4a49a119d072dc70d3971a6d |
Summary
error: the server doesn't have a resource type "rabbitmqs"whenrabbitmqs.apps.cozystack.ioCRD does not exist on the clusterkubectl getfails, andset -euo pipefailterminates the migration jobTest plan
spec.versionset — should patch them tov3.13spec.version— should skip patchingSummary by CodeRabbit