Skip to content

Commit

Permalink
Merge pull request #29 from appuio/fix-crash-on-fresh-cluster
Browse files Browse the repository at this point in the history
Fix crash on fresh, never upgraded cluster
  • Loading branch information
bastjan authored Jul 7, 2023
2 parents 29226b9 + 211d35b commit 7a08236
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 4 additions & 0 deletions pkg/clusterversion/clusterversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
13 changes: 6 additions & 7 deletions pkg/clusterversion/clusterversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 7a08236

Please sign in to comment.