Skip to content

Commit 17ecfb7

Browse files
committed
removing one level of indirection
1 parent 4d5631a commit 17ecfb7

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

install/infra/modules/gke/cluster.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ resource "google_service_account" "cluster_user_sa" {
158158
resource "google_project_iam_member" "gke-user-sa-iam" {
159159
project = var.project
160160
role = "roles/container.developer"
161-
member = "serviceAccount:${google_service_account.cluster_sa.email}"
161+
member = "serviceAccount:${google_service_account.cluster_user_sa.email}"
162162
}
163163

164164
resource "google_service_account_key" "gke_sa_key" {

install/infra/modules/gke/database.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ resource "random_password" "password" {
4141
count = var.enable_external_database ? 1 : 0
4242

4343
length = 16
44-
special = true
45-
override_special = "!#$%&*()-_=+[]{}<>:?"
44+
special = false
4645
}
4746

4847
resource "google_sql_database" "database" {

install/tests/Makefile

+21-23
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,40 @@ help: Makefile
3535

3636
upload-gcp-cluster-creds:
3737
export GKE_CREDS=$$(terraform output -json gke_user_key) && \
38-
echo ${GKE_CREDS} > gcp-creds
38+
echo $$GKE_CREDS > gcp-creds
3939
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
4141

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"
42+
download-cluster-creds:
43+
gcloud config set project sh-automated-tests
44+
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
4647

4748
upload-aws-cluster-creds:
4849

49-
upload-azure-cluster-creds:
50-
5150
upload-kubeconfig-to-gcp:
5251
gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
5352
gsutil cp ${KUBECONFIG} gs://nightly-tests/tf-state/${TF_VAR_TEST_ID}-kubeconfig
5453

55-
key_file ?= ${GOOGLE_APPLICATION_CREDENTIALS}
5654
sync-kubeconfig:
57-
gcloud auth activate-service-account --key-file=key_file --project=sh-automated-tests
55+
gcloud config set project sh-automated-tests
5856
gsutil cp gs://nightly-tests/tf-state/${TF_VAR_TEST_ID}-kubeconfig ${KUBECONFIG} || echo "No kubeconfig"
5957

6058
## k3s-kubeconfig: Get the kubeconfig configuration for GCP K3s
6159
k3s-kubeconfig: sync-kubeconfig
6260

6361
## gcp-kubeconfig: Get the kubeconfig configuration for GCP GKE
6462
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
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; }
6965
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"
66+
gcloud container clusters get-credentials gp-${TF_VAR_TEST_ID} --zone europe-west1-d --project sh-automated-tests || echo "No cluster present"
7167
rm -f ${TF_VAR_TEST_ID}-key.json
7268

7369
## azure-kubeconfig: Get the kubeconfig configuration for Azure AKS
7470
azure-kubeconfig:
75-
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; }
7672
export KUBECONFIG=${KUBECONFIG} && \
7773
az aks get-credentials --name p$$TF_VAR_TEST_ID-cluster --resource-group p$$TF_VAR_TEST_ID --file ${KUBECONFIG} || echo "No cluster present"
7874

@@ -81,7 +77,6 @@ aws-kubeconfig:
8177
export KUBECONFIG=${KUBECONFIG} && \
8278
aws eks update-kubeconfig --name ${TF_VAR_TEST_ID} --region eu-west-1 --kubeconfig ${KUBECONFIG} || echo "No cluster present"
8379

84-
8580
.PHONY:
8681
## gke-standard-cluster: Creates a zonal GKE cluster
8782
gke-standard-cluster: check-env-cluster-version
@@ -90,6 +85,7 @@ gke-standard-cluster: check-env-cluster-version
9085
rm -f ${KUBECONFIG} && \
9186
$(MAKE) get-kubeconfig && \
9287
[[ -f ${KUBECONFIG} ]] || terraform apply -target=module.gke -var kubeconfig=${KUBECONFIG} --auto-approve
88+
$(MAKE) upload-gcp-cluster-creds
9389
@echo "Done creating GKE cluster"
9490

9591
ami_id_121 := "ami-060637af2651bc8bb"
@@ -156,7 +152,6 @@ k3s-standard-cluster: check-env-cluster-version
156152
$(MAKE) get-kubeconfig && \
157153
[[ -f ${KUBECONFIG} ]] || terraform apply -target=module.k3s -var kubeconfig=${KUBECONFIG} -var k3s_node_image_id=${image_id} --auto-approve && \
158154
$(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
160155
@echo "Done creating k3s cluster"
161156

162157
.PHONY:
@@ -180,8 +175,10 @@ external-dns: check-env-cloud select-workspace
180175

181176
.PHONY:
182177
## get-kubeconfig: Returns KUBECONFIG of a just created cluster
183-
get-kubeconfig: ${cloud}-kubeconfig
184-
178+
get-kubeconfig:
179+
echo "Getting kubeconfig for $$TF_VAR_TEST_ID terraform state" && \
180+
export provider=$$(echo "$$TF_VAR_TEST_ID" | sed 's/\(.*\)-/\1 /' | xargs | awk '{print $$2}') && \
181+
$(MAKE) $$provider-kubeconfig && echo "kubeconfig written to ${KUBECONFIG}"
185182

186183
get-github-config:
187184
ifneq ($(GITHUB_SCM_OAUTH),)
@@ -233,8 +230,8 @@ registry-config-azure:
233230
yq m -i tmp_config.yml tmp_2_config.yml
234231

235232
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') && \
233+
export USERNAME=$$(terraform output -json azure_storage | yq r - 'account_name') && \
234+
export PASSWORD=$$(terraform output -json azure_storage | yq r - 'account_key') && \
238235
export REGION=$$(terraform output -json azure_storage | yq r - 'storage_region') && \
239236
envsubst < ./manifests/kots-config-azure-storage.yaml > tmp_2_config.yml
240237
yq m -i tmp_config.yml tmp_2_config.yml
@@ -409,7 +406,7 @@ kots-upgrade:
409406
kubectl kots upstream upgrade --kubeconfig=${KUBECONFIG} gitpod -n gitpod --deploy
410407

411408
cloud ?= cluster
412-
cleanup: $(cloud)-kubeconfig destroy-gitpod tf-init destroy-$(cloud) destroy-workspace destroy-kubeconfig
409+
cleanup: get-kubeconfig destroy-gitpod tf-init destroy-$(cloud) destroy-workspace destroy-kubeconfig
413410

414411
cluster-kubeconfig: azure-kubeconfig aws-kubeconfig k3s-kubeconfig gcp-kubeconfig
415412

@@ -421,6 +418,7 @@ destroy-cluster: destroy-gcp destroy-aws destroy-azure
421418
destroy-kubeconfig:
422419
gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} --project=sh-automated-tests
423420
gsutil rm gs://nightly-tests/tf-state/${TF_VAR_TEST_ID}-kubeconfig || echo "No kubeconfig"
421+
gsutil rm gs://nightly-tests/tf-state/${TF_VAR_TEST_ID}-creds || echo "No credentials file"
424422
rm ${KUBECONFIG} || echo "No kubeconfig"
425423

426424
select-workspace:

install/tests/cleanup.sh

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ for i in $(gsutil ls gs://nightly-tests/tf-state); do
1919
[ -z "$filename" ] && continue
2020

2121
if [[ "$filename" == *-kubeconfig ]]; then continue; fi
22+
if [[ "$filename" == *-creds ]]; then continue; fi
2223

2324
TF_VAR_TEST_ID=$(basename "$filename" .tfstate)
2425

0 commit comments

Comments
 (0)