From 211d35baeeb20324ce21a6ee8da8abbd7ed5a482 Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Fri, 7 Jul 2023 11:52:10 +0200 Subject: [PATCH] Fix crash on fresh, never upgraded cluster `DesiredUpdate` is nil on those clusters. --- pkg/clusterversion/clusterversion.go | 4 ++++ pkg/clusterversion/clusterversion_test.go | 13 ++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/clusterversion/clusterversion.go b/pkg/clusterversion/clusterversion.go index 1fe536e..7bcfa7e 100644 --- a/pkg/clusterversion/clusterversion.go +++ b/pkg/clusterversion/clusterversion.go @@ -17,6 +17,10 @@ func SpecEqualIgnoringDesiredUpdate(a, b configv1.ClusterVersionSpec) (equal boo // IsVersionUpgradeCompleted returns whether the version upgrade in desired version is completed func IsVersionUpgradeCompleted(cv configv1.ClusterVersion) bool { + if cv.Spec.DesiredUpdate == nil { + return true + } + for _, version := range cv.Status.History { if version.State == configv1.CompletedUpdate && version.Image == cv.Spec.DesiredUpdate.Image && diff --git a/pkg/clusterversion/clusterversion_test.go b/pkg/clusterversion/clusterversion_test.go index e94522b..63791d6 100644 --- a/pkg/clusterversion/clusterversion_test.go +++ b/pkg/clusterversion/clusterversion_test.go @@ -80,13 +80,12 @@ func TestIsVersionUpgradeCompleted(t *testing.T) { desiredImg := "quay.io/openshift-release-dev/ocp-release@sha256:1234" desiredVer := "4.5.23" - subject := configv1.ClusterVersion{ - Spec: configv1.ClusterVersionSpec{ - DesiredUpdate: &configv1.Update{ - Image: desiredImg, - Version: desiredVer, - }, - }, + subject := configv1.ClusterVersion{} + assert.True(t, clusterversion.IsVersionUpgradeCompleted(subject), "fresh install, desired update not set") + + subject.Spec.DesiredUpdate = &configv1.Update{ + Image: desiredImg, + Version: desiredVer, } assert.False(t, clusterversion.IsVersionUpgradeCompleted(subject), "update not in history")