@@ -33,35 +33,55 @@ help: Makefile
33
33
@sed -n ' s/^##//p' $< | column -t -s ' :' | sed -e ' s/^/ /'
34
34
@echo
35
35
36
+ upload-gcp-cluster-creds :
37
+ export GKE_CREDS=$$(terraform output -json gke_user_key ) && \
38
+ echo $$ GKE_CREDS > gcp-creds
39
+ gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
40
+ gsutil cp gcp-creds gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -creds
41
+
42
+ download-cluster-creds :
43
+ [[ -z $$ TF_VAR_sa_creds ]] || gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
44
+ gcloud config set project sh-automated-tests
45
+ [[ -n $$ TF_VAR_sa_creds ]] || gsutil cp gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -creds gcs-creds
46
+ [[ -f gcs-creds ]] && cat gcs-creds | tr -d ' "' | base64 -d > ${TF_VAR_TEST_ID} -key.json || echo " No GCP credentials"
47
+ rm -f gcs-creds
48
+ [[ -f ${TF_VAR_TEST_ID} -key.json ]] || cp ${GOOGLE_APPLICATION_CREDENTIALS} ${TF_VAR_TEST_ID} -key.json
49
+
36
50
upload-kubeconfig-to-gcp :
37
51
gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
38
52
gsutil cp ${KUBECONFIG} gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -kubeconfig
39
53
40
54
sync-kubeconfig :
41
- gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
55
+ [[ -z $$ TF_VAR_sa_creds ]] || gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
56
+ gcloud config set project sh-automated-tests
42
57
gsutil cp gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -kubeconfig ${KUBECONFIG} || echo " No kubeconfig"
43
58
44
59
# # k3s-kubeconfig: Get the kubeconfig configuration for GCP K3s
45
60
k3s-kubeconfig : sync-kubeconfig
46
61
47
62
# # gcp-kubeconfig: Get the kubeconfig configuration for GCP GKE
48
63
gcp-kubeconfig :
49
- gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
64
+ $(MAKE ) download-cluster-creds
65
+ gcloud auth activate-service-account --key-file=${TF_VAR_TEST_ID} -key.json --project=sh-automated-tests || { echo " Count not authenicate the service account" ; exit 1; }
50
66
export KUBECONFIG=${KUBECONFIG} && \
51
- gcloud container clusters get-credentials gp-${TF_VAR_TEST_ID} --zone europe-west1-d --project sh-automated-tests || $(MAKE ) sync-kubeconfig || echo " No cluster present"
67
+ gcloud container clusters get-credentials gp-${TF_VAR_TEST_ID} --zone europe-west1-d --project sh-automated-tests || echo " No cluster present"
68
+ rm -f ${TF_VAR_TEST_ID} -key.json
52
69
53
70
# # azure-kubeconfig: Get the kubeconfig configuration for Azure AKS
54
71
azure-kubeconfig :
55
- az login --service-principal -u $$ ARM_CLIENT_ID -p $$ ARM_CLIENT_SECRET --tenant $$ ARM_TENANT_ID
72
+ [[ -n " $$ ARM_CLIENT_SECRET " ]] && az login --service-principal -u $$ ARM_CLIENT_ID -p $$ ARM_CLIENT_SECRET --tenant $$ ARM_TENANT_ID || { echo " Please login to azure using az login command " ; exit 1 ; }
56
73
export KUBECONFIG=${KUBECONFIG} && \
57
74
az aks get-credentials --name p$$ TF_VAR_TEST_ID-cluster --resource-group p$$ TF_VAR_TEST_ID --file ${KUBECONFIG} || echo " No cluster present"
58
75
59
76
# # aws-kubeconfig: Get the kubeconfig configuration for AWS EKS
60
77
aws-kubeconfig :
61
- export KUBECONFIG=${KUBECONFIG} && \
78
+ [[ -z $$ TF_VAR_sa_creds ]] || gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
79
+ gcloud config set project sh-automated-tests
80
+ [[ -n $$ TF_VAR_sa_creds ]] || gsutil cp gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -creds ${TF_VAR_TEST_ID} -creds
81
+ [[ -f ${TF_VAR_TEST_ID} -creds ]] || touch ${TF_VAR_TEST_ID} -creds
82
+ source ${TF_VAR_TEST_ID} -creds; \
62
83
aws eks update-kubeconfig --name ${TF_VAR_TEST_ID} --region eu-west-1 --kubeconfig ${KUBECONFIG} || echo " No cluster present"
63
84
64
-
65
85
.PHONY :
66
86
# # gke-standard-cluster: Creates a zonal GKE cluster
67
87
gke-standard-cluster : check-env-cluster-version
@@ -70,8 +90,22 @@ gke-standard-cluster: check-env-cluster-version
70
90
rm -f ${KUBECONFIG} && \
71
91
$(MAKE ) get-kubeconfig && \
72
92
[[ -f ${KUBECONFIG} ]] || terraform apply -target=module.gke -var kubeconfig=${KUBECONFIG} --auto-approve
93
+ $(MAKE ) upload-gcp-cluster-creds
73
94
@echo " Done creating GKE cluster"
74
95
96
+ upload-eks-user :
97
+ export AWS_CLUSTER_USER=$$(terraform output -json aws_cluster_user ) && \
98
+ export USERARN=$$(echo $$AWS_CLUSTER_USER | yq r - 'userarn' ) && \
99
+ export NAME=$$(echo $$AWS_CLUSTER_USER | yq r - 'name' ) && \
100
+ envsubst < ./manifests/aws-auth.yaml > tmp-aws-auth.yaml && \
101
+ echo " export AWS_SECRET_ACCESS_KEY=$$ (echo $$ AWS_CLUSTER_USER | yq r - 'secret_access_key')" > ${TF_VAR_TEST_ID} -creds && \
102
+ echo " export AWS_ACCESS_KEY_ID=$$ (echo $$ AWS_CLUSTER_USER | yq r - 'access_key_id')" >> ${TF_VAR_TEST_ID} -creds && \
103
+ kubectl --kubeconfig=${KUBECONFIG} get configmap -n kube-system aws-auth -o yaml | grep -v " creationTimestamp\|resourceVersion\|selfLink\|uid" | sed ' /^ annotations:/,+2 d' > /tmp/aws-auth.yaml
104
+ yq m --inplace /tmp/aws-auth.yaml tmp-aws-auth.yaml
105
+ gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
106
+ gsutil cp ${TF_VAR_TEST_ID} -creds gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -creds
107
+ kubectl --kubeconfig=${KUBECONFIG} replace -f /tmp/aws-auth.yaml
108
+
75
109
ami_id_121 := "ami-060637af2651bc8bb"
76
110
77
111
ami_id_122 := "ami-0733d755ed2c97a4d"
@@ -87,6 +121,7 @@ eks-standard-cluster: check-env-cluster-version
87
121
rm -f ${KUBECONFIG} && \
88
122
$(MAKE ) get-kubeconfig && \
89
123
[[ -f ${KUBECONFIG} ]] || terraform apply -target=module.eks -var kubeconfig=${KUBECONFIG} -var eks_node_image_id=${ami_id} --auto-approve
124
+ $(MAKE ) upload-eks-user
90
125
@echo " Done creating EKS cluster"
91
126
92
127
.PHONY :
@@ -159,8 +194,10 @@ external-dns: check-env-cloud select-workspace
159
194
160
195
.PHONY :
161
196
# # get-kubeconfig: Returns KUBECONFIG of a just created cluster
162
- get-kubeconfig : ${cloud}-kubeconfig
163
-
197
+ get-kubeconfig :
198
+ echo " Getting kubeconfig for $$ TF_VAR_TEST_ID terraform state" && \
199
+ export provider =$$(echo "$$TF_VAR_TEST_ID" | sed 's/\(.*\ ) -/\1 /' | xargs | awk '{print $$2}') && \
200
+ $(MAKE ) $$provider-kubeconfig && echo "kubeconfig written to ${KUBECONFIG}"
164
201
165
202
get-github-config :
166
203
ifneq ($(GITHUB_SCM_OAUTH ) ,)
@@ -212,8 +249,8 @@ registry-config-azure:
212
249
yq m -i tmp_config.yml tmp_2_config.yml
213
250
214
251
storage-config-azure :
215
- export PASSWORD =$$(terraform output -json azure_storage | yq r - 'account_name' ) && \
216
- export USERNAME =$$(terraform output -json azure_storage | yq r - 'account_key' ) && \
252
+ export USERNAME =$$(terraform output -json azure_storage | yq r - 'account_name' ) && \
253
+ export PASSWORD =$$(terraform output -json azure_storage | yq r - 'account_key' ) && \
217
254
export REGION=$$(terraform output -json azure_storage | yq r - 'storage_region' ) && \
218
255
envsubst < ./manifests/kots-config-azure-storage.yaml > tmp_2_config.yml
219
256
yq m -i tmp_config.yml tmp_2_config.yml
@@ -388,7 +425,7 @@ kots-upgrade:
388
425
kubectl kots upstream upgrade --kubeconfig=${KUBECONFIG} gitpod -n gitpod --deploy
389
426
390
427
cloud ?= cluster
391
- cleanup : $( cloud ) -kubeconfig destroy-gitpod tf-init destroy-$(cloud ) destroy-workspace destroy-kubeconfig
428
+ cleanup : get -kubeconfig destroy-gitpod tf-init destroy-$(cloud ) destroy-workspace destroy-kubeconfig
392
429
393
430
cluster-kubeconfig : azure-kubeconfig aws-kubeconfig k3s-kubeconfig gcp-kubeconfig
394
431
@@ -400,6 +437,7 @@ destroy-cluster: destroy-gcp destroy-aws destroy-azure
400
437
destroy-kubeconfig :
401
438
gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
402
439
gsutil rm gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -kubeconfig || echo " No kubeconfig"
440
+ gsutil rm gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -creds || echo " No credentials file"
403
441
rm ${KUBECONFIG} || echo " No kubeconfig"
404
442
405
443
select-workspace :
0 commit comments