Skip to content

Commit

Permalink
TACODEV-909: integrate postjobs, update version and so on
Browse files Browse the repository at this point in the history
- integrate postjobs - initialize k8s for taco and register to argocd
- change error on duplicated registration to warning
- change rbac to allow 'kubectl apply'
- update version for cluster-api-aws
- add README.md
  • Loading branch information
intelliguy committed Oct 7, 2021
1 parent 4d5e371 commit cad41cb
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 44 deletions.
1 change: 1 addition & 0 deletions cluster-api-aws/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
.idea/
*.tmproj
.vscode/
README.md
artifacts/Dockerfile
artifacts/helm
artifacts/gh
2 changes: 1 addition & 1 deletion cluster-api-aws/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ description: A chart to install Kubernetes cluster using Cluster API Provider AW

type: application

version: 0.3.1
version: 0.3.2

appVersion: "0.0.1"
35 changes: 35 additions & 0 deletions cluster-api-aws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# cluster-api-aws
This chart creates a kubernetes resource for the Cluster API for AWS (CAPA).
Since CAPA implementation is not a fully supported specification, this chart also includes several workaround tasks.
There are also some useful features, such as cluster registration of argocd servers.

## Resouce List
- AWSCluster
- AWSMachineTemplate
- Cluster
- ConfigMap
- Job
- Job-post
- KubeadmControlPlane
- RoleBinding
- Role
- ServiceAccount

## Job List
- CheckJob: Wait until kubconfig of the new cluster is created.
- PostJob: Depend on the configured value, create machine pools, set labels, and register to the argocd server.

## Configuration

|Parameter|Description|Default|
|---|---|---|
|sshKeyName|sshkey to use to access the VMs|default|
|cluster.name|cluster name|capi-quickstart|
|cluster.region|cluster region|ap-northeast-2|
|cluster.kubernetesVersion|kubernetes version|v1.18.16|
|cluster.bastion.enabled|whether or not to use bastion for the cluster|false|
|kubeadmControlPlane.replicas|the number of masters|3|
|machinePool|define machinepools as a worker node, see annoations in the value file|[]|
|machineDeployment.enabled|whether or not to use a machine deployment|false|
|job.taconode.enabled|whether or not to initialize nodes for taco|false|
|job.argo.enabled|whether or not to register to the argocd server|false|
5 changes: 4 additions & 1 deletion cluster-api-aws/artifacts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ FROM python

ADD https://dl.k8s.io/release/v1.22.0/bin/linux/amd64/kubectl /usr/local/bin/kubectl
ADD https://github.com/argoproj/argo-cd/releases/download/v2.1.1/argocd-linux-amd64 /usr/local/bin/argocd
ADD https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 /get_helm.sh

COPY requirements.txt requirements.txt
COPY generate_machine_pool.py /usr/local/bin/generate_machine_pool.py
COPY gh /usr/local/bin/gh

RUN pip3 install -r requirements.txt
RUN chmod +x /usr/local/bin/argocd /usr/local/bin/generate_machine_pool.py /usr/local/bin/kubectl /usr/local/bin/gh
RUN chmod +x /get_helm.sh
RUN /get_helm.sh
RUN chmod +x /usr/local/bin/argocd /usr/local/bin/generate_machine_pool.py /usr/local/bin/kubectl /usr/local/bin/gh

ENTRYPOINT [ "/usr/local/bin/generate_machine_pool.py" ]
5 changes: 2 additions & 3 deletions cluster-api-aws/artifacts/argo-register.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -ex

yes | argocd login --insecure $ARGO_SERVER --username $ARGO_USERNAME --password $ARGO_PASSWORD
mkdir ~/.kube
mkdir -p ~/.kube
KUBECONFIG="/kube.config" kubectl config view --merge --flatten > ~/.kube/config
CONTEXT_NAME=$(kubectl --kubeconfig=/kube.config config view -o jsonpath='{.current-context}')

Expand All @@ -15,6 +15,5 @@ done
if [ $(argocd cluster list | grep \ $1\ | wc -l ) == 0 ]; then
argocd cluster add $CONTEXT_NAME --name $1 --upsert
else
echo "FATAL error: $1 is already registered on argo-cd server"
exit 1
echo "Warning: $1 is already registered on argo-cd server. If unintended, it may occure woring operations."
fi
50 changes: 29 additions & 21 deletions cluster-api-aws/artifacts/wait_and_k8s_init.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
#!/bin/bash
set -ex

# echo "> Wait for awsmachinepoool $1-$2-mp-0 generated"
# while [ $(kubectl get awsmachinepool -n $3 $1-$2-mp-0 --ignore-not-found | wc -l) == 0 ]
# do
# echo "> Wait for awsmachinepools deployed (20s)"
# sleep 20
# done
# kubectl wait awsmachinepool -n $3 $1-$2-mp-0 --for condition=Ready=true --timeout=600s
# if taconode is set
if [ $4 = 'true' ]; then
echo "> Wait for machinepoool $1-$2-mp-0 generated"
while [ $(kubectl get machinepool -n $3 $1-$2-mp-0 --ignore-not-found | wc -l) == 0 ]
do
echo "> Wait for machinepools deployed (30s)"
sleep 30
done

echo "> Wait for machinepoool $1-$2-mp-0 generated"
while [ $(kubectl get machinepool -n $3 $1-$2-mp-0 --ignore-not-found | wc -l) == 0 ]
do
echo "> Wait for machinepools deployed (30s)"
sleep 30
done
while [ $(kubectl get machinepool -n $3 $1-$2-mp-0 -o=jsonpath='{.status.nodeRefs}' | wc -c) == 0 ]
do
echo "> Wait for instance is ready (20s)"
sleep 20
done

while [ $(kubectl get machinepool -n $3 $1-$2-mp-0 -o=jsonpath='{.status.nodeRefs}' | wc -c) == 0 ]
do
echo "> Wait for instance is ready (20s)"
sleep 20
done
./node_label.py $1 $2 $3

./node_label.py $1 $2 $3
cat <<EOF >/taco-system.yaml
apiVersion: v1
kind: Namespace
metadata:
labels:
name: taco-system
name: taco-system
EOF

kubectl --kubeconfig=/kube.config create ns taco-system
kubectl --kubeconfig=/kube.config label ns taco-system name=taco-system
kubectl --kubeconfig=/kube.config apply -f /taco-system.yaml
fi

# if argo-register.sh is set
if [ $5 = 'true' ]; then
/argo-register.sh $1
fi
27 changes: 9 additions & 18 deletions cluster-api-aws/templates/job-post.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
subPath: generate_machine_pool.py
mountPath: /generate_machine_pool.py

{{- if .Values.job.taconode.enabled }}
{{- if or .Values.job.taconode.enabled .Values.job.argo.enabled }}
- name: wait-and-initialize
image: "{{ .Values.job.image.repository }}:{{ .Values.job.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.job.image.pullPolicy }}
Expand All @@ -43,6 +43,14 @@ spec:
- {{ .Values.cluster.name }}
- taco
- {{ .Release.Namespace }}
- "{{ .Values.job.taconode.enabled }}"
- "{{ .Values.job.argo.enabled }}"

{{- if .Values.job.argo.enabled }}
envFrom:
- secretRef:
name: decapod-argocd-config
{{- end }}
volumeMounts:
- name: kubeconfig
subPath: value
Expand All @@ -53,23 +61,6 @@ spec:
- name: vol
subPath: wait_and_k8s_init.sh
mountPath: /wait_and_k8s_init.sh
{{- end }}

{{- if .Values.job.argo.enabled }}
- name: register-argo
image: "{{ .Values.job.image.repository }}:{{ .Values.job.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.job.image.pullPolicy }}
command:
- /argo-register.sh
- {{.Values.cluster.name }}

envFrom:
- secretRef:
name: decapod-argocd-config
volumeMounts:
- name: kubeconfig
subPath: value
mountPath: /kube.config
- name: vol
subPath: argo-register.sh
mountPath: /argo-register.sh
Expand Down
3 changes: 3 additions & 0 deletions cluster-api-aws/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ rules:
- get
- list
- create
- patch
- apiGroups:
- 'infrastructure.cluster.x-k8s.io'
resources:
Expand All @@ -42,6 +43,7 @@ rules:
- get
- list
- create
- patch
- apiGroups:
- 'bootstrap.cluster.x-k8s.io'
resources:
Expand All @@ -50,6 +52,7 @@ rules:
- get
- list
- create
- patch
- apiGroups:
- ''
resources:
Expand Down

0 comments on commit cad41cb

Please sign in to comment.