Skip to content

Commit a417adc

Browse files
committed
fix(openshift): drop z from next calculated y-stream (#2324)
When determining operator compatibility, drop z and build versions in the calculation of the next Y-stream (minor) release of OpenShift. e.g. If the current version is v4.9.5+build, the next Y-stream is calculated as v4.10.0. If a pre-release is included, drop it as well but don't increment the minor version. e.g. If the current version is v4.10.0-rc, the next Y-stream is calculated as v4.10.0. Before this change, the next Y-stream was the result of simply iterating the cluster's minor version. When the cluster was at a patch version greater than that specified by an operator, upgrades would be erroneously blocked. e.g. If the current version was v4.9.5, the next version would be calculated as v4.10.5, which would block upgrades on operators with max versions set to v4.10 -- or more explicitly [v4.10.0, v4.10.5) (')' is read "exclusive"). Signed-off-by: Nick Hale <[email protected]> Upstream-repository: operator-lifecycle-manager Upstream-commit: 760c10d78d6f830b5aa773080847b46557c5986a
1 parent 2ab4171 commit a417adc

File tree

3 files changed

+127
-12
lines changed
  • staging/operator-lifecycle-manager/pkg/controller/operators/openshift
  • vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/openshift

3 files changed

+127
-12
lines changed

staging/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,20 @@ func transientErrors(err error) error {
125125
}
126126

127127
func incompatibleOperators(ctx context.Context, cli client.Client) (skews, error) {
128-
next, err := desiredRelease(ctx, cli)
128+
desired, err := desiredRelease(ctx, cli)
129129
if err != nil {
130130
return nil, err
131131
}
132132

133-
if next == nil {
133+
if desired == nil {
134134
// Note: This shouldn't happen
135-
return nil, fmt.Errorf("Failed to determine next OpenShift Y-stream release")
135+
return nil, fmt.Errorf("Failed to determine current OpenShift Y-stream release")
136+
}
137+
138+
next, err := nextY(*desired)
139+
if err != nil {
140+
return nil, err
136141
}
137-
next.Minor++
138142

139143
csvList := &operatorsv1alpha1.ClusterServiceVersionList{}
140144
if err := cli.List(ctx, csvList); err != nil {
@@ -158,7 +162,7 @@ func incompatibleOperators(ctx context.Context, cli client.Client) (skews, error
158162
continue
159163
}
160164

161-
if max == nil || max.GTE(*next) {
165+
if max == nil || max.GTE(next) {
162166
continue
163167
}
164168
s.maxOpenShiftVersion = max.String()
@@ -189,6 +193,20 @@ func desiredRelease(ctx context.Context, cli client.Client) (*semver.Version, er
189193
return &desired, nil
190194
}
191195

196+
func nextY(v semver.Version) (semver.Version, error) {
197+
v.Build = nil // Builds are irrelevant
198+
199+
if len(v.Pre) > 0 {
200+
// Dropping pre-releases is equivalent to incrementing Y
201+
v.Pre = nil
202+
v.Patch = 0
203+
204+
return v, nil
205+
}
206+
207+
return v, v.IncrementMinor() // Sets Y=Y+1 and Z=0
208+
}
209+
192210
const (
193211
MaxOpenShiftVersionProperty = "olm.maxOpenShiftVersion"
194212
)

staging/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers_test.go

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ func TestIncompatibleOperators(t *testing.T) {
250250
{
251251
name: "chestnut",
252252
namespace: "default",
253+
maxOpenShiftVersion: "1.2.0-pre+build",
254+
},
255+
{
256+
name: "drupe",
257+
namespace: "default",
253258
maxOpenShiftVersion: "2.0.0",
254259
},
255260
},
@@ -289,6 +294,11 @@ func TestIncompatibleOperators(t *testing.T) {
289294
{
290295
name: "drupe",
291296
namespace: "default",
297+
maxOpenShiftVersion: "1.1.0-pre+build",
298+
},
299+
{
300+
name: "european-hazelnut",
301+
namespace: "default",
292302
maxOpenShiftVersion: "0.1.0",
293303
},
294304
},
@@ -313,6 +323,11 @@ func TestIncompatibleOperators(t *testing.T) {
313323
{
314324
name: "drupe",
315325
namespace: "default",
326+
maxOpenShiftVersion: "1.1.0-pre+build",
327+
},
328+
{
329+
name: "european-hazelnut",
330+
namespace: "default",
316331
maxOpenShiftVersion: "0.1.0",
317332
},
318333
},
@@ -412,14 +427,14 @@ func TestIncompatibleOperators(t *testing.T) {
412427
},
413428
},
414429
{
415-
description: "Compatible/EmptyVersion",
430+
description: "EmptyVersion",
416431
cv: configv1.ClusterVersion{
417432
ObjectMeta: metav1.ObjectMeta{
418433
Name: "version",
419434
},
420435
Status: configv1.ClusterVersionStatus{
421436
Desired: configv1.Update{
422-
Version: "",
437+
Version: "", // This should result in an transient error
423438
},
424439
},
425440
},
@@ -440,6 +455,70 @@ func TestIncompatibleOperators(t *testing.T) {
440455
incompatible: nil,
441456
},
442457
},
458+
{
459+
description: "ClusterZ",
460+
cv: configv1.ClusterVersion{
461+
ObjectMeta: metav1.ObjectMeta{
462+
Name: "version",
463+
},
464+
Status: configv1.ClusterVersionStatus{
465+
Desired: configv1.Update{
466+
Version: "1.0.1", // Next Y-stream is 1.1.0, NOT 1.1.1
467+
},
468+
},
469+
},
470+
in: skews{
471+
{
472+
name: "almond",
473+
namespace: "default",
474+
maxOpenShiftVersion: "1.1.2",
475+
},
476+
{
477+
name: "beech",
478+
namespace: "default",
479+
maxOpenShiftVersion: "1.1",
480+
},
481+
},
482+
expect: expect{
483+
err: false,
484+
incompatible: nil,
485+
},
486+
},
487+
{
488+
description: "ClusterPre",
489+
cv: configv1.ClusterVersion{
490+
ObjectMeta: metav1.ObjectMeta{
491+
Name: "version",
492+
},
493+
Status: configv1.ClusterVersionStatus{
494+
Desired: configv1.Update{
495+
Version: "1.1.0-pre", // Next Y-stream is 1.1.0, NOT 1.2.0
496+
},
497+
},
498+
},
499+
in: skews{
500+
{
501+
name: "almond",
502+
namespace: "default",
503+
maxOpenShiftVersion: "1.1.0",
504+
},
505+
{
506+
name: "beech",
507+
namespace: "default",
508+
maxOpenShiftVersion: "1.1.0-pre",
509+
},
510+
},
511+
expect: expect{
512+
err: false,
513+
incompatible: skews{
514+
{
515+
name: "beech",
516+
namespace: "default",
517+
maxOpenShiftVersion: "1.1.0-pre",
518+
},
519+
},
520+
},
521+
},
443522
} {
444523
t.Run(tt.description, func(t *testing.T) {
445524
objs := []client.Object{tt.cv.DeepCopy()}

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers.go

Lines changed: 23 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)