@@ -121,41 +121,53 @@ data:
121
121
function update_idp_config {
122
122
info "Updating IDP configuration with actual cluster domain..."
123
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\.//' )
124
+ # Get the cluster domain from ibmcloud-cluster-info configmap
125
+ CLUSTER_DOMAIN=$(oc get cm ibmcloud-cluster-info -n $CSDB_NAMESPACE -o jsonpath='{.data.cluster_address }' 2>/dev/null || echo "" )
126
126
127
127
if [[ -z $CLUSTER_DOMAIN ]]; then
128
- error "Could not determine cluster domain. Please update IDP configuration manually."
128
+ error "Could not determine cluster domain from ibmcloud-cluster-info configmap . Please update IDP configuration manually."
129
129
return 1
130
130
fi
131
131
132
132
info "Detected cluster domain: $CLUSTER_DOMAIN"
133
133
134
- NEW_IDP_URL="https://cp-console.${CSDB_NAMESPACE}. ${CLUSTER_DOMAIN}/idprovider/v1/auth"
134
+ NEW_IDP_URL="https://${CLUSTER_DOMAIN}/idprovider/v1/auth"
135
135
136
- info "Updating IDP URLs to : $NEW_IDP_URL"
136
+ info "Target IDP URL : $NEW_IDP_URL"
137
137
138
138
# Check if account_iam database exists
139
139
ACCOUNT_IAM_EXISTS=$(oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -c "\list" | grep "account_iam" || echo False)
140
140
141
141
if [[ $ACCOUNT_IAM_EXISTS != "False" ]]; then
142
- oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c "
143
- UPDATE accountiam.idp_config
144
- SET idp = '$NEW_IDP_URL',
145
- modified_ts = NOW()
146
- WHERE idp LIKE '%/idprovider/v1/%';
147
- "
142
+ # Check current IDP configuration
143
+ CURRENT_IDP=$(oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -t -c "SELECT DISTINCT idp FROM accountiam.idp_config WHERE idp LIKE '%/idprovider/v1/%' LIMIT 1;" | xargs || echo "")
148
144
149
- info "Verifying IDP configuration update..."
150
- oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c "
151
- SELECT uid, realm, idp, modified_ts
152
- FROM accountiam.idp_config
153
- ORDER BY modified_ts DESC;
154
- "
155
-
156
- success "IDP configuration updated successfully."
145
+ if [[ -n $CURRENT_IDP ]] && [[ $CURRENT_IDP != $NEW_IDP_URL ]]; then
146
+ info "Current IDP URL: $CURRENT_IDP"
147
+ info "Updating IDP configuration..."
148
+
149
+ oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c "
150
+ UPDATE accountiam.idp_config
151
+ SET idp = '$NEW_IDP_URL',
152
+ modified_ts = NOW()
153
+ WHERE idp LIKE '%/idprovider/v1/%';
154
+ "
155
+ echo ""
156
+ info "Verifying IDP configuration update..."
157
+ oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c "
158
+ SELECT uid, realm, idp, modified_ts
159
+ FROM accountiam.idp_config
160
+ ORDER BY modified_ts DESC;
161
+ "
162
+
163
+ success "IDP configuration updated successfully in account_iam database."
164
+ elif [[ $CURRENT_IDP == $NEW_IDP_URL ]]; then
165
+ info "IDP configuration already matches target URL, no update needed."
166
+ else
167
+ info "No IDP configuration found in database, skipping update."
168
+ fi
157
169
else
158
- warning "account_iam database not found, skipping IDP configuration update."
170
+ info "account_iam database not found, IDP configuration update not applicable ."
159
171
fi
160
172
}
161
173
0 commit comments