@@ -35,53 +35,49 @@ help: Makefile
35
35
36
36
upload-gcp-cluster-creds :
37
37
export GKE_CREDS=$$(terraform output -json gke_user_key ) && \
38
- echo ${ GKE_CREDS} > gcp-creds
38
+ echo $$ GKE_CREDS > gcp-creds
39
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} -gcp- creds
40
+ gsutil cp gcp-creds gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -creds
41
41
42
- key_file ?= ${GOOGLE_APPLICATION_CREDENTIALS}
43
- download-gcp-cluster-creds :
44
- gcloud auth activate-service-account --key-file=${key_file} --project=sh-automated-tests
45
- gsutil cp gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -gcp-creds gs-creds && cat gs-creds | base64 -d > ${TF_VAR_TEST_ID} -key.json || echo " No GCP credentials"
46
-
47
- upload-aws-cluster-creds :
48
-
49
- upload-azure-cluster-creds :
42
+ download-cluster-creds :
43
+ gcloud config set project sh-automated-tests
44
+ [[ -n $$ TF_VAR_sa_creds ]] || gsutil cp gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -creds gcs-creds && cat gcs-creds | tr -d ' "' | base64 -d > ${TF_VAR_TEST_ID} -key.json || echo " No GCP credentials"
45
+ rm -f gcs-creds
46
+ [[ -f ${TF_VAR_TEST_ID} -key.json ]] || cp ${GOOGLE_APPLICATION_CREDENTIALS} ${TF_VAR_TEST_ID} -key.json
50
47
51
48
upload-kubeconfig-to-gcp :
52
49
gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
53
50
gsutil cp ${KUBECONFIG} gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -kubeconfig
54
51
55
- key_file ?= ${GOOGLE_APPLICATION_CREDENTIALS}
56
52
sync-kubeconfig :
57
- gcloud auth activate-service-account --key-file=key_file -- project= sh-automated-tests
53
+ gcloud config set project sh-automated-tests
58
54
gsutil cp gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -kubeconfig ${KUBECONFIG} || echo " No kubeconfig"
59
55
60
56
# # k3s-kubeconfig: Get the kubeconfig configuration for GCP K3s
61
57
k3s-kubeconfig : sync-kubeconfig
62
58
63
59
# # gcp-kubeconfig: Get the kubeconfig configuration for GCP GKE
64
60
gcp-kubeconfig :
65
- kubectl get secret -n sh-gcs-secret -o -o jsonpath=' {.data.key}' | base64 -d > gcs-key.json || echo " No access to core-dev cluster"
66
- [[ -f gcs-key.json ]] || echo ${GOOGLE_APPLICATION_CREDENTIALS} > gcs-key.json
67
- $(MAKE ) download-gcp-cluster-creds key_file=${key_file}
68
- [[ -f ${TF_VAR_TEST_ID} -key.json ]] && gcloud auth activate-service-account --key-file=${TF_VAR_TEST_ID} -key.json --project=sh-automated-tests
61
+ $(MAKE ) download-cluster-creds
62
+ 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; }
69
63
export KUBECONFIG=${KUBECONFIG} && \
70
- 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"
64
+ gcloud container clusters get-credentials gp-${TF_VAR_TEST_ID} --zone europe-west1-d --project sh-automated-tests || echo " No cluster present"
71
65
rm -f ${TF_VAR_TEST_ID} -key.json
72
66
73
67
# # azure-kubeconfig: Get the kubeconfig configuration for Azure AKS
74
68
azure-kubeconfig :
75
- az login --service-principal -u $$ ARM_CLIENT_ID -p $$ ARM_CLIENT_SECRET --tenant $$ ARM_TENANT_ID
69
+ [[ -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 ; }
76
70
export KUBECONFIG=${KUBECONFIG} && \
77
71
az aks get-credentials --name p$$ TF_VAR_TEST_ID-cluster --resource-group p$$ TF_VAR_TEST_ID --file ${KUBECONFIG} || echo " No cluster present"
78
72
79
73
# # aws-kubeconfig: Get the kubeconfig configuration for AWS EKS
80
74
aws-kubeconfig :
81
- export KUBECONFIG=${KUBECONFIG} && \
75
+ gcloud config set project sh-automated-tests
76
+ [[ -n $$ TF_VAR_sa_creds ]] || gsutil cp gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -creds ${TF_VAR_TEST_ID} -creds
77
+ [[ -f ${TF_VAR_TEST_ID} -creds ]] || touch ${TF_VAR_TEST_ID} -creds
78
+ source ${TF_VAR_TEST_ID} -creds; \
82
79
aws eks update-kubeconfig --name ${TF_VAR_TEST_ID} --region eu-west-1 --kubeconfig ${KUBECONFIG} || echo " No cluster present"
83
80
84
-
85
81
.PHONY :
86
82
# # gke-standard-cluster: Creates a zonal GKE cluster
87
83
gke-standard-cluster : check-env-cluster-version
@@ -90,8 +86,22 @@ gke-standard-cluster: check-env-cluster-version
90
86
rm -f ${KUBECONFIG} && \
91
87
$(MAKE ) get-kubeconfig && \
92
88
[[ -f ${KUBECONFIG} ]] || terraform apply -target=module.gke -var kubeconfig=${KUBECONFIG} --auto-approve
89
+ $(MAKE ) upload-gcp-cluster-creds
93
90
@echo " Done creating GKE cluster"
94
91
92
+ upload-eks-user :
93
+ export AWS_CLUSTER_USER=$$(terraform output -json aws_cluster_user ) && \
94
+ export USERARN=$$(echo $$AWS_CLUSTER_USER | yq r - 'userarn' ) && \
95
+ export NAME=$$(echo $$AWS_CLUSTER_USER | yq r - 'name' ) && \
96
+ envsubst < ./manifests/aws-auth.yaml > tmp-aws-auth.yaml && \
97
+ echo " export AWS_SECRET_ACCESS_KEY=$$ (echo $$ AWS_CLUSTER_USER | yq r - 'secret_access_key')" > ${TF_VAR_TEST_ID} -creds && \
98
+ echo " export AWS_ACCESS_KEY_ID=$$ (echo $$ AWS_CLUSTER_USER | yq r - 'access_key_id')" >> ${TF_VAR_TEST_ID} -creds && \
99
+ 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
100
+ yq m --inplace /tmp/aws-auth.yaml tmp-aws-auth.yaml
101
+ gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
102
+ gsutil cp ${TF_VAR_TEST_ID} -creds gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -creds
103
+ kubectl --kubeconfig=${KUBECONFIG} replace -f /tmp/aws-auth.yaml
104
+
95
105
ami_id_121 := "ami-060637af2651bc8bb"
96
106
97
107
ami_id_122 := "ami-0733d755ed2c97a4d"
@@ -107,6 +117,7 @@ eks-standard-cluster: check-env-cluster-version
107
117
rm -f ${KUBECONFIG} && \
108
118
$(MAKE ) get-kubeconfig && \
109
119
[[ -f ${KUBECONFIG} ]] || terraform apply -target=module.eks -var kubeconfig=${KUBECONFIG} -var eks_node_image_id=${ami_id} --auto-approve
120
+ $(MAKE ) upload-eks-user
110
121
@echo " Done creating EKS cluster"
111
122
112
123
.PHONY :
@@ -156,7 +167,6 @@ k3s-standard-cluster: check-env-cluster-version
156
167
$(MAKE ) get-kubeconfig && \
157
168
[[ -f ${KUBECONFIG} ]] || terraform apply -target=module.k3s -var kubeconfig=${KUBECONFIG} -var k3s_node_image_id=${image_id} --auto-approve && \
158
169
$(MAKE ) upload-kubeconfig-to-gcp # we upload the file to GCP since we cannot retrieve the file against without SSHing to the master
159
- $(MAKE ) upload-gcp-cluster-creds
160
170
@echo " Done creating k3s cluster"
161
171
162
172
.PHONY :
@@ -180,8 +190,10 @@ external-dns: check-env-cloud select-workspace
180
190
181
191
.PHONY :
182
192
# # get-kubeconfig: Returns KUBECONFIG of a just created cluster
183
- get-kubeconfig : ${cloud}-kubeconfig
184
-
193
+ get-kubeconfig :
194
+ echo " Getting kubeconfig for $$ TF_VAR_TEST_ID terraform state" && \
195
+ export provider =$$(echo "$$TF_VAR_TEST_ID" | sed 's/\(.*\ ) -/\1 /' | xargs | awk '{print $$2}') && \
196
+ $(MAKE ) $$provider-kubeconfig && echo "kubeconfig written to ${KUBECONFIG}"
185
197
186
198
get-github-config :
187
199
ifneq ($(GITHUB_SCM_OAUTH ) ,)
@@ -233,8 +245,8 @@ registry-config-azure:
233
245
yq m -i tmp_config.yml tmp_2_config.yml
234
246
235
247
storage-config-azure :
236
- export PASSWORD =$$(terraform output -json azure_storage | yq r - 'account_name' ) && \
237
- export USERNAME =$$(terraform output -json azure_storage | yq r - 'account_key' ) && \
248
+ export USERNAME =$$(terraform output -json azure_storage | yq r - 'account_name' ) && \
249
+ export PASSWORD =$$(terraform output -json azure_storage | yq r - 'account_key' ) && \
238
250
export REGION=$$(terraform output -json azure_storage | yq r - 'storage_region' ) && \
239
251
envsubst < ./manifests/kots-config-azure-storage.yaml > tmp_2_config.yml
240
252
yq m -i tmp_config.yml tmp_2_config.yml
@@ -409,7 +421,7 @@ kots-upgrade:
409
421
kubectl kots upstream upgrade --kubeconfig=${KUBECONFIG} gitpod -n gitpod --deploy
410
422
411
423
cloud ?= cluster
412
- cleanup : $( cloud ) -kubeconfig destroy-gitpod tf-init destroy-$(cloud ) destroy-workspace destroy-kubeconfig
424
+ cleanup : get -kubeconfig destroy-gitpod tf-init destroy-$(cloud ) destroy-workspace destroy-kubeconfig
413
425
414
426
cluster-kubeconfig : azure-kubeconfig aws-kubeconfig k3s-kubeconfig gcp-kubeconfig
415
427
@@ -421,6 +433,7 @@ destroy-cluster: destroy-gcp destroy-aws destroy-azure
421
433
destroy-kubeconfig :
422
434
gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
423
435
gsutil rm gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -kubeconfig || echo " No kubeconfig"
436
+ gsutil rm gs://nightly-tests/tf-state/${TF_VAR_TEST_ID} -creds || echo " No credentials file"
424
437
rm ${KUBECONFIG} || echo " No kubeconfig"
425
438
426
439
select-workspace :
0 commit comments