Skip to content

Commit fc58b6a

Browse files
committed
clarify maxOpenShiftVersion upgrade error message
Signed-off-by: Ankita Thomas <[email protected]>
1 parent 4a784fc commit fc58b6a

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
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 {
@@ -161,7 +161,8 @@ func incompatibleOperators(ctx context.Context, cli client.Client) (skews, error
161161
if max == nil || max.GTE(*next) {
162162
continue
163163
}
164-
s.maxOpenShiftVersion = max.String()
164+
165+
s.maxOpenShiftVersion = fmt.Sprintf("%d.%d", max.Major, max.Minor)
165166

166167
incompatible = append(incompatible, s)
167168
}
@@ -234,7 +235,11 @@ func maxOpenShiftVersion(csv *operatorsv1alpha1.ClusterServiceVersion) (*semver.
234235
return nil, fmt.Errorf(`Failed to parse "%s" as semver: %w`, value, err)
235236
}
236237

237-
return &version, nil
238+
truncatedVersion := semver.Version{Major: version.Major, Minor: version.Minor}
239+
if !version.EQ(truncatedVersion) {
240+
return nil, fmt.Errorf("property %s must specify only <major>.<minor> version, got invalid value %s", MaxOpenShiftVersionProperty, version)
241+
}
242+
return &truncatedVersion, nil
238243
}
239244

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

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -299,22 +299,22 @@ func TestIncompatibleOperators(t *testing.T) {
299299
{
300300
name: "almond",
301301
namespace: "default",
302-
maxOpenShiftVersion: "1.0.0",
302+
maxOpenShiftVersion: "1.0",
303303
},
304304
{
305305
name: "beech",
306306
namespace: "default",
307-
maxOpenShiftVersion: "1.0.0+build",
307+
maxOpenShiftVersion: "1.0",
308308
},
309309
{
310-
name: "chestnut",
311-
namespace: "default",
312-
maxOpenShiftVersion: "1.1.0-pre",
310+
name: "chestnut",
311+
namespace: "default",
312+
err: fmt.Errorf("property olm.maxOpenShiftVersion must specify only <major>.<minor> version, got invalid value 1.1.0-pre"),
313313
},
314314
{
315315
name: "drupe",
316316
namespace: "default",
317-
maxOpenShiftVersion: "0.1.0",
317+
maxOpenShiftVersion: "0.1",
318318
},
319319
},
320320
},
@@ -354,12 +354,12 @@ func TestIncompatibleOperators(t *testing.T) {
354354
{
355355
name: "beech",
356356
namespace: "default",
357-
maxOpenShiftVersion: "1.0.0",
357+
maxOpenShiftVersion: "1.0",
358358
},
359359
{
360360
name: "chestnut",
361361
namespace: "default",
362-
maxOpenShiftVersion: "1.0.0",
362+
maxOpenShiftVersion: "1.0",
363363
},
364364
},
365365
},
@@ -399,7 +399,7 @@ func TestIncompatibleOperators(t *testing.T) {
399399
{
400400
name: "beech",
401401
namespace: "default",
402-
maxOpenShiftVersion: "1.0.0",
402+
maxOpenShiftVersion: "1.0",
403403
},
404404
{
405405
name: "chestnut",

0 commit comments

Comments
 (0)