Skip to content

Commit 12cef7b

Browse files
committed
Modify deployment scripts to use kustomize
1 parent 5a2ddb8 commit 12cef7b

File tree

5 files changed

+83
-19
lines changed

5 files changed

+83
-19
lines changed

deploy/common.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# Common variables
4+
readonly KUSTOMIZE_PATH="${PKGDIR}/bin/kustomize"
5+
36
# Common functions
47

58
function ensure_var(){
@@ -15,4 +18,11 @@ function ensure_var(){
1518
function get_needed_roles()
1619
{
1720
echo "roles/compute.storageAdmin roles/iam.serviceAccountUser projects/${PROJECT}/roles/gcp_compute_persistent_disk_csi_driver_custom_role"
18-
}
21+
}
22+
23+
# Installs kustomize in ${PKGDIR}/bin
24+
function ensure_kustomize()
25+
{
26+
ensure_var PKGDIR
27+
${PKGDIR}/deploy/kubernetes/install-kustomize.sh
28+
}

deploy/kubernetes/base/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
commonLabels:
22
app: gcp-compute-persistent-disk-csi-driver
3+
namespace:
4+
default
35
resources:
46
- node.yaml
57
- controller.yaml

deploy/kubernetes/delete-driver.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
# currently available Kubernetes cluster
55
#
66
# Args:
7-
# GCE_PD_DRIVER_VERSION: The version of the GCE PD CSI Driver to deploy. Can be one of {v0.1.0, latest}
7+
# GCE_PD_DRIVER_VERSION: The kustomize overlay to deploy (located under
8+
# deploy/kubernetes/overlays). Can be one of {stable, dev}
89

910
set -o nounset
1011
set -o errexit
1112

13+
readonly DEPLOY_VERSION="${GCE_PD_DRIVER_VERSION:-stable}"
1214
readonly PKGDIR="${GOPATH}/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver"
1315
source "${PKGDIR}/deploy/common.sh"
1416

15-
ensure_var GCE_PD_DRIVER_VERSION
17+
ensure_kustomize
1618

17-
readonly KUBEDEPLOY="${PKGDIR}/deploy/kubernetes/${GCE_PD_DRIVER_VERSION}"
18-
19-
kubectl delete -f "${KUBEDEPLOY}/node.yaml" --ignore-not-found
20-
kubectl delete -f "${KUBEDEPLOY}/controller.yaml" --ignore-not-found
21-
kubectl delete -f "${KUBEDEPLOY}/setup-cluster.yaml" --ignore-not-found
22-
kubectl delete secret cloud-sa --ignore-not-found
19+
${KUSTOMIZE_PATH} build ${PKGDIR}/deploy/kubernetes/overlays/${DEPLOY_VERSION} | kubectl delete --ignore-not-found -f -
20+
kubectl delete secret cloud-sa --ignore-not-found

deploy/kubernetes/deploy-driver.sh

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,41 @@
99

1010
# Args:
1111
# GCE_PD_SA_DIR: Directory the service account key has been saved in (generated by setup-project.sh)
12-
# GCE_PD_DRIVER_VERSION: The version of the GCE PD CSI Driver to deploy. Can be one of {stable, dev}
12+
# GCE_PD_DRIVER_VERSION: The kustomize overlay (located in
13+
# deploy/kubernetes/overlays) to deploy. Can be one of {stable, dev}
1314

1415
set -o nounset
1516
set -o errexit
17+
set -x
1618

19+
readonly NAMESPACE="${GCE_PD_DRIVER_NAMESPACE:-default}"
20+
readonly DEPLOY_VERSION="${GCE_PD_DRIVER_VERSION:-stable}"
1721
readonly PKGDIR="${GOPATH}/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver"
1822
source "${PKGDIR}/deploy/common.sh"
1923

20-
ensure_var GCE_PD_SA_DIR
21-
ensure_var GCE_PD_DRIVER_VERSION
24+
print_usage()
25+
{
26+
echo "deploy-driver.sh [--skip-sa-check]\n"
27+
echo "\t--skip-sa-check: don't check the service account for required roles"
28+
echo
29+
}
2230

23-
readonly KUBEDEPLOY="${PKGDIR}/deploy/kubernetes/${GCE_PD_DRIVER_VERSION}"
31+
skip_sa_check=
32+
while [ ! -z "${1-}" ]; do
33+
case $1 in
34+
--skip-sa-check ) shift
35+
skip_sa_check=true
36+
;;
37+
-h | --help ) print_usage
38+
exit 1
39+
;;
40+
* ) print_usage
41+
exit 1
42+
;;
43+
esac
44+
done
45+
46+
ensure_var GCE_PD_SA_DIR
2447

2548
function check_service_account()
2649
{
@@ -47,11 +70,15 @@ function check_service_account()
4770
fi
4871
}
4972

50-
check_service_account
73+
ensure_kustomize
74+
75+
if [ "$skip_sa_check" != true ]; then
76+
check_service_account
77+
fi
5178

52-
if ! kubectl get secret cloud-sa;
79+
if ! kubectl get secret cloud-sa -n ${NAMESPACE};
5380
then
54-
kubectl create secret generic cloud-sa --from-file="${GCE_PD_SA_DIR}/cloud-sa.json"
81+
kubectl create secret generic cloud-sa --from-file="${GCE_PD_SA_DIR}/cloud-sa.json" -n ${NAMESPACE}
5582
fi
5683

5784
# GKE Required Setup
@@ -60,6 +87,6 @@ then
6087
kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user $(gcloud config get-value account)
6188
fi
6289

63-
kubectl apply -f "${KUBEDEPLOY}/setup-cluster.yaml"
64-
kubectl apply -f "${KUBEDEPLOY}/node.yaml"
65-
kubectl apply -f "${KUBEDEPLOY}/controller.yaml"
90+
readonly tmp_spec=/tmp/gcp-compute-persistent-disk-csi-driver-specs-generated.yaml
91+
${KUSTOMIZE_PATH} build ${PKGDIR}/deploy/kubernetes/overlays/${DEPLOY_VERSION} | tee $tmp_spec
92+
kubectl apply -f $tmp_spec
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# This script will install kustomize, which is a tool that simplifies patching
4+
# Kubernetes manifests for different environments.
5+
# https://github.com/kubernetes-sigs/kustomize
6+
7+
set -o nounset
8+
set -o errexit
9+
10+
readonly INSTALL_DIR="${GOPATH}/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/bin"
11+
readonly KUSTOMIZE_PATH="${INSTALL_DIR}/kustomize"
12+
13+
if [ ! -f "${KUSTOMIZE_PATH}" ]; then
14+
if [ ! -f "${INSTALL_DIR}" ]; then
15+
mkdir -p ${INSTALL_DIR}
16+
fi
17+
18+
echo "Installing kustomize in ${KUSTOMIZE_PATH}"
19+
opsys=linux # or darwin, or windows
20+
curl -s https://api.github.com/repos/kubernetes-sigs/kustomize/releases/tags/v1.0.8 |\
21+
grep browser_download |\
22+
grep $opsys |\
23+
cut -d '"' -f 4 |\
24+
xargs curl -O -L
25+
mv kustomize_*_${opsys}_amd64 ${KUSTOMIZE_PATH}
26+
chmod u+x ${KUSTOMIZE_PATH}
27+
fi

0 commit comments

Comments
 (0)