-
Notifications
You must be signed in to change notification settings - Fork 9
Add --keep-config flag to preserve OperatorConfig during redeploy #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,23 +12,32 @@ Commands: | |||||||||||||||
| build Build and push images only (no install) | ||||||||||||||||
| help Show this help message | ||||||||||||||||
|
|
||||||||||||||||
| Flags: | ||||||||||||||||
| -y, --yes Skip confirmation prompt | ||||||||||||||||
| --keep-config Save and restore OperatorConfig during redeploy | ||||||||||||||||
|
|
||||||||||||||||
| Examples: | ||||||||||||||||
| $0 # Full redeploy (most common) | ||||||||||||||||
| $0 uninstall # Just uninstall | ||||||||||||||||
| $0 build # Just build images | ||||||||||||||||
| $0 -y # Full redeploy, skip confirmation | ||||||||||||||||
| $0 -y --keep-config # Redeploy preserving OperatorConfig | ||||||||||||||||
| EOF | ||||||||||||||||
| exit 0 | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| # Parse command and flags | ||||||||||||||||
| SKIP_CONFIRM=false | ||||||||||||||||
| KEEP_CONFIG=false | ||||||||||||||||
| COMMAND="" | ||||||||||||||||
| for arg in "$@"; do | ||||||||||||||||
| case "$arg" in | ||||||||||||||||
| -y|--yes) | ||||||||||||||||
| SKIP_CONFIRM=true | ||||||||||||||||
| ;; | ||||||||||||||||
| --keep-config) | ||||||||||||||||
| KEEP_CONFIG=true | ||||||||||||||||
| ;; | ||||||||||||||||
| help|-h|--help) | ||||||||||||||||
| show_help | ||||||||||||||||
| ;; | ||||||||||||||||
|
|
@@ -106,6 +115,14 @@ uninstall_operator() { | |||||||||||||||
| echo "Uninstalling existing operator" | ||||||||||||||||
| echo "==========================================" | ||||||||||||||||
|
|
||||||||||||||||
| # 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 | ||||||||||||||||
|
|
||||||||||||||||
| echo "Removing finalizers from OperatorConfig CRs..." | ||||||||||||||||
| for oc_name in $(oc get operatorconfig -n ${NAMESPACE} -o name 2>/dev/null); do | ||||||||||||||||
| oc patch ${oc_name} -n ${NAMESPACE} --type=merge -p '{"metadata":{"finalizers":[]}}' 2>/dev/null || true | ||||||||||||||||
|
|
@@ -404,8 +421,15 @@ if [ "$COMMAND" = "redeploy" ]; then | |||||||||||||||
| done | ||||||||||||||||
|
|
||||||||||||||||
| echo "" | ||||||||||||||||
| echo "Creating sample OperatorConfig..." | ||||||||||||||||
| oc apply -f config/samples/automotive_v1_operatorconfig.yaml | ||||||||||||||||
| 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 - | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The script checks for 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| rm -f "$SAVED_CONFIG" | ||||||||||||||||
| else | ||||||||||||||||
| echo "Creating sample OperatorConfig..." | ||||||||||||||||
| oc apply -f config/samples/automotive_v1_operatorconfig.yaml | ||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| echo "" | ||||||||||||||||
| echo "==========================================" | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--keep-configsilently does nothing useful with theuninstallcommand.When
$0 uninstall --keep-configis run, the config is saved to a temp file here, but the restore logic (line 424) only runs duringredeploy. 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:
--keep-configwhenCOMMAND=uninstall(orbuild), orOption: 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