Skip to content

Commit 865431f

Browse files
committed
Implement more functions
1 parent 8d2cc90 commit 865431f

8 files changed

Lines changed: 1113 additions & 95 deletions

File tree

pkg/cvo/availableupdates_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ func TestSyncAvailableUpdates(t *testing.T) {
248248
return nil, nil, nil
249249
}, fake.NewClientBuilder().Build(), func(_ string) (*configv1.ClusterVersion, error) {
250250
return &configv1.ClusterVersion{}, nil
251+
}, func(name, namespace string) (*corev1.ConfigMap, error) {
252+
return &corev1.ConfigMap{}, nil
253+
}, func() string {
254+
return optr.release.Version
251255
})
252256
err := optr.syncAvailableUpdates(context.Background(), cvFixture)
253257

@@ -342,6 +346,10 @@ func TestSyncAvailableUpdates_ConditionalUpdateRecommendedConditions(t *testing.
342346
return nil, nil, nil
343347
}, fake.NewClientBuilder().Build(), func(_ string) (*configv1.ClusterVersion, error) {
344348
return &configv1.ClusterVersion{}, nil
349+
}, func(name, namespace string) (*corev1.ConfigMap, error) {
350+
return &corev1.ConfigMap{}, nil
351+
}, func() string {
352+
return optr.release.Version
345353
})
346354
err := optr.syncAvailableUpdates(context.Background(), cv)
347355

@@ -783,6 +791,10 @@ func TestSyncAvailableUpdatesDesiredUpdate(t *testing.T) {
783791
return nil, nil, nil
784792
}, fake.NewClientBuilder().Build(), func(_ string) (*configv1.ClusterVersion, error) {
785793
return &configv1.ClusterVersion{}, nil
794+
}, func(name, namespace string) (*corev1.ConfigMap, error) {
795+
return &corev1.ConfigMap{}, nil
796+
}, func() string {
797+
return optr.release.Version
786798
})
787799
if err := optr.syncAvailableUpdates(context.Background(), cv); err != nil {
788800
t.Fatalf("syncAvailableUpdates() unexpected error: %v", err)

pkg/cvo/cvo.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ func New(
330330
return nil, nil, nil
331331
}
332332
return availableUpdates.Updates, availableUpdates.ConditionalUpdates, nil
333-
}, rtClient, cvInformer.Lister().Get)
333+
}, rtClient, cvInformer.Lister().Get, func(namespace, name string) (*corev1.ConfigMap, error) {
334+
return cmConfigManagedInformer.Lister().ConfigMaps(namespace).Get(name)
335+
}, func() string {
336+
return optr.release.Version
337+
})
334338

335339
return optr, nil
336340
}

pkg/cvo/cvo_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,10 @@ func TestOperator_availableUpdatesSync(t *testing.T) {
27642764
return nil, nil, nil
27652765
}, ctrlruntimefake.NewClientBuilder().Build(), func(_ string) (*configv1.ClusterVersion, error) {
27662766
return &configv1.ClusterVersion{}, nil
2767+
}, func(name, namespace string) (*corev1.ConfigMap, error) {
2768+
return &corev1.ConfigMap{}, nil
2769+
}, func() string {
2770+
return optr.release.Version
27672771
})
27682772
err := optr.availableUpdatesSync(ctx, optr.queueKey())
27692773
if err != nil && tt.wantErr == nil {

pkg/internal/constants.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/blang/semver/v4"
8+
79
"k8s.io/apimachinery/pkg/util/sets"
810
"k8s.io/klog/v2"
911

@@ -131,3 +133,24 @@ func IsAlertConditionReason(reason string) bool {
131133
func AlertConditionMessage(alertName, severity, state, impact, details string) string {
132134
return fmt.Sprintf("%s alert %s %s, %s. %s", severity, alertName, state, impact, details)
133135
}
136+
137+
const (
138+
UpdateTypeMajor = "Major"
139+
UpdateTypeMinor = "Minor"
140+
UpdateTypePatch = "Patch"
141+
UpdateTypeUnknown = "Unknown"
142+
)
143+
144+
// UpdateType returns the type of the update from the source to the target versions
145+
func UpdateType(source, target semver.Version) string {
146+
if source.Major < target.Major {
147+
return UpdateTypeMajor
148+
}
149+
if source.Major == target.Major && source.Minor < target.Minor {
150+
return UpdateTypeMinor
151+
}
152+
if source.LT(target) {
153+
return UpdateTypePatch
154+
}
155+
return UpdateTypeUnknown
156+
}

pkg/payload/precondition/clusterversion/upgradeable.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,8 @@ func majorOrMinorUpdateFrom(status configv1.ClusterVersionStatus, currentVersion
150150
}
151151
if cond := resourcemerge.FindOperatorStatusCondition(status.Conditions, configv1.OperatorProgressing); cond != nil &&
152152
cond.Status == configv1.ConditionTrue {
153-
if v.Major < currentVersion.Major {
154-
return completedVersion, "Major"
155-
}
156-
if v.Major == currentVersion.Major && v.Minor < currentVersion.Minor {
157-
return completedVersion, "Minor"
153+
if ut := internal.UpdateType(v, currentVersion); ut == internal.UpdateTypeMajor || ut == internal.UpdateTypeMinor {
154+
return completedVersion, ut
158155
}
159156
}
160157
return "", ""

0 commit comments

Comments
 (0)