Skip to content

Commit 89e339b

Browse files
committed
deploy: fix CSIStorageCapacity version check
Checking via "kubectl get" and parsing its output was broken in combination with "-o pipefail" because then the overall result of the pipe was false even when the expected error occurred. Checking the output of "kubectl api-resources" and failing the install when that command fails (i.e. not using it inside an if) is better. The check also failed on clusters that had the v1beta1 API but not the v1alpha1. We need to be very careful about which version we need for the external-provisioner that is going to be installed. Unfortunately some heuristics are needed to determine that.
1 parent 4e95588 commit 89e339b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

deploy/kubernetes-distributed/deploy.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,21 @@ for component in CSI_PROVISIONER; do
136136
run kubectl apply -f "${current}"
137137
done
138138

139-
if kubectl get csistoragecapacities 2>&1 | grep "the server doesn't have a resource type"; then
140-
have_csistoragecapacity=false
141-
else
139+
# The cluster must support exactly the version that the external-provisioner supports.
140+
# The problem then becomes that the version of the external-provisioner might get
141+
# changed via CSI_PROVISIONER_TAG, so we cannot just check for the version currently
142+
# listed in the YAML file.
143+
case "$CSI_PROVISIONER_TAG" in
144+
"") csistoragecapacities_api=v1alpha1;; # unchanged, assume version from YAML
145+
*) csistoragecapacities_api=v1beta1;; # set, assume that it is more recent *and* a version that uses v1beta1 (https://github.com/kubernetes-csi/external-provisioner/pull/584)
146+
esac
147+
resources=$(kubectl api-resources)
148+
if echo "$resources" | grep -q "csistoragecapacities.*storage.k8s.io/$csistoragecapacities_api"; then
142149
have_csistoragecapacity=true
150+
else
151+
have_csistoragecapacity=false
143152
fi
153+
echo "deploying with CSIStorageCapacity: $have_csistoragecapacity"
144154

145155
# deploy hostpath plugin and registrar sidecar
146156
echo "deploying hostpath components"

0 commit comments

Comments
 (0)