Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change tks site repo structures #25

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 73 additions & 4 deletions github_repo/create-cluster-site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 "[email protected]"
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"
Expand All @@ -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: {}
33 changes: 1 addition & 32 deletions github_repo/create-contract-repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: {}

47 changes: 5 additions & 42 deletions tks-cluster/create-usercluster-wftpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 "[email protected]"
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}}"
2 changes: 1 addition & 1 deletion tks-cluster/tks-createapp-wftp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down