Files
update/patch-scripts/kube-upgrade/KUBE.2.preremove
Bart Wensley defa24cbaa Create sample scripts for generating k8s upgrade patches
Provide a make_kube_patch.sh script that will build patches
that can be used to upgrade kubernetes. Also includes sample
preapply/preremove scripts that will be included in the
patches.

Change-Id: Ifab05e9d407d9a7c3d8c519c90add1b3857ecdf2
Story: 2006781
Task: 38479
Signed-off-by: Bart Wensley <barton.wensley@windriver.com>
2020-01-29 10:23:47 -06:00

58 lines
1.3 KiB
Python

#!/usr/bin/python
"""
Copyright (c) 2020 Wind River Systems, Inc.
SPDX-License-Identifier: Apache-2.0
"""
from kubernetes import client, 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) is 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()