Skip to content

Commit

Permalink
deploy: fix CSIStorageCapacity version check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pohly committed Mar 24, 2021
1 parent 4e95588 commit 89e339b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions deploy/kubernetes-distributed/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,21 @@ for component in CSI_PROVISIONER; do
run kubectl apply -f "${current}"
done

if kubectl get csistoragecapacities 2>&1 | grep "the server doesn't have a resource type"; then
have_csistoragecapacity=false
else
# The cluster must support exactly the version that the external-provisioner supports.
# The problem then becomes that the version of the external-provisioner might get
# changed via CSI_PROVISIONER_TAG, so we cannot just check for the version currently
# listed in the YAML file.
case "$CSI_PROVISIONER_TAG" in
"") csistoragecapacities_api=v1alpha1;; # unchanged, assume version from YAML
*) 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)
esac
resources=$(kubectl api-resources)
if echo "$resources" | grep -q "csistoragecapacities.*storage.k8s.io/$csistoragecapacities_api"; then
have_csistoragecapacity=true
else
have_csistoragecapacity=false
fi
echo "deploying with CSIStorageCapacity: $have_csistoragecapacity"

# deploy hostpath plugin and registrar sidecar
echo "deploying hostpath components"
Expand Down

0 comments on commit 89e339b

Please sign in to comment.