Skip to content

Commit 463cd0b

Browse files
committed
Manage proposals
- Create proposals for each direct update path. - Clean up the proposals if needed. ReadinessJson will be implemented with another pull.
1 parent a87d072 commit 463cd0b

10 files changed

Lines changed: 1190 additions & 113 deletions

File tree

.openshift-tests-extension/openshift_payload_cluster-version-operator.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"name": "[Jira:\"Cluster Version Operator\"] cluster-version-operator should create proposals",
102102
"labels": {
103103
"Lifecycle:informing": {},
104+
"OTA-1966": {},
104105
"Serial": {}
105106
},
106107
"resources": {

pkg/cvo/availableupdates_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ func newOperator(url string, cluster release, promqlMock clusterconditions.Condi
211211
fake.NewClientBuilder().Build(), func(_ string) (*configv1.ClusterVersion, error) {
212212
return &configv1.ClusterVersion{}, nil
213213
},
214+
func(_ context.Context, namespace, name string, _ metav1.GetOptions) (*corev1.ConfigMap, error) {
215+
return &corev1.ConfigMap{}, nil
216+
},
217+
func() string {
218+
return operator.release.Version
219+
},
214220
)
215221
return availableUpdates, operator
216222
}

pkg/cvo/cvo.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,23 @@ func New(
324324

325325
optr.configuration = configuration.NewClusterVersionOperatorConfiguration(operatorClient, operatorInformerFactory)
326326

327-
optr.proposalController = proposal.NewController(func() ([]configv1.Release, []configv1.ConditionalUpdate, error) {
328-
availableUpdates := optr.getAvailableUpdates()
329-
if availableUpdates == nil {
330-
return nil, nil, nil
331-
}
332-
return availableUpdates.Updates, availableUpdates.ConditionalUpdates, nil
333-
}, rtClient, cvInformer.Lister().Get)
327+
optr.proposalController = proposal.NewController(
328+
func() ([]configv1.Release, []configv1.ConditionalUpdate, error) {
329+
availableUpdates := optr.getAvailableUpdates()
330+
if availableUpdates == nil {
331+
return nil, nil, nil
332+
}
333+
return availableUpdates.Updates, availableUpdates.ConditionalUpdates, nil
334+
},
335+
rtClient,
336+
cvInformer.Lister().Get,
337+
func(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*corev1.ConfigMap, error) {
338+
return kubeClient.CoreV1().ConfigMaps(namespace).Get(ctx, name, opts)
339+
},
340+
func() string {
341+
return optr.release.Version
342+
},
343+
)
334344

335345
return optr, nil
336346
}

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(_ context.Context, namespace, name string, _ metav1.GetOptions) (*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)