2 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 COMMANDS="kubectl helm make java az"
25 function check_requirement() {
30 echo "$1 was not found on machine. Please install it before proceeding."
35 echo "Checking requirements are installed..."
37 for req in $COMMANDS; do
38 check_requirement $req
41 echo "Checking K8 version is available in Azure..."
42 if [ -z "$KUBE_VERSION" ]; then
43 echo "K8 version not provided in cloud.conf."
44 echo "Update cloud.conf with the desired version."
48 if [ -z "$LOCATION" ]; then
49 echo "Location not provided in cloud.conf."
50 echo "Update cloud.conf with the desired location."
54 supported_k8_versions=`az aks get-versions --location $LOCATION --output json --query 'orchestrators[].orchestratorVersion'`
55 echo $supported_k8_versions | grep -q $KUBE_VERSION
57 echo "K8 version $KUBE_VERSION is not supported in location $LOCATION"
58 echo "The supported versions are $supported_k8_versions."
59 echo "Update cloud.conf with a supported version."
63 echo "Checking Azure CLI version..."
64 installed_cli_version=`az --version | grep -e "^azure-cli" | awk '{print $2}'`
65 installed_major=`echo $installed_cli_version | cut -d "." -f 1`
66 installed_minor=`echo $installed_cli_version | cut -d "." -f 2`
67 installed_inc=`echo $installed_cli_version | cut -d "." -f 3`
69 if [ $installed_major -lt $CLI_MAJOR ]; then
70 echo "Azure cli version is out of date."
71 echo "Major version required is $CLI_MAJOR but $installed_major is installed."
75 if [ $installed_minor -lt $CLI_MINOR ]; then
76 echo "Azure cli version is out of date."
77 echo "Minor version required is $CLI_INC but $installed_inc is installed."
81 if [ $installed_inc -lt $CLI_INC ]; then
82 echo "Azure cli version is out of date."
83 echo "Incremental version required is $CLI_INC but $installed_inc is installed."
87 echo "Checking kubectl version is compatible with the K8 version..."
88 kubectl_version=`kubectl version --client --short | awk '{print $3}'`
89 kubectl_major=`echo $kubectl_version | cut -d "." -f 1 | sed 's/v//'`
90 kubectl_minor=`echo $kubectl_version | cut -d "." -f 2`
91 k8_major=`echo $KUBE_VERSION | cut -d "." -f 1`
92 k8_minor=`echo $KUBE_VERSION | cut -d "." -f 2`
94 if [ $kubectl_major -ne $k8_major ]; then
95 echo "kubectl major version $kubectl_major doesn't equal kubernetes server version $k8_major"
99 minor_difference=`echo "$(($kubectl_minor-$k8_minor))"`
100 minor_abs_diff=`echo $minor_difference | tr -d -`
101 if [ $minor_abs_diff -gt 1 ]; then
102 echo "The difference between k8 minor version $KUBE_VERSION and kubectl minor version $kubectl_version is greater than 1"
103 echo "Kubernetes supports kubectl within 1 minor version."
107 echo "All requirements satisfied..."