Skip to content

Commit 4092f6e

Browse files
Adding in override block and testing
1 parent dcd35fc commit 4092f6e

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

cf-deploy-kubernetes.sh

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,40 @@ else
5959
fi
6060
fi
6161

62-
#check the cluster version and decide which version of kubectl to use:
63-
SERVER_VERSION=$(kubectl version --short=true --context "${KUBECONTEXT}" | grep -i server | cut -d ':' -f2 | cut -d '.' -f2 | sed 's/[^0-9]*//g')
64-
echo "Server minor version: $SERVER_VERSION"
65-
if (( "$SERVER_VERSION" <= "6" )); then cp -f /usr/local/bin/kubectl1.6 /usr/local/bin/kubectl; fi 2>/dev/null
66-
if (( "$SERVER_VERSION" == "14" )); then cp -f /usr/local/bin/kubectl1.14 /usr/local/bin/kubectl; fi 2>/dev/null
67-
if (( "$SERVER_VERSION" >= "15" )); then cp -f /usr/local/bin/kubectl1.15 /usr/local/bin/kubectl; fi 2>/dev/null
68-
[ ! -f "${deployment_file}" ] && echo "Couldn't find $deployment_file file at $(pwd)" && exit 1;
62+
# Add SERVER_VERSION override and testing capabilities
63+
64+
if [[ -n "${SERVER_VERSION}" ]]; then
65+
# Statically define SERVER_VERSION from variable override
66+
echo "Statically defined version: ${SERVER_VERSION}"
67+
# Assign kubectl version
68+
echo "Setting kubectl to version 1.${SERVER_VERSION}"
69+
cp -f "/usr/local/bin/kubectl1.${SERVER_VERSION}" /usr/local/bin/kubectl 2>/dev/null
70+
else
71+
#check the cluster version and decide which version of kubectl to use:
72+
SERVER_VERSION=$(kubectl version --short=true --context "${KUBECONTEXT}" | grep -i server | cut -d ':' -f2 | cut -d '.' -f2 | sed 's/[^0-9]*//g')
73+
echo "Server minor version: $SERVER_VERSION"
74+
if (( "$SERVER_VERSION" <= "6" )); then cp -f /usr/local/bin/kubectl1.6 /usr/local/bin/kubectl; fi 2>/dev/null
75+
if (( "$SERVER_VERSION" == "14" )); then cp -f /usr/local/bin/kubectl1.14 /usr/local/bin/kubectl; fi 2>/dev/null
76+
if (( "$SERVER_VERSION" >= "15" )); then cp -f /usr/local/bin/kubectl1.15 /usr/local/bin/kubectl; fi 2>/dev/null
77+
[ ! -f "${deployment_file}" ] && echo "Couldn't find $deployment_file file at $(pwd)" && exit 1;
78+
fi
79+
80+
# Simple testing logic for making sure override versions are set
81+
if [[ -n "${KUBE_CTL_TEST_VERSION}" ]]; then
82+
KUBE_CTL_VERSION=`kubectl version --client --short`
83+
echo "Testing kubectl version is set..."
84+
if [[ "${KUBE_CTL_VERSION}" == *"${KUBE_CTL_TEST_VERSION}"* ]]; then
85+
echo "Version correctly set"
86+
echo "Kubectl Version: ${KUBE_CTL_VERSION}"
87+
echo "Test Version: ${KUBE_CTL_TEST_VERSION}"
88+
exit 0
89+
else
90+
echo "Kubectl Version: ${KUBE_CTL_VERSION}"
91+
echo "Test Version: ${KUBE_CTL_TEST_VERSION}"
92+
fatal "Version Mismatch!!!"
93+
exit 1
94+
fi
95+
fi
6996

7097
DEPLOYMENT_FILE=${deployment_file}-$(date '+%y-%m-%d_%H-%M-%S').yml
7198
$(dirname $0)/template.sh "$deployment_file" > "$DEPLOYMENT_FILE" || fatal "Failed to apply deployment template on $deployment_file"

0 commit comments

Comments
 (0)