Merge branch 'VidyaReddy-Prettier' of https://github.com/Vidya2606/setup-kubectl into VidyaReddy-Prettier

This commit is contained in:
Vidya Reddy 2022-06-24 15:35:01 -07:00
commit ac4bd7b4bf
5 changed files with 10403 additions and 12433 deletions

3468
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,31 +1,65 @@
import os, sys, json, requests, time
import os
import sys
import json
import requests
import time
version_to_check = sys.argv[1]
version_info = None
PASSED = False
try:
print('kubectl version --client -o json')
version_info = json.load(os.popen('kubectl version --client -o json'))
except Exception as ex:
sys.exit('kubectl not installed')
try:
if version_to_check == 'latest':
def get_latest_version():
response = None
time_to_sleep = 2
for _ in range(10):
response = requests.get('https://storage.googleapis.com/kubernetes-release/release/stable.txt')
response = requests.get(
'https://storage.googleapis.com/kubernetes-release/release/stable.txt')
if response.status_code == 200:
break
print('Failed to obtain latest version info, retrying.')
time.sleep(time_to_sleep)
time_to_sleep *= 2
version_to_check = response.content.decode('utf-8')
PASSED = True if version_info['clientVersion']['gitVersion'] == version_to_check else False
except:
return response.content.decode('utf-8')
version_arg = sys.argv[1]
installed_version_info = None
PASSED = True
try:
print('kubectl version --client -o json')
installed_version_info = json.load(
os.popen('kubectl version --client -o json'))
print(
f'installed version: {installed_version_info["clientVersion"]["gitVersion"]}')
except Exception as ex:
sys.exit('kubectl not installed')
try:
installed_version = installed_version_info['clientVersion']['gitVersion']
# NOT Match
if version_arg[0] == '!':
undesired_version = version_arg[1:]
print(f'undesired version: {undesired_version}')
if installed_version == undesired_version:
print(
f'installed version ({installed_version}) matches undesire {undesired_version} - FAIL')
PASSED = False
# Exact Match
else:
if version_arg == 'latest':
print('checking latest version')
desired_version = get_latest_version()
else:
desired_version = version_arg
print(f'desired version: {desired_version}')
if installed_version != desired_version:
print(
f'installed version ({installed_version}) does not match desired ({desired_version}) - FAIL')
PASSED = False
except Exception as ex:
print(f'Exception: {ex}')
pass
if not PASSED:
sys.exit('Setting up of '+version_to_check+' kubectl failed')
sys.exit('Setting up of '+version_arg+' kubectl failed')
print('Test passed')
sys.exit()