diff --git a/plugins/integrations/kubernetes-service/src/main/resources/script/autoscale-kube-cluster b/plugins/integrations/kubernetes-service/src/main/resources/script/autoscale-kube-cluster index ac3fd8eab4ce..692815f3d09f 100755 --- a/plugins/integrations/kubernetes-service/src/main/resources/script/autoscale-kube-cluster +++ b/plugins/integrations/kubernetes-service/src/main/resources/script/autoscale-kube-cluster @@ -51,7 +51,7 @@ while [ -n "$1" ]; do ENABLE="true" shift 1 ;; - -d | --enable) + -d | --disable) ENABLE="false" shift 1 ;; @@ -69,7 +69,11 @@ while [ -n "$1" ]; do ;; esac done -if [ $ENABLE == "true" ] ; then +if [ -z "$ENABLE" ]; then + echo "ERROR: one of -e/--enable or -d/--disable is required. -h or --help for help" + exit 1 +fi +if [ "$ENABLE" == "true" ] ; then if [ -e /opt/autoscaler/autoscaler_tmpl.yaml ]; then sed -e "s//$ID/g" -e "s//$MINSIZE/g" -e "s//$MAXSIZE/g" /opt/autoscaler/autoscaler_tmpl.yaml > /opt/autoscaler/autoscaler_now.yaml /opt/bin/kubectl apply -f /opt/autoscaler/autoscaler_now.yaml @@ -78,16 +82,16 @@ if [ $ENABLE == "true" ] ; then mkdir -p /opt/autoscaler AUTOSCALER_URL="https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/cloudstack/examples/cluster-autoscaler-standard.yaml" autoscaler_conf_file="/opt/autoscaler/autoscaler_tmpl.yaml" - curl -sSL ${AUTOSCALER_URL} -o ${autoscaler_conf_file} - if [ $? -ne 0 ]; then + trap 'rm -f "$autoscaler_conf_file.tmp.$$"' EXIT + if ! curl -fsSL "$AUTOSCALER_URL" -o "$autoscaler_conf_file.tmp.$$"; then echo "Unable to connect to the internet to download the autoscaler deployment and image" exit 1 - else - sed -e "s//$ID/g" -e "s//$MINSIZE/g" -e "s//$MAXSIZE/g" /opt/autoscaler/autoscaler_tmpl.yaml > /opt/autoscaler/autoscaler_now.yaml - /opt/bin/kubectl apply -f /opt/autoscaler/autoscaler_now.yaml - exit 0 fi + mv -f "$autoscaler_conf_file.tmp.$$" "$autoscaler_conf_file" + sed -e "s//$ID/g" -e "s//$MINSIZE/g" -e "s//$MAXSIZE/g" /opt/autoscaler/autoscaler_tmpl.yaml > /opt/autoscaler/autoscaler_now.yaml + /opt/bin/kubectl apply -f /opt/autoscaler/autoscaler_now.yaml + exit 0 fi else - /opt/bin/kubectl delete deployment -n kube-system cluster-autoscaler + /opt/bin/kubectl delete deployment -n kube-system cluster-autoscaler --ignore-not-found fi diff --git a/plugins/integrations/kubernetes-service/src/main/resources/script/deploy-csi-driver b/plugins/integrations/kubernetes-service/src/main/resources/script/deploy-csi-driver index 69684fa32bd5..ac531d16fcd0 100644 --- a/plugins/integrations/kubernetes-service/src/main/resources/script/deploy-csi-driver +++ b/plugins/integrations/kubernetes-service/src/main/resources/script/deploy-csi-driver @@ -18,7 +18,7 @@ (/opt/bin/kubectl get pods -A | grep cloudstack-csi-controller) && exit 0 -if [ -e /opt/csi/snapshot-crds.yaml ]; then +if [ -e /opt/csi/snapshot-crds.yaml ] && [ -e /opt/csi/manifest.yaml ]; then /opt/bin/kubectl apply -f /opt/csi/snapshot-crds.yaml sleep 5 /opt/bin/kubectl apply -f /opt/csi/manifest.yaml @@ -30,17 +30,18 @@ else "https://github.com/cloudstack/cloudstack-csi-driver/releases/download/v3.0.0/snapshot-crds.yaml" "https://github.com/cloudstack/cloudstack-csi-driver/releases/download/v3.0.0/manifest.yaml" ) + trap 'rm -f "$TARGET_DIR"/*.tmp.$$' EXIT for url in "${CSI_URLS[@]}"; do filename=$(basename "$url") - curl -sSL ${url} -o ${TARGET_DIR}/${filename} - if [ $? -ne 0 ]; then + if ! curl -fsSL "$url" -o "$TARGET_DIR/$filename.tmp.$$"; then echo "Unable to connect to the internet to download the relevant files to install and setup CloudStack CSI driver" exit 1 - else - /opt/bin/kubectl apply -f /opt/csi/snapshot-crds.yaml - /opt/bin/kubectl apply -f /opt/csi/manifest.yaml - exit 0 fi + mv -f "$TARGET_DIR/$filename.tmp.$$" "$TARGET_DIR/$filename" done + /opt/bin/kubectl apply -f /opt/csi/snapshot-crds.yaml + sleep 5 + /opt/bin/kubectl apply -f /opt/csi/manifest.yaml + exit 0 fi diff --git a/plugins/integrations/kubernetes-service/src/main/resources/script/deploy-provider b/plugins/integrations/kubernetes-service/src/main/resources/script/deploy-provider index ce71e21072b6..df884eba7d46 100755 --- a/plugins/integrations/kubernetes-service/src/main/resources/script/deploy-provider +++ b/plugins/integrations/kubernetes-service/src/main/resources/script/deploy-provider @@ -25,12 +25,12 @@ else mkdir -p /opt/provider PROVIDER_URL="https://raw.githubusercontent.com/apache/cloudstack-kubernetes-provider/main/deployment.yaml" provider_conf_file="/opt/provider/provider.yaml" - curl -sSL ${PROVIDER_URL} -o ${provider_conf_file} - if [ $? -ne 0 ]; then + trap 'rm -f "$provider_conf_file.tmp.$$"' EXIT + if ! curl -fsSL "$PROVIDER_URL" -o "$provider_conf_file.tmp.$$"; then echo "Unable to connect to the internet to download the provider deployment and image" exit 1 - else - /opt/bin/kubectl apply -f /opt/provider/provider.yaml - exit 0 fi + mv -f "$provider_conf_file.tmp.$$" "$provider_conf_file" + /opt/bin/kubectl apply -f /opt/provider/provider.yaml + exit 0 fi