Skip to content

Commit

Permalink
feature. implementation import stack
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Jul 17, 2024
1 parent 023267d commit da0c748
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 9 deletions.
82 changes: 74 additions & 8 deletions tks-cli/tks-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
- name: login-tks-api
container:
name: login-tks-api
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.1
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.2
envFrom:
- secretRef:
name: "tks-api-secret"
Expand All @@ -31,7 +31,7 @@ spec:
- name: description
container:
name: create-organization
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.1
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.2
envFrom:
- secretRef:
name: "tks-api-secret"
Expand Down Expand Up @@ -95,7 +95,7 @@ spec:
- name: cluster_domains
container:
name: create-usercluster
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.1
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.2
envFrom:
- secretRef:
name: "tks-api-secret"
Expand Down Expand Up @@ -166,7 +166,7 @@ spec:
- name: organization_id
container:
name: install-usercluster
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.1
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.2
envFrom:
- secretRef:
name: "tks-api-secret"
Expand Down Expand Up @@ -212,14 +212,80 @@ spec:
default: "Something wrong"
path: /mnt/out/cluster_id.txt

- name: import-usercluster
inputs:
parameters:
- name: cluster_name
- name: stack_template_id
- name: organization_id
- name: creator
- name: description
- name: policy_ids
- name: cluster_domains
- name: kubeconfig_string
container:
name: import-usercluster
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.2
envFrom:
- secretRef:
name: "tks-api-secret"
command:
- /bin/bash
- '-exc'
- |
tks login {{workflow.parameters.tks_api_url}} --organization-id ${ORGANIZATION_ID} --account-id ${ACCOUNT_ID} --password ${PASSWORD}
CL_NAME="{{inputs.parameters.cluster_name}}"
echo "* Import $CL_NAME cluster"
tks cluster import ${CL_NAME} \
--stack-template-id "{{inputs.parameters.stack_template_id}}" \
--organization-id "{{inputs.parameters.organization_id}}" \
--description "{{inputs.parameters.description}}" \
--cluster-type "USER" \
--kubeconfig-string "{{inputs.parameters.kubeconfig_string}}" \
--domains "{{inputs.parameters.cluster_domains}}" \
--policy-ids "{{inputs.parameters.policy_ids}}"
threshold=720
for i in $(seq 1 $threshold)
do
CL_STATUS=$(tks cluster list "{{inputs.parameters.organization_id}}" | grep -w $CL_ID | awk '{ print $4 }')
if [ "$CL_STATUS" = "RUNNING" ]; then
break
elif [ "$CL_STATUS" = "ERROR" ]; then
exit 1
fi
if [ "$i" -ge "$threshold" ]; then
echo "Timed out waiting for user-cluster to be ready."
exit 1
fi
sleep 5
done
tks cluster list "{{inputs.parameters.organization_id}}" | grep -w $CL_ID | awk '{print $3}' | tee /mnt/out/cluster_id.txt
volumeMounts:
- name: out
mountPath: /mnt/out
volumes:
- name: out
emptyDir: { }
outputs:
parameters:
- name: cluster-id
valueFrom:
default: "Something wrong"
path: /mnt/out/cluster_id.txt

- name: delete-usercluster
inputs:
parameters:
- name: organization_id
- name: cluster_id
container:
name: delete-usercluster
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.1
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.2
envFrom:
- secretRef:
name: "tks-api-secret"
Expand Down Expand Up @@ -262,7 +328,7 @@ spec:
- name: description
container:
name: create-appgroup
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.1
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.2
envFrom:
- secretRef:
name: "tks-api-secret"
Expand Down Expand Up @@ -312,7 +378,7 @@ spec:
- name: appgroup_id
container:
name: delete-appgroup
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.1
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.2
envFrom:
- secretRef:
name: "tks-api-secret"
Expand Down Expand Up @@ -352,7 +418,7 @@ spec:
- name: name
container:
name: get-appgroup-id
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.1
image: harbor.taco-cat.xyz/tks/tks-e2e-test:v3.2.2
envFrom:
- secretRef:
name: "tks-api-secret"
Expand Down
1 change: 0 additions & 1 deletion tks-cluster/import-usercluster-wftpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ spec:
value: "{{steps.tks-get-cluster-info.outputs.parameters.cluster_domains}}"
- name: cluster_id
value: "{{ workflow.parameters.cluster_id }}"
when: "{{steps.tks-create-cluster-repo.outputs.parameters.infra_provider}} == byoh"

- - name: init-cluster-for-tks
template: init-cluster-for-tks
Expand Down
96 changes: 96 additions & 0 deletions tks-stack/tks-stack-import.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: tks-stack-import
namespace: argo
spec:
entrypoint: main
arguments:
parameters:
- name: tks_api_url
value: "http://tks-api.tks.svc:9110"
- name: organization_id
value: ""
- name: stack_template_id
value: "NULL"
- name: creator
value: ""
- name: description
value: ""
- name: object_store
value: "s3"
- name: base_repo_branch
value: develop
- name: policy_ids
value: ""
- name: cluster_domains
value: ""
- name: kubeconfig_string
value: ""

templates:
- name: main
steps:
- - name: tks-get-stack-template-type
templateRef:
name: tks-get-stack-template-type
template: getTksGetStackTemplateType

- - name: call-import-usercluster
templateRef:
name: tks-cli
template: import-usercluster
arguments:
parameters:
- name: cluster_name
value: "{{workflow.parameters.cluster_name}}"
- name: stack_template_id
value: "{{workflow.parameters.stack_template_id}}"
- name: organization_id
value: "{{workflow.parameters.organization_id}}"
- name: creator
value: "{{workflow.parameters.creator}}"
- name: description
value: "{{workflow.parameters.description}}"
- name: policy_ids
value: "{{workflow.parameters.policy_ids}}"
- name: cluster_domains
value: "{{workflow.parameters.cluster_domains}}"
- name: kubeconfig_string
value: "{{workflow.parameters.kubeconfig_string}}"

- - name: call-create-appgroup-for-LMA
templateRef:
name: tks-cli
template: create-appgroup
arguments:
parameters:
- name: cluster_id
value: "{{steps.call-import-usercluster.outputs.parameters.cluster-id}}"
- name: name
value: "{{steps.call-import-usercluster.outputs.parameters.cluster-id}}_lma"
- name: type
value: "LMA"
- name: creator
value: "{{workflow.parameters.creator}}"
- name: description
value: "{{workflow.parameters.description}}"

- - name: call-create-appgroup-for-SERVICEMESH
templateRef:
name: tks-cli
template: create-appgroup
arguments:
parameters:
- name: cluster_id
value: "{{steps.call-import-usercluster.outputs.parameters.cluster-id}}"
- name: name
value: "{{steps.call-import-usercluster.outputs.parameters.cluster-id}}_servicemesh"
- name: type
value: "SERVICE_MESH"
- name: creator
value: "{{workflow.parameters.creator}}"
- name: description
value: "{{workflow.parameters.description}}"
when: "{{steps.tks-get-stack-template-type.outputs.parameters.stack_template_type}} == MSA"

0 comments on commit da0c748

Please sign in to comment.