Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions hack/deploy-catalog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down Expand Up @@ -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
Comment on lines +118 to +124

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.


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
Expand Down Expand Up @@ -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 -

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.

rm -f "$SAVED_CONFIG"
else
echo "Creating sample OperatorConfig..."
oc apply -f config/samples/automotive_v1_operatorconfig.yaml
fi

echo ""
echo "=========================================="
Expand Down