Skip to content

Commit 7c2f004

Browse files
authored
clarify maxOpenShiftVersion upgrade error message (#2326)
Signed-off-by: Ankita Thomas <[email protected]>
1 parent 760c10d commit 7c2f004

File tree

3 files changed

+25
-41
lines changed

3 files changed

+25
-41
lines changed

Diff for: pkg/controller/operators/openshift/clusteroperator_controller_test.go

+3-3
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(),

Diff for: pkg/controller/operators/openshift/helpers.go

+8-3
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) {

Diff for: pkg/controller/operators/openshift/helpers_test.go

+14-35
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,6 @@ func TestIncompatibleOperators(t *testing.T) {
251251
{
252252
name: "chestnut",
253253
namespace: "default",
254-
maxOpenShiftVersion: "1.2.0-pre+build",
255-
},
256-
{
257-
name: "drupe",
258-
namespace: "default",
259254
maxOpenShiftVersion: "2.0.0",
260255
},
261256
},
@@ -309,27 +304,27 @@ func TestIncompatibleOperators(t *testing.T) {
309304
{
310305
name: "almond",
311306
namespace: "default",
312-
maxOpenShiftVersion: "1.0.0",
307+
maxOpenShiftVersion: "1.0",
313308
},
314309
{
315310
name: "beech",
316311
namespace: "default",
317-
maxOpenShiftVersion: "1.0.0+build",
312+
maxOpenShiftVersion: "1.0",
318313
},
319314
{
320-
name: "chestnut",
321-
namespace: "default",
322-
maxOpenShiftVersion: "1.1.0-pre",
315+
name: "chestnut",
316+
namespace: "default",
317+
err: fmt.Errorf("property olm.maxOpenShiftVersion must specify only <major>.<minor> version, got invalid value 1.1.0-pre"),
323318
},
324319
{
325-
name: "drupe",
326-
namespace: "default",
327-
maxOpenShiftVersion: "1.1.0-pre+build",
320+
name: "drupe",
321+
namespace: "default",
322+
err: fmt.Errorf("property olm.maxOpenShiftVersion must specify only <major>.<minor> version, got invalid value 1.1.0-pre+build"),
328323
},
329324
{
330325
name: "european-hazelnut",
331326
namespace: "default",
332-
maxOpenShiftVersion: "0.1.0",
327+
maxOpenShiftVersion: "0.1",
333328
},
334329
},
335330
},
@@ -369,12 +364,12 @@ func TestIncompatibleOperators(t *testing.T) {
369364
{
370365
name: "beech",
371366
namespace: "default",
372-
maxOpenShiftVersion: "1.0.0",
367+
maxOpenShiftVersion: "1.0",
373368
},
374369
{
375370
name: "chestnut",
376371
namespace: "default",
377-
maxOpenShiftVersion: "1.0.0",
372+
maxOpenShiftVersion: "1.0",
378373
},
379374
},
380375
},
@@ -414,7 +409,7 @@ func TestIncompatibleOperators(t *testing.T) {
414409
{
415410
name: "beech",
416411
namespace: "default",
417-
maxOpenShiftVersion: "1.0.0",
412+
maxOpenShiftVersion: "1.0",
418413
},
419414
{
420415
name: "chestnut",
@@ -469,11 +464,6 @@ func TestIncompatibleOperators(t *testing.T) {
469464
},
470465
},
471466
in: skews{
472-
{
473-
name: "almond",
474-
namespace: "default",
475-
maxOpenShiftVersion: "1.1.2",
476-
},
477467
{
478468
name: "beech",
479469
namespace: "default",
@@ -503,21 +493,10 @@ func TestIncompatibleOperators(t *testing.T) {
503493
namespace: "default",
504494
maxOpenShiftVersion: "1.1.0",
505495
},
506-
{
507-
name: "beech",
508-
namespace: "default",
509-
maxOpenShiftVersion: "1.1.0-pre",
510-
},
511496
},
512497
expect: expect{
513-
err: false,
514-
incompatible: skews{
515-
{
516-
name: "beech",
517-
namespace: "default",
518-
maxOpenShiftVersion: "1.1.0-pre",
519-
},
520-
},
498+
err: false,
499+
incompatible: nil,
521500
},
522501
},
523502
} {

0 commit comments

Comments
 (0)