StarlingX Installation/Update/Patching/Backup/Restore
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
update/patch-scripts/kube-upgrade/KUBE.2.preremove

56 lines
1.3 KiB

#!/usr/bin/python
"""
Copyright (c) 2020 Wind River Systems, Inc.
SPDX-License-Identifier: Apache-2.0
"""
from kubernetes import client
from kubernetes import config
from distutils.version import LooseVersion
import sys
patch_states = {}
def fatal_error(message):
print(message)
sys.exit(1)
def get_kube_apiserver_versions():
config.load_kube_config('/etc/kubernetes/admin.conf')
versions = []
v1 = client.CoreV1Api()
ret = v1.list_pod_for_all_namespaces(watch=False)
for item in ret.items:
if item.metadata.labels.get('component') == 'kube-apiserver':
for c in item.spec.containers:
if c.name == 'kube-apiserver':
versions.append(c.image.split(':')[-1])
return versions
def main():
running_versions = get_kube_apiserver_versions()
if len(running_versions) == 0:
fatal_error("Could not determine kube-apiserver version")
# Running version must be no higher than v1.16.2
test_version = 'v1.16.2'
for running_version in running_versions:
if LooseVersion(running_version) > LooseVersion(test_version):
fatal_error("A kube-apiserver is running %s, but must be"
" no higher than %s" % (running_version, test_version))
# Success
sys.exit(0)
if __name__ == '__main__':
main()