Skip to content

Commit dca2c2c

Browse files
Merge pull request #173 from timflannagan/release-4.8-bz-1992677-parent-manual-cp
[release-4.8] Bug 1994038: clarify maxOpenShiftVersion upgrade error message
2 parents f936939 + 99e57be commit dca2c2c

File tree

4 files changed

+33
-44
lines changed

4 files changed

+33
-44
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package openshift
22

33
import (
44
"fmt"
5-
65
semver "github.com/blang/semver/v4"
76
. "github.com/onsi/ginkgo"
87
. "github.com/onsi/gomega"
@@ -213,6 +212,7 @@ var _ = Describe("ClusterOperator controller", func() {
213212
}).Should(Succeed())
214213
}()
215214

215+
parsedVersion := semver.MustParse(clusterVersion)
216216
Eventually(func() ([]configv1.ClusterOperatorStatusCondition, error) {
217217
err := k8sClient.Get(ctx, clusterOperatorName, co)
218218
return co.Status.Conditions, err
@@ -224,7 +224,7 @@ var _ = Describe("ClusterOperator controller", func() {
224224
{
225225
namespace: ns.GetName(),
226226
name: incompatible.GetName(),
227-
maxOpenShiftVersion: clusterVersion,
227+
maxOpenShiftVersion: fmt.Sprintf("%d.%d", parsedVersion.Major, parsedVersion.Minor),
228228
},
229229
}.String(),
230230
LastTransitionTime: fixedNow(),
@@ -270,7 +270,7 @@ var _ = Describe("ClusterOperator controller", func() {
270270
{
271271
namespace: ns.GetName(),
272272
name: incompatible.GetName(),
273-
maxOpenShiftVersion: short + ".0",
273+
maxOpenShiftVersion: short,
274274
},
275275
}.String(),
276276
LastTransitionTime: fixedNow(),

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (s skew) String() string {
110110
return fmt.Sprintf("%s/%s has invalid %s properties: %s", s.namespace, s.name, MaxOpenShiftVersionProperty, s.err)
111111
}
112112

113-
return fmt.Sprintf("%s/%s is incompatible with OpenShift versions greater than %s", s.namespace, s.name, s.maxOpenShiftVersion)
113+
return fmt.Sprintf("%s/%s is incompatible with OpenShift minor versions greater than %s", s.namespace, s.name, s.maxOpenShiftVersion)
114114
}
115115

116116
type transientError struct {
@@ -165,7 +165,8 @@ func incompatibleOperators(ctx context.Context, cli client.Client) (skews, error
165165
if max == nil || max.GTE(next) {
166166
continue
167167
}
168-
s.maxOpenShiftVersion = max.String()
168+
169+
s.maxOpenShiftVersion = fmt.Sprintf("%d.%d", max.Major, max.Minor)
169170

170171
incompatible = append(incompatible, s)
171172
}
@@ -252,7 +253,11 @@ func maxOpenShiftVersion(csv *operatorsv1alpha1.ClusterServiceVersion) (*semver.
252253
return nil, fmt.Errorf(`Failed to parse "%s" as semver: %w`, value, err)
253254
}
254255

255-
return &version, nil
256+
truncatedVersion := semver.Version{Major: version.Major, Minor: version.Minor}
257+
if !version.EQ(truncatedVersion) {
258+
return nil, fmt.Errorf("property %s must specify only <major>.<minor> version, got invalid value %s", MaxOpenShiftVersionProperty, version)
259+
}
260+
return &truncatedVersion, nil
256261
}
257262

258263
func notCopiedSelector() (labels.Selector, error) {

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

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,6 @@ 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",
258253
maxOpenShiftVersion: "2.0.0",
259254
},
260255
},
@@ -308,27 +303,27 @@ func TestIncompatibleOperators(t *testing.T) {
308303
{
309304
name: "almond",
310305
namespace: "default",
311-
maxOpenShiftVersion: "1.0.0",
306+
maxOpenShiftVersion: "1.0",
312307
},
313308
{
314309
name: "beech",
315310
namespace: "default",
316-
maxOpenShiftVersion: "1.0.0+build",
311+
maxOpenShiftVersion: "1.0",
317312
},
318313
{
319-
name: "chestnut",
320-
namespace: "default",
321-
maxOpenShiftVersion: "1.1.0-pre",
314+
name: "chestnut",
315+
namespace: "default",
316+
err: fmt.Errorf("property olm.maxOpenShiftVersion must specify only <major>.<minor> version, got invalid value 1.1.0-pre"),
322317
},
323318
{
324-
name: "drupe",
325-
namespace: "default",
326-
maxOpenShiftVersion: "1.1.0-pre+build",
319+
name: "drupe",
320+
namespace: "default",
321+
err: fmt.Errorf("property olm.maxOpenShiftVersion must specify only <major>.<minor> version, got invalid value 1.1.0-pre+build"),
327322
},
328323
{
329324
name: "european-hazelnut",
330325
namespace: "default",
331-
maxOpenShiftVersion: "0.1.0",
326+
maxOpenShiftVersion: "0.1",
332327
},
333328
},
334329
},
@@ -368,12 +363,12 @@ func TestIncompatibleOperators(t *testing.T) {
368363
{
369364
name: "beech",
370365
namespace: "default",
371-
maxOpenShiftVersion: "1.0.0",
366+
maxOpenShiftVersion: "1.0",
372367
},
373368
{
374369
name: "chestnut",
375370
namespace: "default",
376-
maxOpenShiftVersion: "1.0.0",
371+
maxOpenShiftVersion: "1.0",
377372
},
378373
},
379374
},
@@ -413,7 +408,7 @@ func TestIncompatibleOperators(t *testing.T) {
413408
{
414409
name: "beech",
415410
namespace: "default",
416-
maxOpenShiftVersion: "1.0.0",
411+
maxOpenShiftVersion: "1.0",
417412
},
418413
{
419414
name: "chestnut",
@@ -468,11 +463,6 @@ func TestIncompatibleOperators(t *testing.T) {
468463
},
469464
},
470465
in: skews{
471-
{
472-
name: "almond",
473-
namespace: "default",
474-
maxOpenShiftVersion: "1.1.2",
475-
},
476466
{
477467
name: "beech",
478468
namespace: "default",
@@ -502,21 +492,10 @@ func TestIncompatibleOperators(t *testing.T) {
502492
namespace: "default",
503493
maxOpenShiftVersion: "1.1.0",
504494
},
505-
{
506-
name: "beech",
507-
namespace: "default",
508-
maxOpenShiftVersion: "1.1.0-pre",
509-
},
510495
},
511496
expect: expect{
512-
err: false,
513-
incompatible: skews{
514-
{
515-
name: "beech",
516-
namespace: "default",
517-
maxOpenShiftVersion: "1.1.0-pre",
518-
},
519-
},
497+
err: false,
498+
incompatible: nil,
520499
},
521500
},
522501
} {

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

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

0 commit comments

Comments
 (0)