generated from terraform-ibm-modules/terraform-ibm-module-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the ability to disable / enable the OCP console using new i…
…nput `enable_ocp_console` (#588)
- Loading branch information
1 parent
a10425b
commit c603b0b
Showing
8 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
|
||
PATCH_APPLY="oc patch consoles.operator.openshift.io cluster --patch '{\"spec\":{\"managementState\":\"Managed\"}}' --type=merge" | ||
PATCH_REMOVE="oc patch consoles.operator.openshift.io cluster --patch '{\"spec\":{\"managementState\":\"Removed\"}}' --type=merge" | ||
MAX_ATTEMPTS=10 | ||
RETRY_WAIT=5 | ||
|
||
function check_oc_cli() { | ||
if ! command -v oc &> /dev/null; then | ||
echo "Error: OpenShift CLI (oc) is not installed. Exiting." | ||
exit 1 | ||
fi | ||
} | ||
|
||
function apply_oc_patch() { | ||
|
||
local attempt=0 | ||
while [ $attempt -lt $MAX_ATTEMPTS ]; do | ||
echo "Attempt $((attempt+1)) of $MAX_ATTEMPTS: Applying OpenShift Console patch..." | ||
|
||
if eval "$PATCH_APPLY"; then | ||
echo "Patch applied successfully." | ||
return 0 | ||
else | ||
echo "Failed to apply patch. Retrying in ${RETRY_WAIT}s..." | ||
sleep $RETRY_WAIT | ||
((attempt++)) | ||
RETRY_WAIT=$((RETRY_WAIT * 2)) | ||
fi | ||
done | ||
|
||
echo "Maximum retry attempts reached. Could not apply patch." | ||
exit 1 | ||
} | ||
|
||
function remove_oc_patch() { | ||
|
||
local attempt=0 | ||
while [ $attempt -lt $MAX_ATTEMPTS ]; do | ||
echo "Attempt $((attempt+1)) of $MAX_ATTEMPTS: Removing OpenShift Console patch..." | ||
|
||
if eval "$PATCH_REMOVE"; then | ||
echo "Patch removed successfully." | ||
return 0 | ||
else | ||
echo "Failed to remove patch. Retrying in ${RETRY_WAIT}s..." | ||
sleep $RETRY_WAIT | ||
((attempt++)) | ||
RETRY_WAIT=$((RETRY_WAIT * 2)) | ||
fi | ||
done | ||
|
||
echo "Maximum retry attempts reached. Could not remove patch." | ||
exit 1 | ||
} | ||
|
||
echo "=========================================" | ||
|
||
if [[ -z "${ENABLE_OCP_CONSOLE}" ]]; then | ||
echo "ENABLE_OCP_CONSOLE must be set" >&2 | ||
exit 1 | ||
fi | ||
|
||
check_oc_cli | ||
|
||
if [ "${ENABLE_OCP_CONSOLE}" == "true" ]; then | ||
echo "Enabling the OpenShift Console" | ||
apply_oc_patch | ||
else | ||
echo "Disabling the OpenShift Console" | ||
remove_oc_patch | ||
fi | ||
|
||
echo "=========================================" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters