abstract get latest
This commit is contained in:
parent
85cd6e4c1d
commit
da81d22323
1 changed files with 24 additions and 15 deletions
|
@ -4,9 +4,24 @@ import json
|
|||
import requests
|
||||
import time
|
||||
|
||||
|
||||
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')
|
||||
if response.status_code == 200:
|
||||
break
|
||||
print('Failed to obtain latest version info, retrying.')
|
||||
time.sleep(time_to_sleep)
|
||||
time_to_sleep *= 2
|
||||
return response.content.decode('utf-8')
|
||||
|
||||
|
||||
version_to_check = sys.argv[1]
|
||||
installed_version_info = None
|
||||
PASSED = False
|
||||
PASSED = True
|
||||
|
||||
try:
|
||||
print('kubectl version --client -o json')
|
||||
|
@ -18,25 +33,19 @@ except Exception as ex:
|
|||
sys.exit('kubectl not installed')
|
||||
|
||||
try:
|
||||
# NOT Match
|
||||
if version_to_check[0] == '!':
|
||||
version_to_check = version_to_check[1:]
|
||||
print(f'checking NOT version: {version_to_check}')
|
||||
PASSED = True if installed_version_info['clientVersion']['gitVersion'] != version_to_check else False
|
||||
if installed_version_info['clientVersion']['gitVersion'] == version_to_check:
|
||||
PASSED = False
|
||||
# Exact Match
|
||||
else:
|
||||
if version_to_check == 'latest':
|
||||
response = None
|
||||
time_to_sleep = 2
|
||||
for _ in range(10):
|
||||
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')
|
||||
version_to_check = get_latest_version()
|
||||
print(f'version_to_check: {version_to_check}')
|
||||
PASSED = True if installed_version_info['clientVersion']['gitVersion'] == version_to_check else False
|
||||
if installed_version_info['clientVersion']['gitVersion'] != version_to_check:
|
||||
PASSED = False
|
||||
except Exception as ex:
|
||||
print(f'Exception: {ex}')
|
||||
pass
|
||||
|
@ -44,4 +53,4 @@ except Exception as ex:
|
|||
if not PASSED:
|
||||
sys.exit('Setting up of '+version_to_check+' kubectl failed')
|
||||
print('Test passed')
|
||||
sys.exit(0)
|
||||
sys.exit()
|
||||
|
|
Loading…
Add table
Reference in a new issue