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