Skip to content

Commit 9fdf0df

Browse files
committed
clarify maxOpenShiftVersion upgrade error message
Signed-off-by: Ankita Thomas <[email protected]>
1 parent 760c10d commit 9fdf0df

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
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

+10-10
Original file line numberDiff line numberDiff line change
@@ -309,27 +309,27 @@ func TestIncompatibleOperators(t *testing.T) {
309309
{
310310
name: "almond",
311311
namespace: "default",
312-
maxOpenShiftVersion: "1.0.0",
312+
maxOpenShiftVersion: "1.0",
313313
},
314314
{
315315
name: "beech",
316316
namespace: "default",
317-
maxOpenShiftVersion: "1.0.0+build",
317+
maxOpenShiftVersion: "1.0",
318318
},
319319
{
320-
name: "chestnut",
321-
namespace: "default",
322-
maxOpenShiftVersion: "1.1.0-pre",
320+
name: "chestnut",
321+
namespace: "default",
322+
err: fmt.Errorf("property olm.maxOpenShiftVersion must specify only <major>.<minor> version, got invalid value 1.1.0-pre"),
323323
},
324324
{
325325
name: "drupe",
326326
namespace: "default",
327-
maxOpenShiftVersion: "1.1.0-pre+build",
327+
err: fmt.Errorf("property olm.maxOpenShiftVersion must specify only <major>.<minor> version, got invalid value 1.1.0-pre+build"),
328328
},
329329
{
330330
name: "european-hazelnut",
331331
namespace: "default",
332-
maxOpenShiftVersion: "0.1.0",
332+
maxOpenShiftVersion: "0.1",
333333
},
334334
},
335335
},
@@ -369,12 +369,12 @@ func TestIncompatibleOperators(t *testing.T) {
369369
{
370370
name: "beech",
371371
namespace: "default",
372-
maxOpenShiftVersion: "1.0.0",
372+
maxOpenShiftVersion: "1.0",
373373
},
374374
{
375375
name: "chestnut",
376376
namespace: "default",
377-
maxOpenShiftVersion: "1.0.0",
377+
maxOpenShiftVersion: "1.0",
378378
},
379379
},
380380
},
@@ -414,7 +414,7 @@ func TestIncompatibleOperators(t *testing.T) {
414414
{
415415
name: "beech",
416416
namespace: "default",
417-
maxOpenShiftVersion: "1.0.0",
417+
maxOpenShiftVersion: "1.0",
418418
},
419419
{
420420
name: "chestnut",

0 commit comments

Comments
 (0)