Skip to content

Commit e3653d9

Browse files
authored
Merge pull request #81 from davidz627/fix/saName
Improve deployment scripts, make service account JSON configurable by directory, not name
2 parents bc201a2 + c4145a2 commit e3653d9

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ this drive in a production environment in its current state.
44

55
DISCLAIMER: This is not an officially supported Google product
66

7+
Kubernetes Note: setup-cluster.yaml depends on the existence of cluster-roles
8+
system:csi-external-attacher and system:csi-external-provisioner which are in
9+
Kubernetes version 1.10.5+
10+
711
# GCP Compute Persistent Disk CSI Driver
812

913
The GCP Compute Persistent Disk CSI Driver is a

Diff for: 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

Diff for: deploy/kubernetes/deploy-driver.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
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+
# Note: setup-cluster.yaml depends on the existence of cluster-roles
7+
# system:csi-external-attacher and system:csi-external-provisioner
8+
# which are in Kubernetes version 1.10.5+
9+
10+
# Args:
11+
# GCE_PD_SA_DIR: Directory the service account key has been saved in (generated by setup-project.sh)
12+
313
set -o nounset
414
set -o errexit
515

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

919
if ! kubectl get secret cloud-sa;
1020
then
11-
kubectl create secret generic cloud-sa --from-file="${SA_FILE}"
21+
kubectl create secret generic cloud-sa --from-file="${GCE_PD_SA_DIR}/cloud-sa.json"
1222
fi
1323

1424
# GKE Required Setup

Diff for: 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 the service accounts, bindings, and keys
8+
# associated with ${GCE_PD_SA_NAME}. Great care must be taken to not run the script
9+
# with a service account that is currently 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)