Skip to content

Commit 5b1b4bc

Browse files
committed
Add IDP configuration update function for mcsp BR
Signed-off-by: YuChen <[email protected]>
1 parent 4557ebc commit 5b1b4bc

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
@@ -98,6 +98,9 @@ data:
9898
if [[ $ACCOUNT_IAM != "False" ]]; then
9999
info "Beginning restore of account_iam database..."
100100
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
101+
102+
# Update IDP configuration with actual cluster domain
103+
update_idp_config
101104
fi
102105
oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -c "\list" -c "\dn" -c "\du"
103106
else
@@ -115,6 +118,42 @@ data:
115118
wait_for_oidc
116119
}
117120
121+
function update_idp_config {
122+
info "Updating IDP configuration with actual cluster domain..."
123+
124+
# Get the cluster domain from the management ingress
125+
CLUSTER_DOMAIN=$(oc get route console -n openshift-console -o jsonpath='{.spec.host}' | sed 's/^console-openshift-console\.//')
126+
127+
if [[ -z $CLUSTER_DOMAIN ]]; then
128+
error "Could not determine cluster domain. Please update IDP configuration manually."
129+
return 1
130+
fi
131+
132+
info "Detected cluster domain: $CLUSTER_DOMAIN"
133+
134+
# Construct the new IDP URL based on the cluster domain and namespace
135+
NEW_IDP_URL="https://cp-console.${CSDB_NAMESPACE}.${CLUSTER_DOMAIN}/idprovider/v1/auth"
136+
137+
info "Updating IDP URLs to: $NEW_IDP_URL"
138+
139+
# Check if account_iam database exists
140+
ACCOUNT_IAM_EXISTS=$(oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -c "\list" | grep "account_iam" || echo False)
141+
142+
if [[ $ACCOUNT_IAM_EXISTS != "False" ]]; then
143+
# Update the idp column in the idp_config table
144+
oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c "
145+
UPDATE accountiam.idp_config
146+
SET idp = '$NEW_IDP_URL',
147+
modified_ts = NOW()
148+
WHERE idp LIKE '%/idprovider/v1/%';
149+
"
150+
151+
success "IDP configuration updated successfully."
152+
else
153+
warning "account_iam database not found, skipping IDP configuration update."
154+
fi
155+
}
156+
118157
function wait_for_oidc {
119158
job_name="oidc-client-registration"
120159
info "Waiting for job $job_name to complete in namespace $CSDB_NAMESPACE."

0 commit comments

Comments
 (0)