@@ -14,10 +14,12 @@ check_required_param() {
14
14
15
15
# Constants:
16
16
CODEFRESH_SECRET_NAME=" codefresh-token"
17
+ CODEFRESH_CM_NAME=" codefresh-cm"
17
18
REPO_CREDS_SECRET_NAME=" autopilot-secret"
18
19
ARGOCD_TOKEN_SECRET_NAME=" argocd-token"
19
20
ARGOCD_INITIAL_TOKEN_SECRET_NAME=" argocd-initial-admin-secret"
20
21
BOOTSTRAP_APP_NAME=" csdp-bootstrap"
22
+ ADDITIONAL_COMPONENTS_MANAGED=" \nevents-reporter"
21
23
ADDITIONAL_COMPONENTS=" \nevents-reporter\nrollout-reporter\nworkflow-reporter"
22
24
RUNTIME_DEF_URL=" https://github.com/codefresh-io/csdp-official-poc/releases/VERSION/download/runtime.yaml"
23
25
@@ -37,6 +39,7 @@ CSDP_GIT_INTEGRATION_PROVIDER="${CSDP_GIT_INTEGRATION_PROVIDER:-GITHUB}"
37
39
CSDP_GIT_INTEGRATION_API_URL=" ${CSDP_GIT_INTEGRATION_API_URL:- https:// api.github.com} "
38
40
CSDP_GIT_INTEGRATION_TOKEN=" ${CSDP_GIT_INTEGRATION_TOKEN:- ${CSDP_RUNTIME_GIT_TOKEN} } "
39
41
CSDP_RUNTIME_REPO_CREDS_PATTERN=` echo ${CSDP_RUNTIME_REPO} | grep --color=never -E -o ' ^http[s]?:\/\/([a-zA-Z0-9\.]*)' `
42
+ CSDP_MANAGED_RUNTIME=" ${CSDP_MANAGED_RUNTIME:- false} "
40
43
41
44
create_codefresh_secret () {
42
45
# Download runtime definition
@@ -50,12 +53,16 @@ create_codefresh_secret() {
50
53
echo " "
51
54
52
55
# Prepare components for request
56
+
57
+ if [[ " $CSDP_MANAGED_RUNTIME " == " true" ]] ; then
58
+ ADDITIONAL_COMPONENTS=${ADDITIONAL_COMPONENTS_MANAGED}
59
+ fi
53
60
COMPONENT_NAMES=` echo " $RUNTIME_DEF " | yq e ' .spec.components.[].name' -`
54
61
COMPONENT_NAMES=` printf " ${COMPONENT_NAMES}${ADDITIONAL_COMPONENTS} " | tr ' \n' ' ' `
55
- COMPONENTS=" [\" argo-cd\" "
62
+ COMPONENTS=" [\" csdp- argo-cd\" "
56
63
for COMPONENT in $COMPONENT_NAMES
57
64
do
58
- CUR_COMPONENT=` echo -n " \" ${CSDP_RUNTIME_NAME} -${COMPONENT} \" " `
65
+ CUR_COMPONENT=` echo -n " \" csdp -${COMPONENT} \" " `
59
66
COMPONENTS=" ${COMPONENTS} ,${CUR_COMPONENT} "
60
67
done
61
68
COMPONENTS=" ${COMPONENTS} ]"
@@ -83,6 +90,13 @@ create_codefresh_secret() {
83
90
--compressed \
84
91
--insecure \
85
92
--data-raw " $RUNTIME_CREATE_DATA " `
93
+
94
+ if ` echo " $RUNTIME_CREATE_RESPONSE " | jq -e ' has("errors")' ` ; then
95
+ echo " Failed to create runtime"
96
+ echo ${RUNTIME_CREATE_RESPONSE}
97
+ exit 1
98
+ fi
99
+
86
100
RUNTIME_ACCESS_TOKEN=` echo $RUNTIME_CREATE_RESPONSE | jq ' .data.createRuntime.newAccessToken' `
87
101
RUNTIME_ENCRYPTION_IV=` hexdump -n 16 -e ' 4/4 "%08x" 1 "\n"' /dev/urandom`
88
102
echo " --> Runtime created!"
@@ -163,6 +177,24 @@ create_repo_creds_secret() {
163
177
" | kubectl apply -f -
164
178
}
165
179
180
+ create_managed_repo_creds_secret () {
181
+ echo " --> Creating managed repo credentials secret"
182
+ echo "
183
+ apiVersion: v1
184
+ kind: Secret
185
+ metadata:
186
+ labels:
187
+ argocd.argoproj.io/secret-type: repository
188
+ name: $REPO_CREDS_SECRET_NAME
189
+ namespace: $NAMESPACE
190
+ stringData:
191
+ type: git
192
+ url: $CSDP_RUNTIME_REPO
193
+ password: $CSDP_RUNTIME_GIT_TOKEN
194
+ username: username
195
+ " | kubectl apply -f -
196
+ }
197
+
166
198
create_argocd_token_secret () {
167
199
echo " --> Reading ArgoCD intial admin token..."
168
200
INITIAL_PASSWORD=` kubectl -n ${NAMESPACE} get secret ${ARGOCD_INITIAL_TOKEN_SECRET_NAME} -o=jsonpath=" {.data.password}" | base64 -d`
@@ -214,7 +246,9 @@ create_git_integration() {
214
246
echo " --> Created git integration:"
215
247
echo " ${GIT_INTEGRATION_CREATE_RESPONSE} "
216
248
echo " "
249
+ }
217
250
251
+ register_to_git_integration () {
218
252
echo " --> Registering user to default git integration"
219
253
220
254
GIT_INTEGRATION_REGISTER_ARGS=" {
@@ -233,7 +267,13 @@ create_git_integration() {
233
267
--insecure \
234
268
--data-raw " $GIT_INTEGRATION_REGISTER_DATA " `
235
269
236
- echo " --> Register to default git integration:"
270
+ if ` echo " $GIT_INTEGRATION_REGISTER_RESPONSE " | jq -e ' has("errors")' ` ; then
271
+ echo " Failed to register git integration"
272
+ echo ${GIT_INTEGRATION_REGISTER_RESPONSE}
273
+ exit 1
274
+ fi
275
+
276
+ echo " --> Registered to default git integration:"
237
277
echo " ${GIT_INTEGRATION_REGISTER_RESPONSE} "
238
278
echo " "
239
279
}
@@ -255,6 +295,7 @@ echo " runtime git-token: ****"
255
295
echo " runtime cluster: ${CSDP_RUNTIME_CLUSTER} "
256
296
echo " runtime name: ${CSDP_RUNTIME_NAME} "
257
297
echo " runtime version: ${CSDP_RUNTIME_VERSION} "
298
+ echo " managed runtime: ${CSDP_MANAGED_RUNTIME} "
258
299
echo " runtime ingress: ${CSDP_RUNTIME_INGRESS_URL} "
259
300
echo " ingress class name: ${CSDP_INGRESS_CLASS_NAME} "
260
301
echo " ingress controller: ${CSDP_INGRESS_CONTROLLER} "
@@ -280,7 +321,12 @@ if kubectl -n "$NAMESPACE" get secret "$REPO_CREDS_SECRET_NAME"; then
280
321
else
281
322
echo " --> Secret $REPO_CREDS_SECRET_NAME doesn't exists."
282
323
echo " "
283
- create_repo_creds_secret
324
+
325
+ if [[ " $CSDP_MANAGED_RUNTIME " == " true" ]] ; then
326
+ create_managed_repo_creds_secret
327
+ else
328
+ create_repo_creds_secret
329
+ fi
284
330
fi
285
331
echo " "
286
332
echo " "
@@ -310,6 +356,11 @@ if kubectl -n "$NAMESPACE" get secret -l io.codefresh.integration-type=git -l io
310
356
else
311
357
echo " --> Default git integration exists"
312
358
fi
359
+
360
+ # 6. Register to git integration
361
+ if [[ " $CSDP_MANAGED_RUNTIME " == " true" ]] ; then
362
+ register_to_git_integration
363
+ fi
313
364
echo " "
314
365
315
366
echo " Done!"
0 commit comments