blob: 6bbbab9b6967ffc603679240914bb1c878a0d36f [file] [log] [blame]
stark, stevenf3519422019-12-05 14:14:32 -08001#!/bin/bash
2# Copyright 2019 AT&T Intellectual Property. All rights reserved.
3#
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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.
15
16KUBE_VERSION=$1
17LOCATION=$2
18
19COMMANDS="kubectl helm make java az"
20
21CLI_MAJOR="2"
22CLI_MINOR="0"
23CLI_INC="75"
24
25function check_requirement() {
26 req=$1
27
28 command -v $1
29 if [ $? -ne 0 ]; then
30 echo "$1 was not found on machine. Please install it before proceeding."
31 exit 1
32 fi
33}
34
35echo "Checking requirements are installed..."
36
37for req in $COMMANDS; do
38 check_requirement $req
39done
40
41echo "Checking K8 version is available in Azure..."
42if [ -z "$KUBE_VERSION" ]; then
43 echo "K8 version not provided in cloud.conf."
44 echo "Update cloud.conf with the desired version."
45 exit 1
46fi
47
48if [ -z "$LOCATION" ]; then
49 echo "Location not provided in cloud.conf."
50 echo "Update cloud.conf with the desired location."
51 exit 1
52fi
53
54supported_k8_versions=`az aks get-versions --location $LOCATION --output json --query 'orchestrators[].orchestratorVersion'`
55echo $supported_k8_versions | grep -q $KUBE_VERSION
56if [ $? -ne 0 ]; then
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."
60 exit 1
61fi
62
63echo "Checking Azure CLI version..."
64installed_cli_version=`az --version | grep -e "^azure-cli" | awk '{print $2}'`
65installed_major=`echo $installed_cli_version | cut -d "." -f 1`
66installed_minor=`echo $installed_cli_version | cut -d "." -f 2`
67installed_inc=`echo $installed_cli_version | cut -d "." -f 3`
68
69if [ $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."
72 exit 1
73fi
74
75if [ $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."
78 exit 1
79fi
80
81if [ $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."
84 exit 1
85fi
86
87echo "Checking kubectl version is compatible with the K8 version..."
88kubectl_version=`kubectl version --client --short | awk '{print $3}'`
89kubectl_major=`echo $kubectl_version | cut -d "." -f 1 | sed 's/v//'`
90kubectl_minor=`echo $kubectl_version | cut -d "." -f 2`
91k8_major=`echo $KUBE_VERSION | cut -d "." -f 1`
92k8_minor=`echo $KUBE_VERSION | cut -d "." -f 2`
93
94if [ $kubectl_major -ne $k8_major ]; then
95 echo "kubectl major version $kubectl_major doesn't equal kubernetes server version $k8_major"
96 exit 1
97fi
98
99minor_difference=`echo "$(($kubectl_minor-$k8_minor))"`
100minor_abs_diff=`echo $minor_difference | tr -d -`
101if [ $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."
104 exit 1
105fi
106
107echo "All requirements satisfied..."
108sleep 1