Skip to content

Commit 1bea478

Browse files
committed
get route from im info configmap
Signed-off-by: YuChen <[email protected]>
1 parent 3046f2c commit 1bea478

File tree

2 files changed

+61
-40
lines changed

2 files changed

+61
-40
lines changed

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

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -127,41 +127,53 @@ data:
127127
function update_idp_config {
128128
info "Updating IDP configuration with actual cluster domain..."
129129
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 "")
132132
133133
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."
135135
return 1
136136
fi
137137
138138
info "Detected cluster domain: $CLUSTER_DOMAIN"
139139
140-
NEW_IDP_URL="https://cp-console.${CSDB_NAMESPACE}.${CLUSTER_DOMAIN}/idprovider/v1/auth"
140+
NEW_IDP_URL="https://${CLUSTER_DOMAIN}/idprovider/v1/auth"
141141
142-
info "Updating IDP URLs to: $NEW_IDP_URL"
142+
info "Target IDP URL: $NEW_IDP_URL"
143143
144144
# Check if account_iam database exists
145145
ACCOUNT_IAM_EXISTS=$(oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -c "\list" | grep "account_iam" || echo False)
146146
147147
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 "")
154150
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
163175
else
164-
warning "account_iam database not found, skipping IDP configuration update."
176+
info "account_iam database not found, IDP configuration update not applicable."
165177
fi
166178
}
167179

velero/schedule/common-service-db/test-idp-update.sh

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,41 @@ oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres
3333
ORDER BY modified_ts DESC;
3434
"
3535

36-
echo "Getting cluster domain..."
37-
CLUSTER_DOMAIN=$(oc get route console -n openshift-console -o jsonpath='{.spec.host}' | sed 's/^console-openshift-console\.//')
36+
echo "Getting cluster domain from ibmcloud-cluster-info configmap..."
37+
CLUSTER_DOMAIN=$(oc get cm ibmcloud-cluster-info -n $CSDB_NAMESPACE -o jsonpath='{.data.cluster_address}' 2>/dev/null || echo "")
3838

3939
if [[ -z $CLUSTER_DOMAIN ]]; then
40-
echo "Warning: Could not determine cluster domain from console route, trying alternative method..."
41-
CLUSTER_DOMAIN=$(oc get ingress.config.openshift.io cluster -o jsonpath='{.spec.domain}')
42-
fi
43-
44-
if [[ -z $CLUSTER_DOMAIN ]]; then
45-
echo "Error: Could not determine cluster domain. Using example.com for testing."
46-
CLUSTER_DOMAIN="example.com"
40+
echo "Error: Could not determine cluster domain from ibmcloud-cluster-info configmap."
41+
echo "Please ensure the ibmcloud-cluster-info configmap exists in namespace $CSDB_NAMESPACE"
42+
exit 1
4743
fi
4844

4945
echo "Detected cluster domain: $CLUSTER_DOMAIN"
5046

51-
NEW_IDP_URL="https://cp-console.${CSDB_NAMESPACE}.${CLUSTER_DOMAIN}/idprovider/v1/auth"
52-
echo "New IDP URL will be: $NEW_IDP_URL"
53-
54-
# Perform the update
55-
echo "Updating IDP configuration..."
56-
oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c "
57-
UPDATE accountiam.idp_config
58-
SET idp = '$NEW_IDP_URL',
59-
modified_ts = NOW()
60-
WHERE idp LIKE '%/idprovider/v1/%';
61-
"
47+
NEW_IDP_URL="https://${CLUSTER_DOMAIN}/idprovider/v1/auth"
48+
echo "Target IDP URL: $NEW_IDP_URL"
49+
50+
# Check current IDP configuration first
51+
echo "Checking current IDP configuration..."
52+
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 "")
53+
54+
if [[ -n $CURRENT_IDP ]] && [[ $CURRENT_IDP != $NEW_IDP_URL ]]; then
55+
echo "Current IDP URL: $CURRENT_IDP"
56+
echo "Updating IDP configuration..."
57+
58+
# Perform the update
59+
oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c "
60+
UPDATE accountiam.idp_config
61+
SET idp = '$NEW_IDP_URL',
62+
modified_ts = NOW()
63+
WHERE idp LIKE '%/idprovider/v1/%';
64+
"
65+
elif [[ $CURRENT_IDP == $NEW_IDP_URL ]]; then
66+
echo "IDP configuration already matches target URL, no update needed."
67+
echo "Current IDP URL: $CURRENT_IDP"
68+
else
69+
echo "No IDP configuration found in database, skipping update."
70+
fi
6271

6372
echo "IDP configuration AFTER update:"
6473
oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c "

0 commit comments

Comments
 (0)