@@ -57,9 +57,9 @@ checkIfhostReachable() {
57
57
if [ -n " $custom_hostname " ]; then
58
58
echo " Given Custom Hostname: $custom_hostname "
59
59
if host " $custom_hostname " > /dev/null 2>&1 ; then
60
- echo " Host is reachable . Proceeding further..."
60
+ echo " Domain is defined . Proceeding further..."
61
61
else
62
- echo " $custom_hostname is not reachable . Exiting the script."
62
+ echo " $custom_hostname is not defined . Exiting the script."
63
63
exit 1
64
64
fi
65
65
fi
@@ -87,7 +87,16 @@ checkIfSecretExist
87
87
88
88
# delete completed job if exists
89
89
echo " Deleting old job of iam-custom-hostname if exists"
90
- oc delete job iam-custom-hostname --ignore-not-found -n $csNamespace
90
+ oc delete job iam-custom-hostname --ignore-not-found -n $map_to_common_service_namespace
91
+
92
+ operator_token=$( oc create token ibm-iam-operator -n $csNamespace )
93
+ if [[ -z " ${operator_token} " ]]
94
+ then
95
+ >&2 echo " Failed to set a ServiceAccount token; exit"
96
+ return 1
97
+ fi
98
+
99
+ oc project $map_to_common_service_namespace
91
100
92
101
echo " Running custom hostname job"
93
102
tmpfile=$( mktemp)
@@ -96,7 +105,7 @@ apiVersion: batch/v1
96
105
kind: Job
97
106
metadata:
98
107
name: iam-custom-hostname
99
- namespace: $csNamespace
108
+ namespace: $map_to_common_service_namespace
100
109
labels:
101
110
app: iam-custom-hostname
102
111
spec:
@@ -106,30 +115,42 @@ spec:
106
115
app: iam-custom-hostname
107
116
spec:
108
117
containers:
109
- - name: iam-custom-hostname
110
- image: icr.io/cpopen/cpfs/iam-custom-hostname:latest
111
- command: ["python3", "/scripts/saas_script.py"]
112
- imagePullPolicy: Always
113
- env:
114
- - name: OPENSHIFT_URL
115
- value: https://kubernetes.default:443
116
- - name: IDENTITY_PROVIDER_URL
117
- value: https://platform-identity-provider.$map_to_common_service_namespace .svc:4300
118
- - name: PLATFORM_AUTH_URL
119
- value: https://platform-auth-service.$map_to_common_service_namespace .svc:9443
120
- - name: POD_NAMESPACE
121
- value: $map_to_common_service_namespace
122
- - name: WLP_CLIENT_ID
123
- value: $wlp_client_id
124
- - name: WLP_CLIENT_SECRET
125
- value: $wlp_client_secret
126
- - name: OAUTH2_CLIENT_REGISTRATION_SECRET
127
- value: $oauth2_client_registration_secret
128
- - name: DEFAULT_ADMIN_USER
129
- value: $admin_username
130
- - name: DEFAULT_ADMIN_PASSWORD
131
- value: $admin_password
132
- serviceAccountName: ibm-iam-operator
118
+ - name: iam-custom-hostname
119
+ image: icr.io/cpopen/cpfs/iam-custom-hostname:latest
120
+ command: ["python3", "/scripts/saas_script.py"]
121
+ imagePullPolicy: Always
122
+ env:
123
+ - name: OPERATOR_TOKEN
124
+ value: $operator_token
125
+ - name: OPENSHIFT_URL
126
+ value: https://kubernetes.default:443
127
+ - name: IDENTITY_PROVIDER_URL
128
+ value: https://platform-identity-provider.$map_to_common_service_namespace .svc:4300
129
+ - name: PLATFORM_AUTH_URL
130
+ value: https://platform-auth-service:9443
131
+ - name: POD_NAMESPACE
132
+ value: $map_to_common_service_namespace
133
+ - name: WLP_CLIENT_ID
134
+ value: $wlp_client_id
135
+ - name: WLP_CLIENT_SECRET
136
+ value: $wlp_client_secret
137
+ - name: OAUTH2_CLIENT_REGISTRATION_SECRET
138
+ value: $oauth2_client_registration_secret
139
+ - name: DEFAULT_ADMIN_USER
140
+ value: $admin_username
141
+ - name: DEFAULT_ADMIN_PASSWORD
142
+ value: $admin_password
143
+ volumeMounts:
144
+ - name: provider-ca-volume
145
+ mountPath: /custom-certs
146
+ readOnly: true
147
+ volumes:
148
+ - name: provider-ca-volume
149
+ secret:
150
+ secretName: identity-provider-secret
151
+ items:
152
+ - key: ca.crt
153
+ path: ca.crt
133
154
restartPolicy: OnFailure
134
155
EOF
135
156
oc apply -f " $tmpfile "
@@ -143,6 +164,12 @@ check_job_completion() {
143
164
# Call the function to check job completion
144
165
check_job_completion iam-custom-hostname $csNamespace
145
166
167
+ # sleep for 10s and compare existing custom_hostname with the current route
168
+ sleep 15
169
+
170
+ oc delete pod -l app=platform-auth-service -n $map_to_common_service_namespace
171
+ echo " Triggered restart of platform-auth-service pods"
172
+
146
173
deployment_name=" platform-auth-service"
147
174
timeout_seconds=180 # assuming auth-service will come in 3 mins after restart
148
175
@@ -151,13 +178,9 @@ end_time=$((start_time + timeout_seconds))
151
178
152
179
while true ; do
153
180
status=$( oc get deployment " $deployment_name " -n $map_to_common_service_namespace -o jsonpath=' {.status.conditions[?(@.type=="Available")].status}' )
154
-
155
- echo " Triggered restart of platform-auth-service pod"
156
- oc delete pod -l app=platform-auth-service -n " $map_to_common_service_namespace "
157
- pod_phase=$( oc get pod -l app=platform-auth-service -n " $map_to_common_service_namespace " -o jsonpath=' {.items[0].status.phase}' 2> /dev/null)
158
181
159
- if [[ " $status " == " True" && " $pod_phase " == " Running " ]]; then
160
- echo " $deployment_name deployment is available and pod is running "
182
+ if [[ " $status " == " True" ]]; then
183
+ echo " $deployment_name is available. "
161
184
break
162
185
fi
163
186
@@ -170,11 +193,8 @@ while true; do
170
193
sleep 5 # Wait for 5 seconds before checking again
171
194
done
172
195
173
- # sleep for 10s and compare existing custom_hostname with the current route
174
- sleep 15
175
-
176
- username=$( oc get secret platform-auth-idp-credentials -n ibm-common-services -o json | jq -r .data.admin_username| base64 -d)
177
- password=$( oc get secret platform-auth-idp-credentials -n ibm-common-services -o json | jq -r .data.admin_password | base64 -d)
196
+ username=$( oc get secret platform-auth-idp-credentials -n $map_to_common_service_namespace -o json | jq -r .data.admin_username| base64 -d)
197
+ password=$( oc get secret platform-auth-idp-credentials -n $map_to_common_service_namespace -o json | jq -r .data.admin_password | base64 -d)
178
198
route=$( oc get routes cp-console -o jsonpath=' {.spec.host}' )
179
199
180
200
190
210
fi
191
211
192
212
new_hostname=$( oc get routes cp-console --no-headers | awk ' {print $2}' )
193
-
194
213
if [ " $new_hostname " = " $custom_hostname " ]; then
195
214
echo " successfully updated the custom hostname"
196
215
else
197
216
echo " update custom hostname failed "
198
- fi
217
+ fi
0 commit comments