diff --git a/github_repo/create-cluster-site.yaml b/github_repo/create-cluster-site.yaml index d8fa7261..3cc4ea52 100644 --- a/github_repo/create-cluster-site.yaml +++ b/github_repo/create-cluster-site.yaml @@ -11,6 +11,8 @@ spec: value: "contract_uuid" - name: cluster_id value: "cluster_uuid" + - name: template_name + value: "template-std" templates: - name: createClusterSite activeDeadlineSeconds: 120 @@ -22,16 +24,52 @@ spec: - /bin/bash - -ecx - | + echo $TOKEN | gh auth login --with-token + + gh repo create tks-management/${CLUSTER_ID} --private --confirm + gh repo create tks-management/${CLUSTER_ID}-manifests --private --confirm + git clone https://${USERNAME}:${TOKEN}@github.com/tks-management/${CONTRACT_ID}.git - cd ${CONTRACT_ID} - cp -r template-site ${CLUSTER_ID} + + cp -r ${CONTRACT_ID}/${TEMPLATE_NAME} ${CLUSTER_ID}/${CLUSTER_ID} + cp -r ${CONTRACT_ID}/_github/ ${CLUSTER_ID}/.github + + sed -i "s/clusterName:\ cluster.local/clusterName:\ $CLUSTER_ID/g" $CLUSTER_ID/$CLUSTER_ID/tks-cluster/site-values.yaml + + echo "Contract ID: "${CONTRACT_ID} > ${CLUSTER_ID}/META + echo "Template Name: "${TEMPLATE_NAME} >> ${CLUSTER_ID}/META git config --global user.email "taco_support@sk.com" git config --global user.name "SKTelecom TACO" - git add ${CLUSTER_ID} + cd ${CLUSTER_ID} + git add .github + git add * + git commit -m "add new ${CLUSTER_ID} site" + git branch -M main + git remote set-url origin https://$(echo -n $TOKEN)@github.com/tks-management/${CLUSTER_ID} + git remote -v + git push -u origin main + cd .. + + cd ${CLUSTER_ID}-manifests + touch README + git add README git commit -m "add new ${CLUSTER_ID} site" - git push origin main + git branch -M main + git remote set-url origin https://$(echo -n $TOKEN)@github.com/tks-management/${CLUSTER_ID}-manifests + git remote -v + git push -u origin main + cd .. + + # buffer for starting the github action + sleep 30 + + # waiting for complete of the github action + cd ${CLUSTER_ID} + gh run list --workflow GenerateYaml --limit 1 + gh run watch $(gh run list --workflow GenerateYaml --limit 1| grep $CLUSTER_ID | awk -F push '{print $2}' | awk '{print $1}') + envFrom: - secretRef: name: "github-tks-mgmt-token" @@ -40,8 +78,39 @@ spec: value: "{{workflow.parameters.contract_id}}" - name: CLUSTER_ID value: "{{workflow.parameters.cluster_id}}" + - name: TEMPLATE_NAME + value: "{{workflow.parameters.template_name}}" + + - name: createRepoCredential + activeDeadlineSeconds: 120 + container: + name: 'createCredential' + image: docker.io/sktdev/argocd:latest + imagePullPolicy: IfNotPresent + command: + - /bin/bash + - -ecx + - | + echo "===== Connect github repo tks-management/${CLUSTER_ID}-manifests with token =====" + # log into Argo CD server + ./argocd login $ARGO_SERVER --plaintext --insecure --username $ARGO_USERNAME \ + --password $ARGO_PASSWORD + + ./argocd repo add https://github.com/tks-management/${CLUSTER_ID}-manifests --username ${USERNAME} --password ${TOKEN} + envFrom: + - secretRef: + name: "github-tks-mgmt-token" + - secretRef: + name: "decapod-argocd-config" + env: + - name: CLUSTER_ID + value: "{{workflow.parameters.cluster_id}}" + - name: main steps: - - name: createClusterSite template: createClusterSite arguments: {} + - - name: createRepoCredential + template: createRepoCredential + arguments: {} diff --git a/github_repo/create-contract-repo.yaml b/github_repo/create-contract-repo.yaml index f3b3ac83..d63c590f 100644 --- a/github_repo/create-contract-repo.yaml +++ b/github_repo/create-contract-repo.yaml @@ -27,7 +27,6 @@ spec: echo "===== Create and initialize tks-management/${CONTRACT_ID} site and manifests repositories =====" gh repo create tks-management/${CONTRACT_ID} --private --confirm - gh repo create tks-management/${CONTRACT_ID}-manifests --private --confirm cd ${CONTRACT_ID} echo -n ${TOKEN} | gh secret set API_TOKEN_GITHUB @@ -38,46 +37,16 @@ spec: git push new_contract main:main cd .. - git clone https://$(echo -n $TOKEN)@github.com/openinfradev/tks-user-site-template-manifests - cd tks-user-site-template-manifests - git remote add new_contract https://$(echo -n $TOKEN)@github.com/tks-management/${CONTRACT_ID}-manifests - git push new_contract main:main - cd .. envFrom: - secretRef: name: "github-tks-mgmt-token" env: - name: CONTRACT_ID value: "{{workflow.parameters.contract_id}}" - - name: createRepoCredential - activeDeadlineSeconds: 120 - container: - name: 'createCredential' - image: docker.io/sktdev/argocd:latest - imagePullPolicy: IfNotPresent - command: - - /bin/bash - - -ecx - - | - echo "===== Connect github repo tks-management/${CONTRACT_ID}-manifests with token =====" - # log into Argo CD server - ./argocd login $ARGO_SERVER --plaintext --insecure --username $ARGO_USERNAME \ - --password $ARGO_PASSWORD - ./argocd repo add https://github.com/tks-management/${CONTRACT_ID}-manifests --username ${USERNAME} --password ${TOKEN} - envFrom: - - secretRef: - name: "github-tks-mgmt-token" - - secretRef: - name: "decapod-argocd-config" - env: - - name: CONTRACT_ID - value: "{{workflow.parameters.contract_id}}" - name: main steps: - - name: createContractRepository template: createContractRepo arguments: {} - - - name: createRepoCredential - template: createRepoCredential - arguments: {} + diff --git a/tks-cluster/create-usercluster-wftpl.yaml b/tks-cluster/create-usercluster-wftpl.yaml index 1b93f362..e5b67fd8 100755 --- a/tks-cluster/create-usercluster-wftpl.yaml +++ b/tks-cluster/create-usercluster-wftpl.yaml @@ -11,6 +11,8 @@ spec: value: "0010010a-d6cb-459b-9148-1b02ac545753" - name: cluster_id value: "011b88fa-4d53-439f-9336-67845f994051" + - name: template_name + value: "template-std" - name: git_account value: "tks-management" - name: revision @@ -40,7 +42,9 @@ spec: - name: deploy steps: - - name: tks-create-cluster-site - template: new-cluster-site + templateRef: + name: tks-create-cluster-site + template: main - - name: k8s-by-capi templateRef: @@ -98,44 +102,3 @@ spec: env: - name: target value: "{{workflow.parameters.cluster_id}}" - - - name: new-cluster-site - container: - image: ghcr.io/openinfradev/python_kubectl:v1.0.1 - command: - - /bin/bash - - -exc - - | - git clone https://$(echo -n $gittoken)@github.com/$git_account/$contract_id.git - cd $contract_id - if [ -d $cluster_id ]; then - echo "Cluster($cluster_id) already exists." - exit 1 - fi - cp -r template-site $cluster_id - sed -i "s/clusterName:\ cluster.local/clusterName:\ $cluster_id/g" $cluster_id/tks-cluster/site-values.yaml - git config --global user.email "taco@tacocloud.com" - git config --global user.name "argo-workflow" - git add $cluster_id - git commit -m "new site: $cluster_id" - git push - - # buffer for starting the github action - sleep 30 - - # waiting for complete of the github action - echo $gittoken| gh auth login --with-token - gh run watch $(gh run list --workflow GenerateYaml --limit 1| grep $cluster_id | awk -F push '{print $2}' | awk '{print $1}') - - envFrom: - - secretRef: - name: "gittoken" - env: - - name: contract_id - value: "{{workflow.parameters.contract_id}}" - - name: cluster_id - value: "{{workflow.parameters.cluster_id}}" - - name: git_account - value: "{{workflow.parameters.git_account}}" - - name: revision - value: "{{workflow.parameters.revision}}" diff --git a/tks-cluster/tks-createapp-wftp.yaml b/tks-cluster/tks-createapp-wftp.yaml index bbdcef95..5d33ca09 100755 --- a/tks-cluster/tks-createapp-wftp.yaml +++ b/tks-cluster/tks-createapp-wftp.yaml @@ -41,7 +41,7 @@ spec: ./argocd login $ARGO_SERVER --plaintext --insecure --username $ARGO_USERNAME \ --password $ARGO_PASSWORD - REPO=https://$(echo -n $gittoken)@github.com/$git_account/${contract_id}-manifests.git + REPO=https://$(echo -n $gittoken)@github.com/$git_account/${SITE_NAME}-manifests.git # check if app already exists. ./argocd app get $CD_APP