Skip to content

Commit bf8dbbf

Browse files
committed
get route from IM configmap
Signed-off-by: YuChen <[email protected]>
1 parent 1eddfb2 commit bf8dbbf

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
@@ -121,41 +121,53 @@ data:
121121
function update_idp_config {
122122
info "Updating IDP configuration with actual cluster domain..."
123123
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 "")
126126
127127
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."
129129
return 1
130130
fi
131131
132132
info "Detected cluster domain: $CLUSTER_DOMAIN"
133133
134-
NEW_IDP_URL="https://cp-console.${CSDB_NAMESPACE}.${CLUSTER_DOMAIN}/idprovider/v1/auth"
134+
NEW_IDP_URL="https://${CLUSTER_DOMAIN}/idprovider/v1/auth"
135135
136-
info "Updating IDP URLs to: $NEW_IDP_URL"
136+
info "Target IDP URL: $NEW_IDP_URL"
137137
138138
# Check if account_iam database exists
139139
ACCOUNT_IAM_EXISTS=$(oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -c "\list" | grep "account_iam" || echo False)
140140
141141
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 "")
148144
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
157169
else
158-
warning "account_iam database not found, skipping IDP configuration update."
170+
info "account_iam database not found, IDP configuration update not applicable."
159171
fi
160172
}
161173

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)