Cluster API: Implement upgrade to a new template

Implement the upgrade method to move a cluster to a new template.
Similar to other patches, this just updates the Helm values as required.

story: 2009780
Change-Id: I623bb47fc6a1e6abb9f2b7a50a844729fe65683d
This commit is contained in:
Matt Pryor 2023-05-24 17:03:18 +00:00 committed by John Garbutt
parent 414575a450
commit a3af9bd850
No known key found for this signature in database
3 changed files with 45 additions and 14 deletions

View File

@ -82,12 +82,29 @@ openstack image create ubuntu-focal-kube-v1.26.3 \
openstack image set ubuntu-focal-kube-v1.26.3 --os-distro ubuntu --os-version 20.04
openstack image set ubuntu-focal-kube-v1.26.3 --property kube_version=v1.26.3
curl -O https://object.arcus.openstack.hpc.cam.ac.uk/swift/v1/AUTH_f0dc9cb312144d0aa44037c9149d2513/azimuth-images-prerelease/ubuntu-focal-kube-v1.27.0-230418-0937.qcow2
openstack image create ubuntu-focal-kube-v1.27.0 \
--file ubuntu-focal-kube-v1.27.0-230418-0937.qcow2 \
--disk-format qcow2 \
--container-format bare \
--public
openstack image set ubuntu-focal-kube-v1.27.0 --os-distro ubuntu --os-version 20.04
openstack image set ubuntu-focal-kube-v1.27.0 --property kube_version=v1.27.0
# Register template for cluster api driver
openstack coe cluster template create new_driver \
--coe kubernetes \
--image $(openstack image show ubuntu-focal-kube-v1.26.3 -c id -f value) \
--external-network public \
--label kube_tag=v1.26.3 \
--master-flavor ds2G20 \
--flavor ds2G20 \
--public \
--master-lb-enabled
openstack coe cluster template create new_driver_upgrade \
--coe kubernetes \
--image $(openstack image show ubuntu-focal-kube-v1.27.0 -c id -f value) \
--external-network public \
--master-flavor ds2G20 \
--flavor ds2G20 \
--public \

View File

@ -80,6 +80,14 @@ class Driver(driver.Driver):
kcp_spec = kcp.get("spec", {}) if kcp else {}
kcp_status = kcp.get("status", {}) if kcp else {}
# The control plane object is what controls the Kubernetes version
# If it is known, report it
kube_version = kcp_status.get("version", kcp_spec.get("version"))
if cluster.coe_version != kube_version:
cluster.coe_version = kube_version
cluster.save()
kcp_true_conditions = {
cond["type"]
for cond in kcp_status.get("conditions", [])
@ -686,7 +694,22 @@ class Driver(driver.Driver):
scale_manager=None,
rollback=False,
):
raise NotImplementedError("don't support upgrade yet")
# TODO(mkjpryor) check that the upgrade is viable
# e.g. not a downgrade, not an upgrade by more than one minor version
# Updating the template will likely apply for all nodegroups
# So mark them all as having an update in progress
for nodegroup in cluster.nodegroups:
nodegroup.status = fields.ClusterStatus.UPDATE_IN_PROGRESS
nodegroup.save()
# Move the cluster to the new template
cluster.cluster_template_id = cluster_template.uuid
cluster.status = fields.ClusterStatus.UPDATE_IN_PROGRESS
cluster.save()
cluster.refresh()
self._update_helm_release(context, cluster)
def create_nodegroup(self, context, cluster, nodegroup):
nodegroup.status = fields.ClusterStatus.CREATE_IN_PROGRESS
@ -709,9 +732,7 @@ class Driver(driver.Driver):
self._update_helm_release(
context,
cluster,
list(
[ng for ng in cluster.nodegroups if ng.name != nodegroup.name]
),
[ng for ng in cluster.nodegroups if ng.name != nodegroup.name]
)
def create_federation(self, context, federation):

View File

@ -1420,15 +1420,8 @@ class ClusterAPIDriverTest(base.DbTestCase):
mock_update.assert_called_once_with(self.context, self.cluster_obj)
def test_upgrade_cluster(self):
self.assertRaises(
NotImplementedError,
self.driver.upgrade_cluster,
self.context,
self.cluster_obj,
self.cluster_obj.cluster_template,
1,
None,
)
# TODO(mkjpryor) implement this
pass
@mock.patch.object(driver.Driver, "_update_helm_release")
def test_create_nodegroup(self, mock_update):