Skip to content

Commit

Permalink
add new workflow for set-primary-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
sungil committed Apr 5, 2023
1 parent 485c13a commit aeed3b8
Show file tree
Hide file tree
Showing 3 changed files with 605 additions and 16 deletions.
127 changes: 111 additions & 16 deletions deploy_apps/tks-lma-federation-wftpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ spec:
- name: logging_component
value: "loki"
- name: github_account
value: "tks-management"
value: "decapod10"
- name: manifest_repo_url
value: "https://github.com/openinfradev/decapod-manifests"
value: "https://github.com/decapod10/c3c16juq5-manifests"
- name: revision
value: "main"
- name: organization_id
value: "o086tb3zc"
- name: app_prefix
value: "{{workflow.parameters.site_name}}"
##########################
Expand All @@ -25,22 +27,50 @@ spec:
- name: tks_info_host
value: "http://tks-api.tks.svc:9110"
- name: cluster_id
value: "Cabbead61"
value: "c3c16juq5"
- name: app_group_id
value: "Aabbead61"
value: "a60sfxh4v"

volumes:
- name: tks-proto-vol
configMap:
name: tks-proto
templates:
- name: deployLMA
steps:
- - name: createNamespace
template: createNamespace
# - - name: createNamespace
# template: createNamespace
# arguments:
# parameters:
# - name: target_namespace
# value: lma

- - name: get-clusters-in-contract
templateRef:
name: tks-primary-cluster
template: sub-get-cluster

- - name: set-this-to-primary-cluster
templateRef:
name: tks-primary-cluster
template: set-primary-cluster
arguments:
parameters:
- name: primary_cluster
value: '{{steps.get-clusters-in-contract.outputs.parameters.primary_cluster}}'
- name: member_clusters
value: '{{steps.get-clusters-in-contract.outputs.parameters.member_clusters}}'
when: "{{steps.get-clusters-in-contract.outputs.parameters.primary_cluster}} == null"

- - name: organization-level-update
template: primayCluster
arguments:
parameters:
- name: target_namespace
value: lma
- name: primary_cluster
value: '{{steps.get-clusters-in-contract.outputs.parameters.primary_cluster}}'
- name: member_clusters
value: '{{workflow.parameters.cluster_id}}'
when: "{{steps.get-clusters-in-contract.outputs.parameters.primary_cluster}} != null && {{workflow.parameters.cluster_id}} != {{steps.get-clusters-in-contract.outputs.parameters.primary_cluster}}"

- - name: installApps
templateRef:
Expand All @@ -66,7 +96,7 @@ spec:
# LMA appGroup specific task #
- - name: collectThanosScEndpoints
template: collectThanosScEndpoints
arguments:
arguments:====
# These params should be moved to global argument? #
parameters:
- name: tks_info_host
Expand All @@ -88,7 +118,7 @@ spec:
value: "lma"
- name: chart
value: "thanos"
- name: kv_map_str
- name: kv_map_str
value: "{'querier.stores': '{{steps.GetMyThanosScEndpoint.outputs.parameters.my_thanos_sc_ep}}'}"
withParam: "{{steps.collectThanosScEndpoints.outputs.parameters.outwards_cluster_list}}"

Expand Down Expand Up @@ -151,6 +181,72 @@ spec:
retryStrategy:
limit: 2

- name: primayCluster
inputs:
parameters:
- name: primary_cluster
- name: member_clusters
container:
name: logging-target-changer
image: harbor-cicd.taco-cat.xyz/tks/hyperkube:v1.18.6
command:
- /bin/bash
- '-c'
- |
function log() {
level=$1
msg=$2
date=$(date '+%F %H:%M:%S')
echo "[$date] $level $msg"
}
# Check endpoints from the primary_cluster
primary_cluster={{inputs.parameters.primary_cluster}}
echo __${primary_cluster}__
if [ -z primary_cluster ] || [ primary_cluster="null" ]; then
primary_cluster={{workflow.parameters.cluster_id}}
fi
echo kubectl get secret -n ${primary_cluster} ${primary_cluster}-kubeconfig -o jsonpath="{.data.value}"
primary_kube_secret=$(kubectl get secret -n ${primary_cluster} ${primary_cluster}-kubeconfig -o jsonpath="{.data.value}" | base64 -d)
echo -e "primary_kube_secret:\n$primary_kube_secret" | head -n 5
cat <<< "$primary_kube_secret" > kubeconfig
while [ -z $(kubectl --kubeconfig=kubeconfig get svc -n lma loki-loki-distributed-gateway -o jsonpath="{.status.loadBalancer.ingress[*].hostname}") ]
do
echo "Waiting for generating the loadbalancer of LOKI(3s)"
sleep 3
done
LOKI_HOST=$(kubectl --kubeconfig=kubeconfig get svc -n lma loki-loki-distributed-gateway -o jsonpath="{.status.loadBalancer.ingress[0].hostname}")
LOKI_PORT=$(kubectl --kubeconfig=kubeconfig get svc -n lma loki-loki-distributed-gateway -o jsonpath="{.spec.ports[0].port}")
THANOS_HOST=$(kubectl --kubeconfig=kubeconfig get svc -n lma loki-loki-distributed-gateway -o jsonpath="{.status.loadBalancer.ingress[0].hostname}")
THANOS_PORT=$(kubectl --kubeconfig=kubeconfig get svc -n lma loki-loki-distributed-gateway -o jsonpath="{.spec.ports[0].port}")
THANOS_URL=${THANOS_HOST}:${THANOS_PORT}
echo "DEBUG: received parameters: {{inputs.parameters.primary_cluster}}:{{inputs.parameters.member_clusters}}:{{workflow.parameters.cluster_id}} "
echo "DEBUG: for the input i get: $LOKI_HOST $LOKI_PORT $THANOS_HOST $THANOS_PORT"
exit 0
# update primary
kube_secret=$(kubectl get secret -n {{workflow.parameters.cluster_id}} {{workflow.parameters.cluster_id}}-kubeconfig -o jsonpath="{.data.value}" | base64 -d)
echo -e "kube_secret:\n$kube_secret" | head -n 5
cat <<< "$kube_secret" > /etc/kubeconfig
kubectl --kubeconfig=/etc/kubeconfig get ns ${TARGET_NAMESPACE}
if [[ $? =~ 1 ]]; then
kubectl --kubeconfig=/etc/kubeconfig create ns ${TARGET_NAMESPACE}
kubectl --kubeconfig=/etc/kubeconfig label ns ${TARGET_NAMESPACE} name=${TARGET_NAMESPACE}
kubectl --kubeconfig=/etc/kubeconfig label ns ${TARGET_NAMESPACE} taco-tls=enabled
log "INFO" "${TARGET_NAMESPACE} successfully created."
fi
activeDeadlineSeconds: 900
retryStrategy:
limit: 2

- name: GetMyThanosScEndpoint
inputs:
parameters:
Expand Down Expand Up @@ -193,7 +289,6 @@ spec:
echo "$thanos_sc_ep:$THANOS_SC_PORT" > /mnt/out/thanos_sc_ep.txt
fi
- name: collectThanosScEndpoints
inputs:
parameters:
Expand All @@ -213,7 +308,7 @@ spec:
volumes:
- name: out
emptyDir: {}
script:
script:
name: 'collect'
image: harbor-cicd.taco-cat.xyz/tks/centos-tks-api:v1.0
command: ["python"]
Expand Down Expand Up @@ -306,10 +401,10 @@ spec:
headers={"Authorization": "Bearer " + TOKEN} )
if res.status_code != 200 :
print( 'Failed to get appgroups for cluster ')
continue
continue
appGroups = res.json()['appGroups']
print( appGroups )
print( appGroups )
os.system("rm -rf ./tempcluster")
Expand All @@ -324,7 +419,7 @@ spec:
print( 'Failed to get applications for appgroup')
continue
applications = res.json()['applications']
applications = res.json()['applications']
if applications :
# This is based on the premise that there's only one prometheus per appGroup.
Expand All @@ -340,7 +435,7 @@ spec:
output_cluster_list.append(str_json)
# Compose profer format to be used as input on next step
# Compose profer format to be used as input on next step
inwards_endpoint_map['querier.stores'] = inwards_endpoint_list
###########################
Expand Down
Loading

0 comments on commit aeed3b8

Please sign in to comment.