@@ -147,12 +147,6 @@ spec:
147
147
]
148
148
when : " {{workflow.parameters.object_store}} == s3"
149
149
150
- # TODO: 전체 완성을 위해서는 아래내역을 구현하여 동적인 bucket을 만드는 방식으로 구현해야 하지만
151
- # 5월 오픈전 가능한 형상을 위해 협의한 바(아래)에 따라 본부분은 기존 준비됀 것을 사용하는 것으로 구현하고 추후 수정하다.
152
- # 1. 사용자가 생성하는 첫번째 클러스터는 primary cluster
153
- # 2. primary cluster는 계약이 종료되기 전까지 임의 삭제불가
154
- # 3. 개별 클러스터에서 수행되는 모니터링은 없고 계약단위에서 수행되어야 함
155
- # 하지만 이부분에 datasource 바꿔주는 부분을 포함하고 있으므로 일단 한번 타야할듯...
156
150
- - name : change-target
157
151
template : change-logging-target
158
152
arguments :
@@ -216,6 +210,28 @@ spec:
216
210
- name : primary_cluster
217
211
- name : member_clusters
218
212
steps :
213
+
214
+ - - name : change-thanos-sidecar
215
+ template : sub-change-thanos-sidecar
216
+ arguments :
217
+ parameters :
218
+ - name : primary_cluster
219
+ value : ' {{inputs.parameters.primary_cluster}}'
220
+ - name : member_clusters
221
+ value : ' {{inputs.parameters.member_clusters}}'
222
+
223
+ - - name : render-current-cluster
224
+ templateRef :
225
+ name : event-gitea-render-manifests
226
+ template : main
227
+ arguments :
228
+ parameters :
229
+ - name : decapod_site_repo
230
+ value : " {{ workflow.parameters.github_account }}/{{ workflow.parameters.cluster_id }}"
231
+ - name : base_repo_branch
232
+ value : " {{ workflow.parameters.base_repo_branch }}"
233
+ when : " {{steps.change-thanos-sidecar.outputs.parameters.changed}} != 'NO_CHANGE_HERE'" # 이미 변경내역이 반영된 (한번 수행됐던) 클러스터라면 랜더링은 필요없음
234
+
219
235
- - name : sync-organization-changes
220
236
template : sub-sync-organization-changes
221
237
arguments :
@@ -232,10 +248,10 @@ spec:
232
248
arguments :
233
249
parameters :
234
250
- name : decapod_site_repo
235
- value : " {{ workflow.parameters.github_account }}/{{steps.sync-organization-changes.outputs.parameters.primary_cluster }}"
251
+ value : " {{ workflow.parameters.github_account }}/{{steps.sync-organization-changes.outputs.parameters.changed }}"
236
252
- name : base_repo_branch
237
253
value : " {{ workflow.parameters.base_repo_branch }}"
238
- when : " {{steps.sync-organization-changes.outputs.parameters.primary_cluster }} != 'NO_CHANGE_HERE'"
254
+ when : " {{steps.sync-organization-changes.outputs.parameters.changed }} != 'NO_CHANGE_HERE'"
239
255
240
256
# ######################
241
257
# Template Definition #
@@ -258,22 +274,9 @@ spec:
258
274
retryStrategy :
259
275
limit : 2
260
276
261
- # - name: sub-prepare-bucket
262
- # inputs:
263
- # parameters:
264
- # - name: primary_cluster
265
- # container:
266
- # name: prepare-bucket
267
- # image: harbor.taco-cat.xyz/tks/hyperkube:v1.18.6
268
- # command:
269
- # - /bin/bash
270
- # - '-c'
271
- # - |
272
- # echo "prepare bucket for the '{{workflow.parameters.organization_id}}' (clusters: '{{inputs.parameters.primary_cluster}}')"
273
- # activeDeadlineSeconds: 900
274
- # retryStrategy:
275
- # limit: 2
276
-
277
+ # function sub-pre-change-logging-target
278
+ # 1. Change endpoint of fluentbit-output (all in org.)
279
+ # 2. Change endpoint of thanos-sidecar in prometheus-pod (all in org.)
277
280
- name : sub-pre-change-logging-target
278
281
inputs :
279
282
parameters :
@@ -546,6 +549,104 @@ spec:
546
549
path : /mnt/out/modified_cluster_list.txt
547
550
activeDeadlineSeconds : 900
548
551
552
+ - name : sub-change-thanos-sidecar
553
+ inputs :
554
+ parameters :
555
+ - name : primary_cluster
556
+ - name : member_clusters
557
+ container :
558
+ name : logging-target-changer
559
+ image : harbor.taco-cat.xyz/tks/shyaml_jq_yq_kubectl_python:3.11
560
+ command :
561
+ - /bin/bash
562
+ - ' -c'
563
+ - |
564
+ #/bin/bash
565
+
566
+ set -ex
567
+
568
+ function log() {
569
+ level=$1
570
+ msg=$2
571
+ date=$(date '+%F %H:%M:%S')
572
+ echo "[$date] $level $msg"
573
+ }
574
+
575
+ current_cluster={{workflow.parameters.cluster_id}}
576
+ primary_cluster={{inputs.parameters.primary_cluster}}
577
+ member_clusters="{{inputs.parameters.member_clusters}}"
578
+ empty_char=
579
+
580
+ if [ -z ${primary_cluster} ] || [ "${primary_cluster}" = "$empty_char" ]; then
581
+ primary_cluster=${current_cluster}
582
+ fi
583
+
584
+ S3_Service="s3://ap-northeast-2"
585
+ cp /kube/value kubeconfig_adm
586
+ export KUBECONFIG=kubeconfig_adm
587
+
588
+ #################
589
+ # updates
590
+ #################
591
+ GIT_ACCOUNT={{workflow.parameters.github_account}}
592
+ if [[ $GIT_SVC_URL == https://* ]]; then
593
+ repository_base=https://${TOKEN//[$'\t\r\n ']}@${GIT_SVC_URL/http:\/\//}/${GIT_ACCOUNT}/
594
+ else
595
+ repository_base=http://${TOKEN//[$'\t\r\n ']}@${GIT_SVC_URL/http:\/\//}/${GIT_ACCOUNT}/
596
+ fi
597
+
598
+ log "INFO" "##### change the loki target to $LOKI_HOST:$LOKI_PORT and $S3_Service (the current target is ${current_cluster})"
599
+ [ -d ${current_cluster} ] || git clone ${repository_base}${current_cluster}
600
+ cd ${current_cluster}
601
+
602
+ yq -i e "del(.charts[] | select(.name == \"thanos-config\").override.objectStorage)" ${current_cluster}/lma/site-values.yaml
603
+ yq -i e ".charts |= map(select(.name == \"thanos-config\").override.objectStorage.type=\"s3\")" ${current_cluster}/lma/site-values.yaml
604
+ yq -i e ".charts |= map(select(.name == \"thanos-config\").override.objectStorage.rawConfig.endpoint=\"s3.ap-northeast-2.amazonaws.com\")" ${current_cluster}/lma/site-values.yaml
605
+ yq -i e ".charts |= map(select(.name == \"thanos-config\").override.objectStorage.rawConfig.region=\"ap-northeast-2\")" ${current_cluster}/lma/site-values.yaml
606
+ yq -i e ".charts |= map(select(.name == \"thanos-config\").override.objectStorage.rawConfig.bucket=\"${primary_cluster}-tks-thanos\")" ${current_cluster}/lma/site-values.yaml
607
+ yq -i e ".charts |= map(select(.name == \"thanos-config\").override.objectStorage.rawConfig.signature_version2=false)" ${current_cluster}/lma/site-values.yaml
608
+
609
+ git config --global user.name "tks"
610
+ git config --global user.email "[email protected] "
611
+
612
+ if [[ `git status --porcelain` ]]; then
613
+ log "INFO" "##### commit changes on ${current_cluster} to use s3"
614
+ cmessage="changes on ${current_cluster} to use s3"
615
+ git add ${current_cluster}/lma/site-values.yaml
616
+ git commit -m "change loki and thanos endpoints. (by set-primary workflow)" -m "$cmessage"
617
+ git push
618
+ modified_clusters=${current_cluster}
619
+ # echo -n "${current_cluster} " >> /mnt/out/modified_cluster_list.txt
620
+ else
621
+ log "INFO" "No change on the cluster ${current_cluster}"
622
+ echo NO_CHANGE_HERE > /mnt/out/modified_cluster_list.txt
623
+ fi
624
+ cd -
625
+ rm -rf ${current_cluster}
626
+
627
+ jq -n '$ARGS.positional' --args $modified_clusters > /mnt/out/modified_cluster_list.txt
628
+
629
+ env :
630
+ - name : OBJECT_SOTRE
631
+ value : " {{workflow.parameters.object_store}}"
632
+ envFrom :
633
+ - secretRef :
634
+ name : " git-svc-token"
635
+ volumeMounts :
636
+ - name : kubeconfig-adm
637
+ mountPath : " /kube"
638
+ - name : out
639
+ mountPath : /mnt/out
640
+ volumes :
641
+ - name : out
642
+ emptyDir : {}
643
+ outputs :
644
+ parameters :
645
+ - name : changed
646
+ valueFrom :
647
+ path : /mnt/out/modified_cluster_list.txt
648
+ activeDeadlineSeconds : 900
649
+
549
650
- name : sub-sync-organization-changes
550
651
inputs :
551
652
parameters :
@@ -658,10 +759,10 @@ spec:
658
759
git add ${primary_cluster}/lma/site-values.yaml
659
760
git commit -m "change thanos-query stores. (by set-primary workflow)" -m "$cmessage"
660
761
git push
661
- echo ${primary_cluster} > /mnt/out/primary_cluster .txt
762
+ echo ${primary_cluster} > /mnt/out/changed .txt
662
763
else
663
764
log "INFO" "No change on the cluster ${member}"
664
- echo NO_CHANGE_HERE > /mnt/out/primary_cluster .txt
765
+ echo NO_CHANGE_HERE > /mnt/out/changed .txt
665
766
fi
666
767
667
768
if [ "$OBJECT_SOTRE" != "s3" ]; then
@@ -673,7 +774,7 @@ spec:
673
774
git add ${primary_cluster}/lma/site-values.yaml
674
775
git commit -m "change iamRoles(s3). (by set-primary workflow)" -m "$cmessage"
675
776
git push
676
- echo ${primary_cluster} > /mnt/out/primary_cluster .txt
777
+ echo ${primary_cluster} > /mnt/out/changed .txt
677
778
else
678
779
log "INFO" "(iamRoles) No change on the cluster ${member}"
679
780
fi
@@ -702,9 +803,9 @@ spec:
702
803
emptyDir : {}
703
804
outputs :
704
805
parameters :
705
- - name : primary_cluster
806
+ - name : changed
706
807
valueFrom :
707
- path : /mnt/out/primary_cluster .txt
808
+ path : /mnt/out/changed .txt
708
809
activeDeadlineSeconds : 900
709
810
710
811
0 commit comments