Skip to content
Open
Show file tree
Hide file tree
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
182 changes: 182 additions & 0 deletions scripts/patches/v110-patch1/apply-v110-patch1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#!/usr/bin/env bash

set -e

INSTALL_FOLDER=$1
MANIFEST=$2
export WORKSPACE_DIR="./v110-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-v110-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-v110-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")
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"

sync_argo ${CLUSTER_NAME}

# run cuga argo refresh commands
refresh_argo ${CLUSTER_NAME}
}

refresh_argo() {
local cluster_name=$1

APPS=(
acm-cuga-system-${cluster_name}
backup-restore-pipelines-${cluster_name}
sov-core-k8s-wrapper-${cluster_name}
acm-vault-aas-${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=(
acm-cuga-system-${cluster_name}
backup-restore-pipelines-${cluster_name}
sov-core-k8s-wrapper-${cluster_name}
acm-vault-aas-${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":"v110-patch1"},"sync":{"syncStrategy":{"hook":{}}}}}'; then
log_error "Failed to sync $app"
failed=1
fi
done
return $failed
}

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 "$@"
9 changes: 9 additions & 0 deletions scripts/patches/v110-patch1/v110-patch1-image-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: mirror.openshift.io/v2alpha1
kind: ImageSetConfiguration
mirror:
additionalImages:
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/main/acm-cuga-system:0.2.0@sha256:fe8fffe4eec8e47ef9ef3928b1361e1720da087a8c1a60e08691e68369e10b21
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/main/acm-vault-aas:0.2.0@sha256:b95436f457e2562b988e017275cf2dbf4451853e466777ff71c179dfb8e50eaa
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/main/backup-restore-pipelines:0.2.0@sha256:b1e8ae431b86e91df0bd7f726a187f382f0f89e2e0fefd1f22993a5395e92fa2
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/main/sov-core-k8s-wrapper:0.2.0@sha256:9461ef8885ed32737b403d09f06d3502e3aaffd008bb435360078f568af8eb2f
- name: cp.icr.io/cp/sovereign-cloud-platform/automation-saas-platform-dev/sov-core-k8s-wrapper:master-1783011623@sha256:8752d7f4e22061f38d7384f56ee0c311bf673ca1ccb9e27e3445e2c2e8456dd1