Skip to content

fix(migrations): handle missing rabbitmq CRD in migration 34#2168

Merged
kvaps merged 1 commit intocozystack:mainfrom
IvanHunters:fix/migration-34-missing-crd
Mar 10, 2026
Merged

fix(migrations): handle missing rabbitmq CRD in migration 34#2168
kvaps merged 1 commit intocozystack:mainfrom
IvanHunters:fix/migration-34-missing-crd

Conversation

@IvanHunters
Copy link
Collaborator

@IvanHunters IvanHunters commented Mar 6, 2026

Summary

  • Migration 34 fails with error: the server doesn't have a resource type "rabbitmqs" when rabbitmqs.apps.cozystack.io CRD does not exist on the cluster
  • This happens when RabbitMQ was never installed — the CRD is not present, kubectl get fails, and set -euo pipefail terminates the migration job
  • Added a CRD existence check before listing resources; if CRD is absent, the migration stamps the version and exits cleanly

Test plan

  • Deploy a cluster without RabbitMQ installed and run migration 34 — should skip gracefully
  • Deploy a cluster with RabbitMQ instances without spec.version set — should patch them to v3.13
  • Deploy a cluster with RabbitMQ instances already having spec.version — should skip patching

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced Migration 34 with improved error handling for missing system prerequisites, ensuring migration processes complete gracefully and update configuration appropriately during platform upgrades.

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]>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Migration Failure Fix: Migration 34 previously failed with an error when the rabbitmqs.apps.cozystack.io Custom Resource Definition (CRD) was not present on the cluster.
  • Root Cause Identified: This failure occurred in environments where RabbitMQ was never installed, causing kubectl get to fail and the set -euo pipefail command to terminate the migration script.
  • Graceful Skipping Mechanism: A CRD existence check has been added; if the RabbitMQ CRD is absent, the migration will now gracefully skip its operations, stamp the version, and exit cleanly.

🧠 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
  • packages/core/platform/images/migrations/migrations/34
    • Added a conditional check to verify the existence of the rabbitmqs.apps.cozystack.io CRD.
    • Implemented logic to skip the migration and stamp the version if the CRD is not found, ensuring graceful exit.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. 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

  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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 467ae5e8-744a-42e5-ba5f-59ec726bbb16

📥 Commits

Reviewing files that changed from the base of the PR and between adacd44 and 21f293a.

📒 Files selected for processing (1)
  • packages/core/platform/images/migrations/migrations/34

📝 Walkthrough

Walkthrough

Migration 34 adds a pre-check for the presence of the rabbitmqs CRD; if missing, it logs a message, dry-runs a patch to set cozystack-version to 35 and exits. If the CRD exists, the original migration enumerates rabbitmqs, patches missing spec.version to v3.13, and stamps the version.

Changes

Cohort / File(s) Summary
Migration 34 Pre-check
packages/core/platform/images/migrations/migrations/34
Added CRD existence check. If rabbitmqs CRD is absent: log message, apply a dry-run patch to create/update cozystack-version configmap with version=35, and exit early. If present: continue original flow to enumerate rabbitmqs, set missing spec.version to v3.13, and stamp version.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped to check a tiny CRD,

If absent, I mark version thirty-five with glee.
A dry-run patch, a careful beat,
Then home I hop — migration complete! 🥕✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@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 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
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
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

Comment on lines +20 to +22
kubectl create configmap -n cozy-system cozystack-version \
--from-literal=version=35 --dry-run=client -o yaml | kubectl apply -f-
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 10, 2026
@kvaps kvaps marked this pull request as ready for review March 10, 2026 07:18
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Mar 10, 2026
@kvaps kvaps added backport Should change be backported on previus release backport-previous and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Mar 10, 2026
@dosubot dosubot bot added the bug Something isn't working label Mar 10, 2026
@kvaps kvaps merged commit 25f0b91 into cozystack:main Mar 10, 2026
11 of 12 checks passed
@github-actions
Copy link

Backport failed for release-1.0, because it was unable to cherry-pick the commit(s).

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

@github-actions
Copy link

Successfully created backport PR for release-1.1:

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Mar 10, 2026
@github-actions
Copy link

Backport failed for release-1.0, because it was unable to cherry-pick the commit(s).

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

kvaps added a commit that referenced this pull request Mar 10, 2026
…n migration 34 (#2180)

# Description
Backport of #2168 to `release-1.1`.
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 backport-previous bug Something isn't working lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants