Skip to content

Commit 0bfc950

Browse files
committed
Improve deployment scripts, make SA directory configuarable instead of name
1 parent bc201a2 commit 0bfc950

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

deploy/kubernetes/delete-driver.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# This script will remove the GCP Compute Persistent Disk CSI Driver from the
4+
# currently available Kubernetes cluster
5+
36
set -o nounset
47
set -o errexit
58

deploy/kubernetes/deploy-driver.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/bash
22

3+
# This script will deploy the GCP Compute Persistent Disk CSI Driver to the
4+
# currently available Kubernetes cluster
5+
6+
# Args:
7+
# GCE_PD_SA_DIR: Directory the service account key has been saved in (generated by setup-project.sh)
8+
39
set -o nounset
410
set -o errexit
511

@@ -8,7 +14,7 @@ readonly KUBEDEPLOY="${PKGDIR}/deploy/kubernetes"
814

915
if ! kubectl get secret cloud-sa;
1016
then
11-
kubectl create secret generic cloud-sa --from-file="${SA_FILE}"
17+
kubectl create secret generic cloud-sa --from-file="${GCE_PD_SA_DIR}/cloud-sa.json"
1218
fi
1319

1420
# GKE Required Setup

deploy/setup-project.sh

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
#!/bin/bash
22

3+
# This script will setup the given project with a Service Account that has the correct
4+
# restricted permissions to run the gcp_compute_persistent_disk_csi_driver and download
5+
# the keys to a specified directory
6+
7+
# WARNING: This script will delete and recreate all service accounts, bindings, and keys.
8+
# Great care must be taken to not run the script with a service account that is currently
9+
# in use.
10+
11+
# Args:
12+
# PROJECT: GCP project
13+
# GCE_PD_SA_NAME: Name of the service account to create
14+
# GCE_PD_SA_DIR: Directory to save the service account key
15+
16+
317
set -o nounset
418
set -o errexit
519

620
readonly PKGDIR="${GOPATH}/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver"
721
readonly KUBEDEPLOY="${PKGDIR}/deploy/kubernetes"
8-
9-
BIND_ROLES="roles/compute.storageAdmin roles/iam.serviceAccountUser projects/${PROJECT}/roles/gcp_compute_persistent_disk_csi_driver_custom_role"
10-
IAM_NAME="${GCEPD_SA_NAME}@${PROJECT}.iam.gserviceaccount.com"
22+
readonly BIND_ROLES="roles/compute.storageAdmin roles/iam.serviceAccountUser projects/${PROJECT}/roles/gcp_compute_persistent_disk_csi_driver_custom_role"
23+
readonly IAM_NAME="${GCE_PD_SA_NAME}@${PROJECT}.iam.gserviceaccount.com"
1124

1225
# Create or Update Custom Role
1326
if gcloud iam roles describe gcp_compute_persistent_disk_csi_driver_custom_role --project "${PROJECT}";
@@ -22,8 +35,8 @@ else
2235
fi
2336

2437
# Delete Service Account Key
25-
if [ -f $SA_FILE ]; then
26-
rm "$SA_FILE"
38+
if [ -f "${GCE_PD_SA_DIR}/cloud-sa.json" ]; then
39+
rm "${GCE_PD_SA_DIR}/cloud-sa.json"
2740
fi
2841
# Delete ALL EXISTING Bindings
2942
gcloud projects get-iam-policy "${PROJECT}" --format json > "${PKGDIR}/deploy/iam.json"
@@ -34,9 +47,9 @@ rm -f "${PKGDIR}/deploy/iam.json"
3447
gcloud iam service-accounts delete "${IAM_NAME}" --project "${PROJECT}" --quiet || true
3548

3649
# Create new Service Account and Keys
37-
gcloud iam service-accounts create "${GCEPD_SA_NAME}" --project "${PROJECT}"
50+
gcloud iam service-accounts create "${GCE_PD_SA_NAME}" --project "${PROJECT}"
3851
for role in ${BIND_ROLES}
3952
do
4053
gcloud projects add-iam-policy-binding "${PROJECT}" --member serviceAccount:"${IAM_NAME}" --role ${role}
4154
done
42-
gcloud iam service-accounts keys create "${SA_FILE}" --iam-account "${IAM_NAME}" --project "${PROJECT}"
55+
gcloud iam service-accounts keys create "${GCE_PD_SA_DIR}/cloud-sa.json" --iam-account "${IAM_NAME}" --project "${PROJECT}"

0 commit comments

Comments
 (0)