From c317fb0324c93cbaeab1b635c745b806c04dc613 Mon Sep 17 00:00:00 2001 From: Don Penney Date: Fri, 8 May 2020 11:40:03 -0400 Subject: [PATCH] Add support to sysinv-conductor to update static images As part of the sysinv-conductor init, apply the upgrade-static-images.yml playbook to download updated images to the local registry as needed. Change-Id: I726a244ae226588327ebe2f69d4131b57cebab85 Depends-On: https://review.opendev.org/726420 Story: 2006781 Task: 39705 Signed-off-by: Don Penney --- .../sysinv/sysinv/sysinv/common/constants.py | 2 + .../sysinv/sysinv/sysinv/conductor/manager.py | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/sysinv/sysinv/sysinv/sysinv/common/constants.py b/sysinv/sysinv/sysinv/sysinv/common/constants.py index f04eba8167..655e1dc3a8 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/constants.py +++ b/sysinv/sysinv/sysinv/sysinv/common/constants.py @@ -1560,6 +1560,8 @@ ANSIBLE_KUBE_PUSH_IMAGES_PLAYBOOK = \ '/usr/share/ansible/stx-ansible/playbooks/push_k8s_images.yml' ANSIBLE_PLATFORM_BACKUP_PLAYBOOK = \ '/usr/share/ansible/stx-ansible/playbooks/backup.yml' +ANSIBLE_KUBE_STATIC_IMAGES_PLAYBOOK = \ + '/usr/share/ansible/stx-ansible/playbooks/upgrade-static-images.yml' # Clock synchronization types NTP = 'ntp' diff --git a/sysinv/sysinv/sysinv/sysinv/conductor/manager.py b/sysinv/sysinv/sysinv/sysinv/conductor/manager.py index 8575f2e9f4..d08084438d 100644 --- a/sysinv/sysinv/sysinv/sysinv/conductor/manager.py +++ b/sysinv/sysinv/sysinv/sysinv/conductor/manager.py @@ -5353,6 +5353,7 @@ class ConductorManager(service.PeriodicService): LOG.info("Tiller deployment has been patched") def _upgrade_downgrade_kube_components(self): + self._upgrade_downgrade_static_images() self._upgrade_downgrade_tiller() self._upgrade_downgrade_kube_networking() @@ -5497,6 +5498,46 @@ class ConductorManager(service.PeriodicService): return True + @retry(retry_on_result=lambda x: x is False, + wait_fixed=(CONF.conductor.kube_upgrade_downgrade_retry_interval * 1000)) + def _upgrade_downgrade_static_images(self): + try: + # Get the kubernetes version from the upgrade table + # if an upgrade exists + kube_upgrade = self.dbapi.kube_upgrade_get_one() + kube_version = \ + kubernetes.get_kube_networking_upgrade_version(kube_upgrade) + except exception.NotFound: + # Not upgrading kubernetes, get the kubernetes version + # from the kubeadm config map + kube_version = self._kube.kube_get_kubernetes_version() + + if not kube_version: + LOG.error("Unable to get the current kubernetes version.") + return False + + try: + LOG.info("_upgrade_downgrade_kube_static_images executing" + " playbook: %s for version %s" % + (constants.ANSIBLE_KUBE_STATIC_IMAGES_PLAYBOOK, kube_version)) + + proc = subprocess.Popen( + ['ansible-playbook', '-e', 'kubernetes_version=%s' % kube_version, + constants.ANSIBLE_KUBE_STATIC_IMAGES_PLAYBOOK], + stdout=subprocess.PIPE) + out, _ = proc.communicate() + + LOG.info("ansible-playbook: %s." % out) + + if proc.returncode: + raise Exception("ansible-playbook returned an error: %s" % proc.returncode) + except Exception as e: + LOG.error("Failed to upgrade/downgrade kubernetes " + "static images: {}".format(e)) + return False + + return True + def check_nodes_stable(self): hosts = self.dbapi.ihost_get_list() if (utils.is_host_simplex_controller(hosts[0]) and