|
11 | 11 | set -e
|
12 | 12 | set -o pipefail
|
13 | 13 |
|
14 |
| -function image_version () { |
| 14 | +BASE_DIR=$(dirname "$0") |
| 15 | +K8S_RELEASE=${K8S_RELEASE:-"release-1.13"} |
| 16 | + |
| 17 | +# If set, the following env variables override image registry and/or tag for each of the images. |
| 18 | +# They are named after the image name, with hyphen replaced by underscore and in upper case. |
| 19 | +# |
| 20 | +# - CSI_ATTACHER_REGISTRY |
| 21 | +# - CSI_ATTACHER_TAG |
| 22 | +# - CSI_NODE_DRIVER_REGISTRAR_REGISTRY |
| 23 | +# - CSI_NODE_DRIVER_REGISTRAR_TAG |
| 24 | +# - CSI_PROVISIONER_REGISTRY |
| 25 | +# - CSI_PROVISIONER_TAG |
| 26 | +# - CSI_SNAPSHOTTER_REGISTRY |
| 27 | +# - CSI_SNAPSHOTTER_TAG |
| 28 | +# - HOSTPATHPLUGIN_REGISTRY |
| 29 | +# - HOSTPATHPLUGIN_TAG |
| 30 | +# |
| 31 | +# Alternatively, it is possible to override all registries or tags with: |
| 32 | +# - IMAGE_REGISTRY |
| 33 | +# - IMAGE_TAG |
| 34 | +# These are used as fallback when the more specific variables are unset or empty. |
| 35 | +# |
| 36 | +# Beware that the .yaml files do not have "imagePullPolicy: Always". That means that |
| 37 | +# also the "canary" images will only be pulled once. This is good for testing |
| 38 | +# (starting a pod multiple times will always run with the same canary image), but |
| 39 | +# implies that refreshing that image has to be done manually. |
| 40 | +# |
| 41 | +# As a special case, 'none' as registry removes the registry name. |
| 42 | + |
| 43 | +# The default is to use the RBAC rules that match the image that is |
| 44 | +# being used, also in the case that the image gets overridden. This |
| 45 | +# way if there are breaking changes in the RBAC rules, the deployment |
| 46 | +# will continue to work. |
| 47 | +# |
| 48 | +# However, such breaking changes should be rare and only occur when updating |
| 49 | +# to a new major version of a sidecar. Nonetheless, to allow testing the scenario |
| 50 | +# where the image gets overridden but not the RBAC rules, updating the RBAC |
| 51 | +# rules can be disabled. |
| 52 | +: ${UPDATE_RBAC_RULES:=true} |
| 53 | +function rbac_version () { |
15 | 54 | yaml="$1"
|
16 | 55 | image="$2"
|
| 56 | + update_rbac="$3" |
| 57 | + |
| 58 | + # get version from `image: quay.io/k8scsi/csi-attacher:v1.0.1`, ignoring comments |
| 59 | + version="$(sed -e 's/ *#.*$//' "$yaml" | grep "image:.*$image" | sed -e 's/ *#.*//' -e 's/.*://')" |
| 60 | + |
| 61 | + if $update_rbac; then |
| 62 | + # apply overrides |
| 63 | + varname=$(echo $image | tr - _ | tr a-z A-Z) |
| 64 | + eval version=\${${varname}_TAG:-\${IMAGE_TAG:-\$version}} |
| 65 | + fi |
| 66 | + |
| 67 | + # When using canary images, we have to assume that the |
| 68 | + # canary images were built from the corresponding branch. |
| 69 | + case "$version" in canary) version=master;; |
| 70 | + *-canary) version="$(echo "$version" | sed -e 's/\(.*\)-canary/release-\1/')";; |
| 71 | + esac |
17 | 72 |
|
18 |
| - # get version from `image: quay.io/k8scsi/csi-attacher:v1.0.1` |
19 |
| - grep "image:.*$image" "$yaml" | sed -e 's/.*:v/v/' |
| 73 | + echo "$version" |
20 | 74 | }
|
21 | 75 |
|
22 |
| -BASE_DIR=$(dirname "$0") |
23 |
| -K8S_RELEASE=${K8S_RELEASE:-"release-1.13"} |
24 |
| -PROVISIONER_RELEASE=${PROVISIONER_RELEASE:-$(image_version "${BASE_DIR}/hostpath/csi-hostpath-provisioner.yaml" csi-provisioner)} |
25 |
| -ATTACHER_RELEASE=${ATTACHER_RELEASE:-$(image_version "${BASE_DIR}/hostpath/csi-hostpath-attacher.yaml" csi-attacher)} |
26 |
| -SNAPSHOTTER_RELEASE=${SNAPSHOTTER_RELEASE:-$(image_version "${BASE_DIR}/snapshotter/csi-hostpath-snapshotter.yaml" csi-snapshotter)} |
| 76 | +# In addition, the RBAC rules can be overridden separately. |
| 77 | +CSI_PROVISIONER_RBAC_YAML="https://raw.githubusercontent.com/kubernetes-csi/external-provisioner/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-provisioner.yaml" csi-provisioner false)/deploy/kubernetes/rbac.yaml" |
| 78 | +: ${CSI_PROVISIONER_RBAC:=https://raw.githubusercontent.com/kubernetes-csi/external-provisioner/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-provisioner.yaml" csi-provisioner "${UPDATE_RBAC_RULES}")/deploy/kubernetes/rbac.yaml} |
| 79 | +CSI_ATTACHER_RBAC_YAML="https://raw.githubusercontent.com/kubernetes-csi/external-attacher/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-attacher.yaml" csi-attacher false)/deploy/kubernetes/rbac.yaml" |
| 80 | +: ${CSI_ATTACHER_RBAC:=https://raw.githubusercontent.com/kubernetes-csi/external-attacher/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-attacher.yaml" csi-attacher "${UPDATE_RBAC_RULES}")/deploy/kubernetes/rbac.yaml} |
| 81 | +CSI_SNAPSHOTTER_RBAC_YAML="https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-snapshotter.yaml" csi-snapshotter false)/deploy/kubernetes/rbac.yaml" |
| 82 | +: ${CSI_SNAPSHOTTER_RBAC:=https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-snapshotter.yaml" csi-snapshotter "${UPDATE_RBAC_RULES}")/deploy/kubernetes/rbac.yaml} |
| 83 | + |
27 | 84 | INSTALL_CRD=${INSTALL_CRD:-"false"}
|
28 | 85 |
|
| 86 | +run () { |
| 87 | + echo "$@" >&2 |
| 88 | + "$@" |
| 89 | +} |
| 90 | + |
29 | 91 | # apply CSIDriver and CSINodeInfo API objects
|
30 | 92 | if [[ "${INSTALL_CRD}" =~ ^(y|Y|yes|true)$ ]] ; then
|
31 | 93 | echo "installing CRDs"
|
32 |
| - kubectl apply -f https://raw.githubusercontent.com/kubernetes/csi-api/${K8S_RELEASE}/pkg/crd/manifests/csidriver.yaml --validate=false |
33 |
| - kubectl apply -f https://raw.githubusercontent.com/kubernetes/csi-api/${K8S_RELEASE}/pkg/crd/manifests/csinodeinfo.yaml --validate=false |
| 94 | + run kubectl apply -f https://raw.githubusercontent.com/kubernetes/csi-api/${K8S_RELEASE}/pkg/crd/manifests/csidriver.yaml --validate=false |
| 95 | + run kubectl apply -f https://raw.githubusercontent.com/kubernetes/csi-api/${K8S_RELEASE}/pkg/crd/manifests/csinodeinfo.yaml --validate=false |
34 | 96 | fi
|
35 | 97 |
|
36 | 98 | # rbac rules
|
37 | 99 | echo "applying RBAC rules"
|
38 |
| -kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-provisioner/${PROVISIONER_RELEASE}/deploy/kubernetes/rbac.yaml |
39 |
| -kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-attacher/${ATTACHER_RELEASE}/deploy/kubernetes/rbac.yaml |
40 |
| -kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${SNAPSHOTTER_RELEASE}/deploy/kubernetes/rbac.yaml |
| 100 | +for component in CSI_PROVISIONER CSI_ATTACHER CSI_SNAPSHOTTER; do |
| 101 | + eval current="\${${component}_RBAC}" |
| 102 | + eval original="\${${component}_RBAC_YAML}" |
| 103 | + if [ "$current" != "$original" ]; then |
| 104 | + echo "Using non-default RBAC rules for $component. Changes from $original to $current are:" |
| 105 | + diff -c <(wget --quiet -O - "$original") <(if [[ "$current" =~ ^http ]]; then wget --quiet -O - "$current"; else cat "$current"; fi) || true |
| 106 | + fi |
| 107 | + run kubectl apply -f "${current}" |
| 108 | +done |
41 | 109 |
|
42 | 110 | # deploy hostpath plugin and registrar sidecar
|
43 | 111 | echo "deploying hostpath components"
|
44 |
| -kubectl apply -f ${BASE_DIR}/hostpath |
| 112 | +for i in $(ls ${BASE_DIR}/hostpath/*.yaml | sort); do |
| 113 | + echo " $i" |
| 114 | + cat "$i" | while IFS= read -r line; do |
| 115 | + nocomments="$(echo "$line" | sed -e 's/ *#.*$//')" |
| 116 | + if echo "$nocomments" | grep -q '^\s*image:\s*'; then |
| 117 | + # Split 'image: quay.io/k8scsi/csi-attacher:v1.0.1' |
| 118 | + # into image (quay.io/k8scsi/csi-attacher:v1.0.1), |
| 119 | + # registry (quay.io/k8scsi), |
| 120 | + # name (csi-attacher), |
| 121 | + # tag (v1.0.1). |
| 122 | + image=$(echo "$nocomments" | sed -e 's;.*image:\s*;;') |
| 123 | + registry=$(echo "$image" | sed -e 's;\(.*\)/.*;\1;') |
| 124 | + name=$(echo "$image" | sed -e 's;.*/\([^:]*\).*;\1;') |
| 125 | + tag=$(echo "$image" | sed -e 's;.*:;;') |
| 126 | + |
| 127 | + # Variables are with underscores and upper case. |
| 128 | + varname=$(echo $name | tr - _ | tr a-z A-Z) |
| 129 | + |
| 130 | + # Now replace registry and/or tag, if set as env variables. |
| 131 | + # If not set, the replacement is the same as the original value. |
| 132 | + prefix=$(eval echo \${${varname}_REGISTRY:-${IMAGE_REGISTRY:-${registry}}}/ | sed -e 's;none/;;') |
| 133 | + suffix=$(eval echo :\${${varname}_TAG:-${IMAGE_TAG:-${tag}}}) |
| 134 | + line="$(echo "$nocomments" | sed -e "s;$image;${prefix}${name}${suffix};")" |
| 135 | + echo " using $line" >&2 |
| 136 | + fi |
| 137 | + echo "$line" |
| 138 | + done | kubectl apply -f - |
| 139 | +done |
45 | 140 |
|
46 |
| -# deploy snapshotter and snapshotclass |
47 |
| -echo "deploying snapshotter and snapshotclass" |
48 |
| -kubectl create -f ${BASE_DIR}/snapshotter/csi-hostpath-snapshotter.yaml |
| 141 | +# deploy snapshotclass |
| 142 | +echo "deploying snapshotclass" |
49 | 143 | kubectl create -f ${BASE_DIR}/snapshotter/csi-hostpath-snapshotclass.yaml
|
0 commit comments