Skip to content
202 changes: 202 additions & 0 deletions scripts/patches/v120-patch1/apply-v120-patch1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#!/usr/bin/env bash

set -e

INSTALL_FOLDER=$1
MANIFEST=$2
export WORKSPACE_DIR="./v120-patch1-mirror-workspace"
export VALUES_FILE_DYNAMIC="${INSTALL_FOLDER}/partner-install/mcsp/resources/charts/bootstrap-cd-pipeline/values-dynamic.yaml"
export SECRETS_FILE="${INSTALL_FOLDER}/partner-install/mcsp/resources/charts/bootstrap-cd-pipeline/secrets.yaml"

# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

function main() {

# need to validate parameters
if [ -z "$INSTALL_FOLDER" ]; then
log_error "Install folder not specified. Please rerun script in format: ./apply-v120-patch1.sh <path to install-folder> <path to manifest-file>"
exit 1
fi
if [ ! -d "$INSTALL_FOLDER" ]; then
log_error "Error: Install folder $INSTALL_FOLDER does not exist."
exit 1
fi

if [ -z "$MANIFEST" ]; then
log_error "Manifest file not specified. Please rerun script in format: ./apply-v120-patch1.sh <path to install-folder> <path to manifest-file>"
exit 1
fi
if [ ! -f "$MANIFEST" ]; then
log_error "Error: Manifest file $MANIFEST does not exist."
exit 1
fi
if [ ! -f "$INSTALL_FOLDER/partner-install/mcsp/resources/charts/bootstrap-cd-pipeline/template.env" ]; then
log_error "Make sure the install folder path points to the SovereignCore directory and re-run"
exit 1
fi
log_info "Validations passed"

#source necessary template.env values
source ${INSTALL_FOLDER}/partner-install/mcsp/resources/charts/bootstrap-cd-pipeline/template.env

# extract variables from values.yaml and secrets.yaml
QUAY_REGISTRY=$(yq -r '.registry.domain // ""' "$VALUES_FILE_DYNAMIC")
IMAGE_REGISTRY=$(yq -r '.imageRegistry // ""' "$VALUES_FILE_DYNAMIC")
QUAY_ORGANIZATION="sovcloud"
CLUSTER_NAME=$(yq -r '.clusterName // ""' "${INSTALL_FOLDER}/config/global.yaml")

ROOT_DIR=$(yq '.workingDir' "${INSTALL_FOLDER}/config/global.yaml")
export KUBECONFIG="${ROOT_DIR}/ocp-cluster/auth/kubeconfig"

# need to mirror images based on image manifest file
# call the mirror.sh mirror_images function, directly point it to the manifest file
if mirror_images "$MANIFEST"; then
log_info "Successfully mirrored images from $MANIFEST"
else
log_error "Failed to mirror images from $MANIFEST"
exit 1
fi
log_info "done mirroring images"

# run argo refresh commands
refresh_argo ${CLUSTER_NAME}
sleep 30

sync_argo ${CLUSTER_NAME}

update_vault_watcher
}

refresh_argo() {
local cluster_name=$1

APPS=(
app-of-apps-parent-app
sovereign-ui-${cluster_name}
acm-cuga-system-${cluster_name}
aiiaas-${cluster_name}
acm-observability-${cluster_name}
)

NS="openshift-gitops"

local failed=0
for app in "${APPS[@]}"; do
log_info "Refreshing $app"
if ! oc patch application.argoproj.io "$app" -n "$NS" \
--type merge \
-p '{"metadata":{"annotations":{"argocd.argoproj.io/refresh":"hard"}}}'; then
log_error "Failed to refresh $app"
failed=1
continue
fi
oc annotate application.argoproj.io "$app" -n "$NS" \
cache-buster="$(date +%s)" --overwrite
done
return $failed
}

sync_argo() {
local cluster_name=$1

APPS=(
app-of-apps-parent-app
sovereign-ui-${cluster_name}
acm-cuga-system-${cluster_name}
aiiaas-${cluster_name}
acm-observability-${cluster_name}
)

NS="openshift-gitops"

local failed=0
for app in "${APPS[@]}"; do
log_info "Syncing $app"
if ! oc patch application.argoproj.io "$app" -n "$NS" \
--type merge \
-p '{"operation":{"initiatedBy":{"username":"v120-patch1"},"sync":{"syncStrategy":{"hook":{}}}}}'; then
log_error "Failed to sync $app"
failed=1
fi
done
return $failed
}

update_vault_watcher() {
local target_registry="${IMAGE_REGISTRY}"
local image_base="${target_registry}/automation-saas-platform/tekton-baseimage:v0.1.7"
local patch="{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"watcher\",\"image\":\"${image_base}\"}]}}}}"

log_info "Patching vault-unsealer-watcher in namespace vault-unsealer"
oc patch deployment vault-unsealer-watcher -n vault-unsealer \
--type strategic -p "$patch"

log_info "Patching vaultaas-unsealer-watcher in namespace vault-aas-unsealer"
oc patch deployment vaultaas-unsealer-watcher -n vault-aas-unsealer \
--type strategic -p "$patch"
}

mirror_images() {
local manifest_file=$1
local manifest_name=$(basename "$manifest_file" .yaml)

log_info "=========================================="
log_info "Mirroring images from: $manifest_file"
log_info "=========================================="

if [ ! -f "$manifest_file" ]; then
log_error "Manifest file not found: $manifest_file"
return 1
fi

# Set workspace directory
local workspace_dir="${WORKSPACE_DIR:-./mirror-workspace}"
mkdir -p "$workspace_dir"

# Get oc-mirror auth file directory
local auth_file_dir="${AUTH_FILE_DIR}"

# Build the oc-mirror command
local target_registry="docker://${QUAY_REGISTRY}/${QUAY_ORGANIZATION}"
local workspace_path="file://$(realpath $workspace_dir)"

log_info "Target registry: $target_registry"
log_info "Workspace: $workspace_path"
log_info ""
log_info "Running oc-mirror..."

# Run oc-mirror
if oc-mirror --v2 --dest-tls-verify=false \
--authfile "$auth_file_dir" \
--config "$manifest_file" \
--retry-times 5 \
--retry-delay 10s \
--workspace "$workspace_path" \
"$target_registry"; then
log_info "✓ Successfully mirrored images from $manifest_name"

return 0
else
log_error "✗ Failed to mirror images from $manifest_name"
return 1
fi
}

# Function to print colored messages
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}

log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}

log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}

main "$@"
14 changes: 14 additions & 0 deletions scripts/patches/v120-patch1/v120-patch1-image-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: mirror.openshift.io/v2alpha1
kind: ImageSetConfiguration
mirror:
additionalImages:
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform/tekton-baseimage:v0.1.7@sha256:10c922db4ea86364905883f381963570774d3666ed7eb5a7445c5c5cc74a70c9
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/gori-experience-apps/mspui:main-1787365235@sha256:e2231e6680ca48a35fa7ab90b6f8d86860fcb903002b0d7dcb054d312228c2da
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/gori-experience-apps/accountui:main-1787365235@sha256:c3529464284a1075eab9217ca934279f25426691494550ae01e4ac83a628ad35
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/gori-experience-apps/xpm:main-1787365235@sha256:a676b7f6097558b095c64685a127ba5a1ab305dce88bd4b1041998308673f4d6
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/release-v1.2.0/acm-cuga-system:0.3.0@sha256:b451aa1b9691cc37cfe59f778abc447fb4d688ab6c742497bdbabea950249959
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/release-v1.2.0/main:0.3.0@sha256:4dea9e0cd4d9ccce7a34cb5f0fffbb368968c7d5806d88d8a868c27198db1fa5
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/release-v1.2.0/sovereign-core-upgrade-pipelines:0.3.0@sha256:6db62d71b3a659af9a38302b65e1cab91e448dbb3527b95dc0307f4ab5b903d0
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/release-v1.2.0/aiiaas:0.3.0@sha256:45ff6d72c23069fa8c95c096526f46c2eb5f8e9dd954e739209454ed900b82fc
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/release-v1.2.0/sovereign-ui:0.3.0@sha256:9f41f3303109fffab7f1fe1416cdcc766cb0f4d2ae7d0b91b11af598c7167310
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/release-v1.2.0/acm-observability:0.3.0@sha256:62cbb724903d73744e5edd4f631614d6a670619e1d110a274c7c7dcce857dd99