Repository navigation
CKS: fix the add-on scripts' download and option handling - #14598
Open
bhouse-nexthop wants to merge 1 commit into
Open
bhouse-nexthop wants to merge 1 commit into
bhouse-nexthop wants to merge 1 commit into
Conversation
deploy-csi-driver falls back to downloading the CSI manifests when the
node has no copy from the binaries ISO. Its download loop applied both
files and exited after fetching only the first:
for url in "${CSI_URLS[@]}"; do
curl -sSL ${url} -o ${TARGET_DIR}/${filename}
...
else
kubectl apply -f /opt/csi/snapshot-crds.yaml
kubectl apply -f /opt/csi/manifest.yaml # never downloaded
exit 0
so manifest.yaml was never fetched and the apply always failed. The
snapshot-crds.yaml it did leave behind then sent every later run down
the "files already present" branch, which failed the same way.
- deploy-csi-driver: download every file, then apply them the way the
ISO path does (CRDs, wait, manifest). Treat the files as present only
when both are there, so a node left with only snapshot-crds.yaml
downloads again.
deploy-csi-driver, deploy-provider and autoscale-kube-cluster also
called curl without -f, so an HTTP error (a moved or missing URL) was
saved as the manifest and applied, and the next run applied the saved
file again instead of downloading. Their "$? -ne 0" checks could not
report anything either: the scripts run under bash -e, so a failing
curl ended the script before the check.
- Use "curl -fsSL" inside the if, and download to a per-run temporary
file (removed by an EXIT trap) that is moved into place only once it
is complete, so a failed or interrupted download leaves no file that
a later run would apply.
autoscale-kube-cluster listed its disable option as "-d | --enable", so
"--disable" was rejected as an unknown option ("-d" worked). Run with
neither option, the unquoted [ $ENABLE == "true" ] failed with "unary
operator expected" and fell through to deleting the autoscaler. Disable
also failed when there was no autoscaler deployment to delete, so
autoscaling could not be turned off after a failed enable.
- Accept "--disable", quote the test, and refuse to run with neither
-e nor -d. CloudStack always passes one of them, so its calls are
unaffected.
- Delete the deployment with --ignore-not-found.
Signed-off-by: Brad House <bhouse@nexthop.ai>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 4.22 #14598 +/- ##
============================================
- Coverage 18.32% 18.31% -0.01%
+ Complexity 16644 16641 -3
============================================
Files 5939 5939
Lines 537768 537768
Branches 65929 65929
============================================
- Hits 98551 98512 -39
- Misses 428008 428050 +42
+ Partials 11209 11206 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the download and option handling in three of the scripts CKS copies to cluster nodes:
deploy-csi-driver,deploy-providerandautoscale-kube-cluster.Fixes #14597
What was wrong
deploy-csi-drivernever fetchedmanifest.yaml. When the node has no CSI manifests from the binaries ISO, the script downloads them. Its loop applied both files and exited after downloading only the first (snapshot-crds.yaml), so the apply ofmanifest.yamlalways failed. Thesnapshot-crds.yamlit left behind then sent every later run down the "files already present" branch, which failed the same way.curl -sSLwithout-f, so a 404 (a moved or missing URL) was written to the manifest file and applied. The bad file stayed under/optand was applied again on the next run without re-downloading. Theif [ $? -ne 0 ]checks aftercurlcouldn't report anything: the scripts run under#!/bin/bash -e, so a failingcurlended the script before the check.autoscale-kube-cluster --disablewas rejected. The option was declared as-d | --enable), so--disablefailed as an unknown option (-dworked, and is what CloudStack passes). With neither-enor-d, the unquoted[ $ENABLE == "true" ]failed with "unary operator expected" and fell through to deleting the autoscaler.kubectl delete deploymentreturned NotFound underbash -e, so the API call failed and autoscaling could not be turned off from CloudStack.How it is fixed
deploy-csi-driver: downloads every file, then applies them the way the ISO path does (CRDs,sleep 5, manifest). It treats the files as present only when bothsnapshot-crds.yamlandmanifest.yamlexist, so a node left with onlysnapshot-crds.yaml(by the old script, or by a failed download) downloads again and recovers.curl -fsSLinside theif, writing to a per-run temporary file (<file>.tmp.$$, removed by anEXITtrap) that is moved into place only once it is complete. A failed or interrupted download leaves no file that a later run would apply, and is retried on the next run with the existing error message.autoscale-kube-cluster: accepts--disable, quotes the test, and exits with an error when neither-enor-dis given, instead of deleting the autoscaler. CloudStack always passes one of them (KubernetesClusterResourceModifierActionWorker), so its calls behave as before. The delete uses--ignore-not-found, so disabling succeeds when the autoscaler isn't deployed.Not changed here:
master/main. Pinning them is separate work.scripts/util/create-kubernetes-binaries-iso.shhas the samecurlwithout-ffor the manifests it bundles into the ISO. That is a build-time script with its own cleanup questions, so it is left for a separate change./optfrom the old scripts still applies it; delete the file to recover.Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
How Has This Been Tested?
Ran the old and new scripts side by side with
/optredirected to a temporary directory, a stubcurl(succeeds, or fails a chosen URL with HTTP 404) and a stubkubectl(records calls, failsapplyof a missing file):deploy-csi-driver, no ISO files, downloads worksnapshot-crds.yamlonly;apply manifest.yamlfails, exit 1manifest.yamlreturns 404snapshot-crds.yamlleft from an earlier runmanifest.yamldeploy-provider/autoscale-kube-cluster -e, URL returns 404/optand appliedautoscale-kube-cluster --disable--ignore-not-found)autoscale-kube-cluster -d,-e -M 3 -m 1(as CloudStack calls them)autoscale-kube-cluster -i x(neither flag)bash -nandshellcheckon the three scripts: the new versions are clean. The old ones had SC2181 ($?check), SC2086 (unquoted) and SC2221/SC2222 (-d | --enableshadowed by-e | --enable).Not tested on a live CKS cluster.
How did you try to break this feature and the system with this change?
k8s-control-node.ymlcopies both CSI files together, so the "both files present" check still takes the ISO path.snapshot-crds.yamlpresent): now re-download and recover instead of failing forever.EXITtrap removes the temporary file (bash runs it on TERM/HUP too)..tmp.$$file, andmvreplaces the target in one step.-d;-i <id> -e -M <max> -m <min>): unchanged.