Skip to content

hack: fix OperatorConfig keeping#115

Merged
bennyz merged 1 commit into
centos-automotive-suite:mainfrom
bennyz:improve-deploy-catalog
Feb 15, 2026
Merged

hack: fix OperatorConfig keeping#115
bennyz merged 1 commit into
centos-automotive-suite:mainfrom
bennyz:improve-deploy-catalog

Conversation

@bennyz

@bennyz bennyz commented Feb 15, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Automatic timestamping of configuration backups for easier identification and recovery.
    • Enhanced restoration mechanism with intelligent fallback options for improved reliability.
  • Improvements

    • Clearer messaging and feedback during configuration preservation and restoration.
    • More robust handling of configuration data during deployment operations.

@coderabbitai

coderabbitai Bot commented Feb 15, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@bennyz has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

The pull request enhances the deploy-catalog.sh script with a persistent backup mechanism for OperatorConfig. A global SAVED_CONFIG variable and cleanup() function are introduced to enable timestamped backups during uninstall, with restoration during redeploy featuring yq-based metadata cleanup and fallback logic.

Changes

Cohort / File(s) Summary
Backup Mechanism & Cleanup Trap
hack/deploy-catalog.sh
Added SAVED_CONFIG global variable to track backup files. Introduced cleanup() function with trap handler to optionally restore backups on script failure. Enhanced help text for --keep-config flag to document the operatorconfig-backup-YYYYMMDD-HHMMSS.yaml backup filename pattern.
Uninstall Flow
hack/deploy-catalog.sh
Modified uninstall logic to detect existing OperatorConfig objects, save them to timestamped files in the current directory, and signal success or failure status. Added conditional messaging for cases where no OperatorConfig exists.
Redeploy & Restore Flow
hack/deploy-catalog.sh
Updated restoration to use SAVED_CONFIG and timestamped backup files. Integrated yq-based metadata field stripping before applying restored configs, with fallback to direct oc apply if yq is unavailable or fails. Added fallback messaging and backup file preservation on restoration failures.

Sequence Diagram

sequenceDiagram
    participant User
    participant Script as deploy-catalog.sh
    participant K8s as Kubernetes<br/>(OperatorConfig)
    participant yq as yq Tool
    participant oc as oc Command

    rect rgba(100, 150, 200, 0.5)
    Note over User,oc: Uninstall Flow (--keep-config)
    User->>Script: Execute with --keep-config
    Script->>K8s: Query OperatorConfig
    K8s-->>Script: OperatorConfig YAML
    Script->>Script: Save to timestamped backup file
    Script-->>User: Backup saved (SAVED_CONFIG set)
    end

    rect rgba(200, 150, 100, 0.5)
    Note over User,oc: Redeploy Flow
    User->>Script: Execute redeploy
    Script->>Script: Locate SAVED_CONFIG backup
    Script->>yq: Strip metadata fields?
    alt yq available & succeeds
        yq-->>Script: Cleaned YAML
        Script->>oc: Apply cleaned config
    else yq unavailable or fails
        Script->>oc: Apply original config (fallback)
    end
    oc->>K8s: Apply OperatorConfig
    K8s-->>Script: Applied
    Script-->>User: Restoration complete or failed
    end

    rect rgba(150, 100, 200, 0.5)
    Note over User,oc: Failure Scenario (Cleanup Trap)
    Script->>Script: Error detected
    Script->>Script: cleanup() trap triggered
    alt --keep-config was set
        Script->>User: Print restoration instructions<br/>(reference SAVED_CONFIG)
    end
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly Related PRs

Poem

A backup's born beneath the shell,
With timestamps dancing—all is well! 🐰
When yq fails, we fall back graceful,
Restoring configs—oh, how grateful!
Like carrots stashed in burrow deep,
Your OperatorConfig's safe to keep! 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'hack: fix OperatorConfig keeping' directly relates to the main change - fixing the OperatorConfig persistence mechanism in the deployment script.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@hack/deploy-catalog.sh`:
- Around line 155-160: The backup step can leave an empty/orphaned $SAVED_CONFIG
file when `oc get operatorconfig -n ${NAMESPACE} -o yaml > "$SAVED_CONFIG"`
fails; in the else branch after detecting failure remove the partial file (e.g.
`rm -f "$SAVED_CONFIG"`) before clearing SAVED_CONFIG, and keep the echo "✗
Failed to save OperatorConfig" and the SAVED_CONFIG="" assignment so no stale
file is left behind.
🧹 Nitpick comments (2)
hack/deploy-catalog.sh (2)

469-484: yq version compatibility: eval subcommand is specific to Mike Farah's Go yq v4+.

command -v yq will also match the Python yq (a jq wrapper) or older Go yq v3, both of which don't support eval. The fallback chain handles this gracefully (failure → direct oc apply), so it's not broken, but you could tighten the check to avoid the misleading error output.

Optional: validate yq flavor before use
-        if command -v yq &> /dev/null; then
+        if command -v yq &> /dev/null && yq --version 2>&1 | grep -q 'mikefarah'; then

471-471: Pipeline masks yq failures without pipefail.

Only oc apply's exit code is checked. If yq fails but produces partial stdout that oc apply accepts, the restore would silently apply malformed config. In practice oc apply rejects bad input, so the fallback kicks in — but a two-step approach is more explicit.

Proposed: use a temp file to isolate yq failures
-            if yq eval 'del(.items[].metadata.resourceVersion, .items[].metadata.uid, .items[].metadata.creationTimestamp, .items[].metadata.generation, .items[].metadata.managedFields, .items[].status)' "$SAVED_CONFIG" | oc apply -f -; then
+            CLEANED_CONFIG=$(mktemp)
+            if yq eval 'del(.items[].metadata.resourceVersion, .items[].metadata.uid, .items[].metadata.creationTimestamp, .items[].metadata.generation, .items[].metadata.managedFields, .items[].status)' "$SAVED_CONFIG" > "$CLEANED_CONFIG" 2>/dev/null && oc apply -f "$CLEANED_CONFIG"; then
+                rm -f "$CLEANED_CONFIG"

Add rm -f "$CLEANED_CONFIG" in the failure branches too (or add it to the cleanup trap).

Comment thread hack/deploy-catalog.sh
Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
@bennyz bennyz force-pushed the improve-deploy-catalog branch from 3f16657 to ca0dabb Compare February 15, 2026 10:08
@bennyz bennyz merged commit d86e014 into centos-automotive-suite:main Feb 15, 2026
4 checks passed
@bennyz bennyz deleted the improve-deploy-catalog branch February 15, 2026 10:14
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.

1 participant