Skip to content

Commit

Permalink
Generate an accepted risk for Y-then-Z upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
hongkailiu committed Oct 7, 2024
1 parent ce6c0b8 commit 7a6d575
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 5 deletions.
19 changes: 19 additions & 0 deletions pkg/payload/precondition/clusterversion/upgradeable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clusterversion

import (
"context"
"fmt"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -100,6 +101,24 @@ func (pf *Upgradeable) Run(ctx context.Context, releaseContext precondition.Rele
} else {
return nil
}
} else if cond := resourcemerge.FindOperatorStatusCondition(cv.Status.Conditions, configv1.OperatorProgressing); cond != nil && cond.Status == configv1.ConditionTrue {
desiredMinorInProgress := GetEffectiveMinor(cv.Status.Desired.Version)
message := fmt.Sprintf("The upgrade is retargeted to %s from the existing minor level upgrade from %s to %s.", releaseContext.DesiredVersion, currentVersion, cv.Status.Desired.Version)
klog.V(2).Infof(message)
// We have to be strict on the condition here to avoid accepting a payload unexpectedly
// because "NonBlockingWarning=true" overrides "Upgradeable=False"
if releaseContext.DesiredVersion > cv.Status.Desired.Version &&
desiredMinorInProgress == desiredMinor &&
minorVersionUpgrade(currentMinor, desiredMinorInProgress) {
return &precondition.Error{
Reason: "MinorVersionClusterUpgradeInProgress",
Message: message,
Name: pf.Name(),
// This is to generate a message in the accepted risks
// for the unblocking case 4.y.z -> 4.y+1.z' -> 4.y+1.z''
NonBlockingWarning: true,
}
}
}

return &precondition.Error{
Expand Down
70 changes: 65 additions & 5 deletions pkg/payload/precondition/clusterversion/upgradeable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ func TestUpgradeableRun(t *testing.T) {
}

tests := []struct {
name string
upgradeable *configv1.ConditionStatus
currVersion string
desiredVersion string
expected string
name string
upgradeable *configv1.ConditionStatus
currVersion string
desiredVersion string
versionPartiallyUpgraded string
NonBlockingWarning bool
expected string
}{
{
name: "first",
Expand Down Expand Up @@ -105,6 +107,38 @@ func TestUpgradeableRun(t *testing.T) {
desiredVersion: "4.1.4",
expected: "",
},
{
name: "move to 4.y.z' while 4.y.z is in progress",
currVersion: "4.6.3",
versionPartiallyUpgraded: "4.6.6",
desiredVersion: "4.6.7",
upgradeable: ptr(configv1.ConditionFalse),
},
{
name: "move to 4.y+1.z' while 4.y+1.z is in progress",
currVersion: "4.6.3",
versionPartiallyUpgraded: "4.7.2",
desiredVersion: "4.7.3",
upgradeable: ptr(configv1.ConditionFalse),
NonBlockingWarning: true,
expected: "The upgrade is retargeted to 4.7.3 from the existing minor level upgrade from 4.6.3 to 4.7.2.",
},
{
name: "block 4.y+2.z' while 4.y+1.z is in progress",
currVersion: "4.6.3",
versionPartiallyUpgraded: "4.7.2",
desiredVersion: "4.8.1",
upgradeable: ptr(configv1.ConditionFalse),
expected: "set to False",
},
{
name: "block 4.y+1.z' while 4.y.z is in progress",
currVersion: "4.14.15",
versionPartiallyUpgraded: "4.14.35",
desiredVersion: "4.15.29",
upgradeable: ptr(configv1.ConditionFalse),
expected: "set to False",
},
}

for _, tc := range tests {
Expand All @@ -114,6 +148,7 @@ func TestUpgradeableRun(t *testing.T) {
Spec: configv1.ClusterVersionSpec{},
Status: configv1.ClusterVersionStatus{
History: []configv1.UpdateHistory{},
Desired: configv1.Release{Version: tc.versionPartiallyUpgraded},
},
}
if len(tc.currVersion) > 0 {
Expand All @@ -126,12 +161,37 @@ func TestUpgradeableRun(t *testing.T) {
Message: fmt.Sprintf("set to %v", *tc.upgradeable),
})
}

if tc.versionPartiallyUpgraded != "" {
clusterVersion.Status.History = append(clusterVersion.Status.History, configv1.UpdateHistory{Version: tc.versionPartiallyUpgraded, State: configv1.PartialUpdate})
clusterVersion.Status.Conditions = append(clusterVersion.Status.Conditions, configv1.ClusterOperatorStatusCondition{
Type: configv1.OperatorProgressing,
Status: configv1.ConditionTrue,
Message: "some-message",
Reason: "some-reason",
})
} else {
clusterVersion.Status.Conditions = append(clusterVersion.Status.Conditions, configv1.ClusterOperatorStatusCondition{
Type: "UpgradeableUpgradeInProgress",
Status: configv1.ConditionFalse,
Message: "message-bar",
Reason: "reason-bar",
})
}
cvLister := fakeClusterVersionLister(t, clusterVersion)
instance := NewUpgradeable(cvLister)

err := instance.Run(ctx, precondition.ReleaseContext{
DesiredVersion: tc.desiredVersion,
})
if tc.NonBlockingWarning {
pError, ok := err.(*precondition.Error)
if !ok {
t.Errorf("Failed to convert to err: %v", err)
} else if !pError.NonBlockingWarning {
t.Error("NonBlockingWarning should be true")
}
}
switch {
case err != nil && len(tc.expected) == 0:
t.Error(err)
Expand Down

0 comments on commit 7a6d575

Please sign in to comment.