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