Skip to content

Commit 734772c

Browse files
committed
Add IDP configuration update function for mcsp BR
Signed-off-by: YuChen <[email protected]>
1 parent 486e80f commit 734772c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

velero/schedule/common-service-db/cs-db-br-script-cm-4.6.10.4.11.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ data:
104104
if [[ $ACCOUNT_IAM != "False" ]]; then
105105
info "Beginning restore of account_iam database..."
106106
oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- pg_restore -U postgres --dbname account_iam --format=c --clean --exit-on-error -v /run/cs-db_backup/cs-db_account_iam_backup.dump
107+
108+
# Update IDP configuration with actual cluster domain
109+
update_idp_config
107110
fi
108111
oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -c "\list" -c "\dn" -c "\du"
109112
else
@@ -121,6 +124,42 @@ data:
121124
wait_for_oidc
122125
}
123126
127+
function update_idp_config {
128+
info "Updating IDP configuration with actual cluster domain..."
129+
130+
# Get the cluster domain from the management ingress
131+
CLUSTER_DOMAIN=$(oc get route console -n openshift-console -o jsonpath='{.spec.host}' | sed 's/^console-openshift-console\.//')
132+
133+
if [[ -z $CLUSTER_DOMAIN ]]; then
134+
error "Could not determine cluster domain. Please update IDP configuration manually."
135+
return 1
136+
fi
137+
138+
info "Detected cluster domain: $CLUSTER_DOMAIN"
139+
140+
# Construct the new IDP URL based on the cluster domain and namespace
141+
NEW_IDP_URL="https://cp-console.${CSDB_NAMESPACE}.${CLUSTER_DOMAIN}/idprovider/v1/auth"
142+
143+
info "Updating IDP URLs to: $NEW_IDP_URL"
144+
145+
# Check if account_iam database exists
146+
ACCOUNT_IAM_EXISTS=$(oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -c "\list" | grep "account_iam" || echo False)
147+
148+
if [[ $ACCOUNT_IAM_EXISTS != "False" ]]; then
149+
# Update the idp column in the idp_config table
150+
oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c "
151+
UPDATE accountiam.idp_config
152+
SET idp = '$NEW_IDP_URL',
153+
modified_ts = NOW()
154+
WHERE idp LIKE '%/idprovider/v1/%';
155+
"
156+
157+
success "IDP configuration updated successfully."
158+
else
159+
warning "account_iam database not found, skipping IDP configuration update."
160+
fi
161+
}
162+
124163
function wait_for_oidc {
125164
job_name="oidc-client-registration"
126165
info "Waiting for job $job_name to complete in namespace $CSDB_NAMESPACE."

0 commit comments

Comments
 (0)