Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit 8adde49

Browse files
authored
Merge pull request #45 from ggriffiths/snapshot_beta_crds
Add snapshotter CRDs after cluster setup
2 parents a41f386 + 003c14b commit 8adde49

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

Diff for: prow.sh

+80
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ configvar CSI_PROW_E2E_ALPHA_GATES_1_16 'VolumeSnapshotDataSource=true' "alpha f
322322
configvar CSI_PROW_E2E_ALPHA_GATES_LATEST 'VolumeSnapshotDataSource=true' "alpha feature gates for latest Kubernetes"
323323
configvar CSI_PROW_E2E_ALPHA_GATES "$(get_versioned_variable CSI_PROW_E2E_ALPHA_GATES "${csi_prow_kubernetes_version_suffix}")" "alpha E2E feature gates"
324324

325+
# Which external-snapshotter tag to use for the snapshotter CRD and snapshot-controller deployment
326+
configvar CSI_SNAPSHOTTER_VERSION 'v2.0.0-rc4' "external-snapshotter version tag"
327+
325328
# Some tests are known to be unusable in a KinD cluster. For example,
326329
# stopping kubelet with "ssh <node IP> systemctl stop kubelet" simply
327330
# doesn't work. Such tests should be written in a way that they verify
@@ -670,6 +673,59 @@ install_hostpath () {
670673
fi
671674
}
672675

676+
# Installs all nessesary snapshotter CRDs
677+
install_snapshot_crds() {
678+
# Wait until volumesnapshot CRDs are in place.
679+
CRD_BASE_DIR="https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${CSI_SNAPSHOTTER_VERSION}/config/crd"
680+
kubectl apply -f "${CRD_BASE_DIR}/snapshot.storage.k8s.io_volumesnapshotclasses.yaml" --validate=false
681+
kubectl apply -f "${CRD_BASE_DIR}/snapshot.storage.k8s.io_volumesnapshots.yaml" --validate=false
682+
kubectl apply -f "${CRD_BASE_DIR}/snapshot.storage.k8s.io_volumesnapshotcontents.yaml" --validate=false
683+
cnt=0
684+
until kubectl get volumesnapshotclasses.snapshot.storage.k8s.io \
685+
&& kubectl get volumesnapshots.snapshot.storage.k8s.io \
686+
&& kubectl get volumesnapshotcontents.snapshot.storage.k8s.io; do
687+
if [ $cnt -gt 30 ]; then
688+
echo >&2 "ERROR: snapshot CRDs not ready after over 1 min"
689+
exit 1
690+
fi
691+
echo "$(date +%H:%M:%S)" "waiting for snapshot CRDs, attempt #$cnt"
692+
cnt=$((cnt + 1))
693+
sleep 2
694+
done
695+
}
696+
697+
# Install snapshot controller and associated RBAC, retrying until the pod is running.
698+
install_snapshot_controller() {
699+
kubectl apply -f "https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${CSI_SNAPSHOTTER_VERSION}/deploy/kubernetes/snapshot-controller/rbac-snapshot-controller.yaml"
700+
cnt=0
701+
until kubectl get clusterrolebinding snapshot-controller-role; do
702+
if [ $cnt -gt 30 ]; then
703+
echo "Cluster role bindings:"
704+
kubectl describe clusterrolebinding
705+
echo >&2 "ERROR: snapshot controller RBAC not ready after over 5 min"
706+
exit 1
707+
fi
708+
echo "$(date +%H:%M:%S)" "waiting for snapshot RBAC setup complete, attempt #$cnt"
709+
cnt=$((cnt + 1))
710+
sleep 10
711+
done
712+
713+
714+
kubectl apply -f "https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${CSI_SNAPSHOTTER_VERSION}/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml"
715+
cnt=0
716+
until kubectl get statefulset snapshot-controller | grep snapshot-controller | grep "1/1"; do
717+
if [ $cnt -gt 30 ]; then
718+
echo "Running statefulsets:"
719+
kubectl describe statefulsets
720+
echo >&2 "ERROR: snapshot controller not ready after over 5 min"
721+
exit 1
722+
fi
723+
echo "$(date +%H:%M:%S)" "waiting for snapshot controller deployment to complete, attempt #$cnt"
724+
cnt=$((cnt + 1))
725+
sleep 10
726+
done
727+
}
728+
673729
# collect logs and cluster status (like the version of all components, Kubernetes version, test version)
674730
collect_cluster_info () {
675731
cat <<EOF
@@ -940,6 +996,10 @@ make_test_to_junit () {
940996
fi
941997
}
942998

999+
function version_gt() {
1000+
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
1001+
}
1002+
9431003
main () {
9441004
local images ret
9451005
ret=0
@@ -1000,6 +1060,16 @@ main () {
10001060
if tests_need_non_alpha_cluster; then
10011061
start_cluster || die "starting the non-alpha cluster failed"
10021062

1063+
# Install necessary snapshot CRDs and snapshot controller
1064+
# For Kubernetes 1.17+, we will install the CRDs and snapshot controller.
1065+
if version_gt "${CSI_PROW_KUBERNETES_VERSION}" "1.16.255" || "${CSI_PROW_KUBERNETES_VERSION}" == "latest"; then
1066+
info "Version ${CSI_PROW_KUBERNETES_VERSION}, installing CRDs and snapshot controller"
1067+
install_snapshot_crds
1068+
install_snapshot_controller
1069+
else
1070+
info "Version ${CSI_PROW_KUBERNETES_VERSION}, skipping CRDs and snapshot controller"
1071+
fi
1072+
10031073
# Installing the driver might be disabled.
10041074
if install_hostpath "$images"; then
10051075
collect_cluster_info
@@ -1037,6 +1107,16 @@ main () {
10371107
# Need to (re)create the cluster.
10381108
start_cluster "${CSI_PROW_E2E_ALPHA_GATES}" || die "starting alpha cluster failed"
10391109

1110+
# Install necessary snapshot CRDs and snapshot controller
1111+
# For Kubernetes 1.17+, we will install the CRDs and snapshot controller.
1112+
if version_gt "${CSI_PROW_KUBERNETES_VERSION}" "1.16.255" || "${CSI_PROW_KUBERNETES_VERSION}" == "latest"; then
1113+
info "Version ${CSI_PROW_KUBERNETES_VERSION}, installing CRDs and snapshot controller"
1114+
install_snapshot_crds
1115+
install_snapshot_controller
1116+
else
1117+
info "Version ${CSI_PROW_KUBERNETES_VERSION}, skipping CRDs and snapshot controller"
1118+
fi
1119+
10401120
# Installing the driver might be disabled.
10411121
if install_hostpath "$images"; then
10421122
collect_cluster_info

0 commit comments

Comments
 (0)