Skip to content

Add --keep-config flag to preserve OperatorConfig during redeploy#107

Merged
bennyz merged 1 commit into
centos-automotive-suite:mainfrom
bennyz:keep-config
Feb 13, 2026
Merged

Add --keep-config flag to preserve OperatorConfig during redeploy#107
bennyz merged 1 commit into
centos-automotive-suite:mainfrom
bennyz:keep-config

Conversation

@bennyz

@bennyz bennyz commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

to avoid losing OperatorConfig

Summary by CodeRabbit

  • New Features
    • Added a --keep-config flag for deployments to preserve configuration settings during redeploys, eliminating the need to reconfigure after updates.

to avoid losing OperatorConfig

Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
@coderabbitai

coderabbitai Bot commented Feb 12, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The deploy catalog script now supports a --keep-config flag that conditionally preserves OperatorConfig custom resources during redeploy operations. When enabled, configurations are saved before uninstall and restored after reinstall, with runtime metadata stripped via yq.

Changes

Cohort / File(s) Summary
Config Preservation Feature
hack/deploy-catalog.sh
Added --keep-config flag to conditionally save and restore OperatorConfig CRs during redeploy, with yq-based metadata stripping for clean restoration. Flag parsing and conditional control flow around uninstall/reinstall operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A flag to keep configs safe and sound,
No loss when redeploys come around!
With yq's gentle hand, we strip the dust,
Preserve what matters—in this script we trust.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly and clearly describes the main change: adding a --keep-config flag to preserve OperatorConfig during redeploy, which aligns with the raw summary and PR objectives.

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

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

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
hack/deploy-catalog.sh (1)

57-70: ⚠️ Potential issue | 🟠 Major

Cluster context is not displayed when -y is passed.

The coding guideline requires: "Before running deploy-catalog.sh (redeploy or uninstall), verify the cluster context by running oc whoami --show-server && oc whoami, display the cluster URL and user to the user, and only proceed with -y flag after user confirms."

Currently, -y skips the entire block, so the user never sees which cluster/user the script will target. At minimum, the cluster info should still be printed even when the confirmation prompt is skipped.

Suggested change
 if [ "$COMMAND" != "build" ] && [ "$SKIP_CONFIRM" = false ]; then
     CLUSTER_URL=$(oc whoami --show-server 2>/dev/null || echo "unknown")
     CLUSTER_USER=$(oc whoami 2>/dev/null || echo "unknown")
     echo ""
     echo "  Cluster: ${CLUSTER_URL}"
     echo "  User:    ${CLUSTER_USER}"
     echo "  Action:  ${COMMAND}"
     echo ""
     read -r -p "Proceed? [y/N] " response
     if [[ ! "$response" =~ ^[Yy]$ ]]; then
         echo "Aborted."
         exit 0
     fi
+elif [ "$COMMAND" != "build" ]; then
+    CLUSTER_URL=$(oc whoami --show-server 2>/dev/null || echo "unknown")
+    CLUSTER_USER=$(oc whoami 2>/dev/null || echo "unknown")
+    echo ""
+    echo "  Cluster: ${CLUSTER_URL}"
+    echo "  User:    ${CLUSTER_USER}"
+    echo "  Action:  ${COMMAND} (auto-confirmed with -y)"
+    echo ""
 fi

As per coding guidelines: "Before running deploy-catalog.sh (redeploy or uninstall), verify the cluster context by running oc whoami --show-server && oc whoami, display the cluster URL and user to the user, and only proceed with -y flag after user confirms."

🤖 Fix all issues with AI agents
In `@hack/deploy-catalog.sh`:
- Around line 118-124: The script currently saves OperatorConfig to SAVED_CONFIG
when KEEP_CONFIG is true but the restore only runs for redeploy, so running with
COMMAND=uninstall or build silently does nothing useful; fix by rejecting the
incompatible flag: after parsing flags, add a check that if KEEP_CONFIG=true and
COMMAND is "uninstall" or "build" then print a clear error (e.g. "ERROR:
--keep-config is not supported with 'uninstall' or 'build'") and exit 1;
reference the KEEP_CONFIG and COMMAND variables (and the SAVED_CONFIG save
block) so the check runs before creating the temp file, ensuring users are
prevented from thinking their config was preserved.
- Line 427: Add a guard that verifies yq is installed before using it (similar
to the existing opm check) to avoid silent failures when running the yq pipeline
on SAVED_CONFIG; detect yq with a simple binary check (e.g., command -v yq or
which yq) and if missing, print a clear error and exit (or handle fallback
behavior), ensuring the check occurs before the line that pipes yq eval into oc
apply so the script will fail fast and not leave the operator in a
partially-configured state.
🧹 Nitpick comments (1)
hack/deploy-catalog.sh (1)

424-428: Saved config can be lost if the restore fails.

If yq or oc apply fails on line 427, set -e kills the script before line 428 (rm -f), so the temp file survives — but only by accident. The user gets no guidance on where it is or how to retry. Consider adding a trap to print the temp file path on error, or move the rm to an explicit cleanup after confirmed success with a message.

Comment thread hack/deploy-catalog.sh
Comment on lines +118 to +124
# Save OperatorConfig if --keep-config was specified
if [ "$KEEP_CONFIG" = true ]; then
echo "Saving OperatorConfig CRs..."
SAVED_CONFIG=$(mktemp /tmp/operatorconfig-XXXXXX.yaml)
oc get operatorconfig -n ${NAMESPACE} -o yaml > "$SAVED_CONFIG" 2>/dev/null || true
echo " Saved to $SAVED_CONFIG"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

--keep-config silently does nothing useful with the uninstall command.

When $0 uninstall --keep-config is run, the config is saved to a temp file here, but the restore logic (line 424) only runs during redeploy. The user gets a "Saved to …" message suggesting the config is preserved, but the script exits at line 178 without restoring or even informing the user where the file is for manual restore.

Consider either:

  • Rejecting --keep-config when COMMAND=uninstall (or build), or
  • Printing a clear message at exit with the temp file path so the user can restore manually.
Option: reject incompatible flag
 COMMAND="${COMMAND:-redeploy}"
+
+if [ "$KEEP_CONFIG" = true ] && [ "$COMMAND" != "redeploy" ]; then
+    echo "ERROR: --keep-config is only supported with the redeploy command"
+    exit 1
+fi
🤖 Prompt for AI Agents
In `@hack/deploy-catalog.sh` around lines 118 - 124, The script currently saves
OperatorConfig to SAVED_CONFIG when KEEP_CONFIG is true but the restore only
runs for redeploy, so running with COMMAND=uninstall or build silently does
nothing useful; fix by rejecting the incompatible flag: after parsing flags, add
a check that if KEEP_CONFIG=true and COMMAND is "uninstall" or "build" then
print a clear error (e.g. "ERROR: --keep-config is not supported with
'uninstall' or 'build'") and exit 1; reference the KEEP_CONFIG and COMMAND
variables (and the SAVED_CONFIG save block) so the check runs before creating
the temp file, ensuring users are prevented from thinking their config was
preserved.

Comment thread hack/deploy-catalog.sh
if [ "$KEEP_CONFIG" = true ] && [ -n "${SAVED_CONFIG:-}" ] && [ -s "$SAVED_CONFIG" ]; then
echo "Restoring saved OperatorConfig..."
# Strip resourceVersion/uid/creationTimestamp so apply works cleanly
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 -

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

yq is used without verifying it's installed.

The script checks for opm (line 282) but not for yq. If yq is missing, the restore fails and set -e aborts the script — leaving the operator installed but without any OperatorConfig, which is arguably worse than the problem --keep-config is meant to solve.

Suggested guard
+    if ! command -v yq &>/dev/null; then
+        echo "ERROR: yq is required for --keep-config but not found in PATH"
+        echo "  Saved config is at: $SAVED_CONFIG"
+        exit 1
+    fi
     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 -
📝 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
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 -
if ! command -v yq &>/dev/null; then
echo "ERROR: yq is required for --keep-config but not found in PATH"
echo " Saved config is at: $SAVED_CONFIG"
exit 1
fi
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 -
🤖 Prompt for AI Agents
In `@hack/deploy-catalog.sh` at line 427, Add a guard that verifies yq is
installed before using it (similar to the existing opm check) to avoid silent
failures when running the yq pipeline on SAVED_CONFIG; detect yq with a simple
binary check (e.g., command -v yq or which yq) and if missing, print a clear
error and exit (or handle fallback behavior), ensuring the check occurs before
the line that pipes yq eval into oc apply so the script will fail fast and not
leave the operator in a partially-configured state.

@bennyz bennyz changed the title add hack/deploy-catalog.sh Add --keep-config flag to preserve OperatorConfig during redeploy Feb 13, 2026
@bennyz bennyz merged commit d77606e into centos-automotive-suite:main Feb 13, 2026
4 checks passed
@bennyz bennyz deleted the keep-config branch February 13, 2026 13:08
@coderabbitai coderabbitai Bot mentioned this pull request Mar 24, 2026
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