Merge "disable image gc when doing k8s upgrade"

This commit is contained in:
Zuul 2023-11-24 19:58:02 +00:00 committed by Gerrit Code Review
commit 1ab7375abe
2 changed files with 31 additions and 0 deletions

View File

@ -15958,6 +15958,22 @@ class ConductorManager(service.PeriodicService):
else:
next_versions = [kube_version]
# For simplex systems, disable image garbage collection by kubelet
# during the K8s upgrade. For duplex this will be done on each controller
# by the puppet manifest called below. It wants to be done before we
# pull the images so that they can't be garbage collected by kubelet
# before they're needed.
if system.system_mode == constants.SYSTEM_MODE_SIMPLEX:
try:
# Call the helper script used by the puppet manifest.
subprocess.check_call( # pylint: disable=not-callable
["/bin/bash",
"/usr/share/puppet/modules/platform/files/disable_image_gc.sh"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
except subprocess.CalledProcessError:
LOG.error("Failed to call disable_image_gc.sh, continuing anyway.")
for k8s_version in next_versions:
LOG.info("executing playbook: %s for version %s" %
(constants.ANSIBLE_KUBE_PUSH_IMAGES_PLAYBOOK, k8s_version))

View File

@ -25,6 +25,7 @@
import copy
import mock
import os.path
import subprocess
import tempfile
import uuid
@ -1051,6 +1052,13 @@ class ManagerTestCase(base.DbTestCase):
p.start().return_value = ['v1.42.2', 'v1.43.1']
self.addCleanup(p.stop)
# Mock subprocess check_call
mock_check_call = mock.MagicMock()
p = mock.patch('eventlet.green.subprocess.check_call', mock_check_call)
mock_subprocess_check_call = p.start()
mock_subprocess_check_call.return_value = 0
self.addCleanup(p.stop)
next_versions = kubernetes.KubeOperator().kube_get_higher_patch_version('v1.41.1',
'v1.43.1')
mock_run_playbook = mock.MagicMock()
@ -1067,6 +1075,13 @@ class ManagerTestCase(base.DbTestCase):
constants.ANSIBLE_KUBE_PUSH_IMAGES_PLAYBOOK]
mock_run_playbook.assert_any_call(playbook_cmd)
# Verify that we called the script to turn off image garbage collection
mock_subprocess_check_call.assert_called_with(
["/bin/bash", "/usr/share/puppet/modules/platform/files/disable_image_gc.sh"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
# Verify that the upgrade state was updated
updated_upgrade = self.dbapi.kube_upgrade_get_one()
self.assertEqual(updated_upgrade.state,