diff --git a/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/clusteroperator_controller_test.go b/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/clusteroperator_controller_test.go index 8d86c580b3..7589a1cf4a 100644 --- a/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/clusteroperator_controller_test.go +++ b/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/clusteroperator_controller_test.go @@ -2,7 +2,6 @@ package openshift import ( "fmt" - semver "github.com/blang/semver/v4" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -213,6 +212,7 @@ var _ = Describe("ClusterOperator controller", func() { }).Should(Succeed()) }() + parsedVersion := semver.MustParse(clusterVersion) Eventually(func() ([]configv1.ClusterOperatorStatusCondition, error) { err := k8sClient.Get(ctx, clusterOperatorName, co) return co.Status.Conditions, err @@ -224,7 +224,7 @@ var _ = Describe("ClusterOperator controller", func() { { namespace: ns.GetName(), name: incompatible.GetName(), - maxOpenShiftVersion: clusterVersion, + maxOpenShiftVersion: fmt.Sprintf("%d.%d", parsedVersion.Major, parsedVersion.Minor), }, }.String(), LastTransitionTime: fixedNow(), @@ -270,7 +270,7 @@ var _ = Describe("ClusterOperator controller", func() { { namespace: ns.GetName(), name: incompatible.GetName(), - maxOpenShiftVersion: short + ".0", + maxOpenShiftVersion: short, }, }.String(), LastTransitionTime: fixedNow(), diff --git a/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers.go b/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers.go index cfdc85d652..0732175437 100644 --- a/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers.go +++ b/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers.go @@ -110,7 +110,7 @@ func (s skew) String() string { return fmt.Sprintf("%s/%s has invalid %s properties: %s", s.namespace, s.name, MaxOpenShiftVersionProperty, s.err) } - return fmt.Sprintf("%s/%s is incompatible with OpenShift versions greater than %s", s.namespace, s.name, s.maxOpenShiftVersion) + return fmt.Sprintf("%s/%s is incompatible with OpenShift minor versions greater than %s", s.namespace, s.name, s.maxOpenShiftVersion) } type transientError struct { @@ -165,7 +165,8 @@ func incompatibleOperators(ctx context.Context, cli client.Client) (skews, error if max == nil || max.GTE(next) { continue } - s.maxOpenShiftVersion = max.String() + + s.maxOpenShiftVersion = fmt.Sprintf("%d.%d", max.Major, max.Minor) incompatible = append(incompatible, s) } @@ -252,7 +253,11 @@ func maxOpenShiftVersion(csv *operatorsv1alpha1.ClusterServiceVersion) (*semver. return nil, fmt.Errorf(`Failed to parse "%s" as semver: %w`, value, err) } - return &version, nil + truncatedVersion := semver.Version{Major: version.Major, Minor: version.Minor} + if !version.EQ(truncatedVersion) { + return nil, fmt.Errorf("property %s must specify only . version, got invalid value %s", MaxOpenShiftVersionProperty, version) + } + return &truncatedVersion, nil } func notCopiedSelector() (labels.Selector, error) { diff --git a/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers_test.go b/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers_test.go index 30d1cbb9ce..86c5cac668 100644 --- a/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers_test.go +++ b/staging/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers_test.go @@ -250,11 +250,6 @@ func TestIncompatibleOperators(t *testing.T) { { name: "chestnut", namespace: "default", - maxOpenShiftVersion: "1.2.0-pre+build", - }, - { - name: "drupe", - namespace: "default", maxOpenShiftVersion: "2.0.0", }, }, @@ -308,27 +303,27 @@ func TestIncompatibleOperators(t *testing.T) { { name: "almond", namespace: "default", - maxOpenShiftVersion: "1.0.0", + maxOpenShiftVersion: "1.0", }, { name: "beech", namespace: "default", - maxOpenShiftVersion: "1.0.0+build", + maxOpenShiftVersion: "1.0", }, { - name: "chestnut", - namespace: "default", - maxOpenShiftVersion: "1.1.0-pre", + name: "chestnut", + namespace: "default", + err: fmt.Errorf("property olm.maxOpenShiftVersion must specify only . version, got invalid value 1.1.0-pre"), }, { - name: "drupe", - namespace: "default", - maxOpenShiftVersion: "1.1.0-pre+build", + name: "drupe", + namespace: "default", + err: fmt.Errorf("property olm.maxOpenShiftVersion must specify only . version, got invalid value 1.1.0-pre+build"), }, { name: "european-hazelnut", namespace: "default", - maxOpenShiftVersion: "0.1.0", + maxOpenShiftVersion: "0.1", }, }, }, @@ -368,12 +363,12 @@ func TestIncompatibleOperators(t *testing.T) { { name: "beech", namespace: "default", - maxOpenShiftVersion: "1.0.0", + maxOpenShiftVersion: "1.0", }, { name: "chestnut", namespace: "default", - maxOpenShiftVersion: "1.0.0", + maxOpenShiftVersion: "1.0", }, }, }, @@ -413,7 +408,7 @@ func TestIncompatibleOperators(t *testing.T) { { name: "beech", namespace: "default", - maxOpenShiftVersion: "1.0.0", + maxOpenShiftVersion: "1.0", }, { name: "chestnut", @@ -468,11 +463,6 @@ func TestIncompatibleOperators(t *testing.T) { }, }, in: skews{ - { - name: "almond", - namespace: "default", - maxOpenShiftVersion: "1.1.2", - }, { name: "beech", namespace: "default", @@ -502,21 +492,10 @@ func TestIncompatibleOperators(t *testing.T) { namespace: "default", maxOpenShiftVersion: "1.1.0", }, - { - name: "beech", - namespace: "default", - maxOpenShiftVersion: "1.1.0-pre", - }, }, expect: expect{ - err: false, - incompatible: skews{ - { - name: "beech", - namespace: "default", - maxOpenShiftVersion: "1.1.0-pre", - }, - }, + err: false, + incompatible: nil, }, }, } { diff --git a/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers.go b/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers.go index cfdc85d652..0732175437 100644 --- a/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers.go +++ b/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/openshift/helpers.go @@ -110,7 +110,7 @@ func (s skew) String() string { return fmt.Sprintf("%s/%s has invalid %s properties: %s", s.namespace, s.name, MaxOpenShiftVersionProperty, s.err) } - return fmt.Sprintf("%s/%s is incompatible with OpenShift versions greater than %s", s.namespace, s.name, s.maxOpenShiftVersion) + return fmt.Sprintf("%s/%s is incompatible with OpenShift minor versions greater than %s", s.namespace, s.name, s.maxOpenShiftVersion) } type transientError struct { @@ -165,7 +165,8 @@ func incompatibleOperators(ctx context.Context, cli client.Client) (skews, error if max == nil || max.GTE(next) { continue } - s.maxOpenShiftVersion = max.String() + + s.maxOpenShiftVersion = fmt.Sprintf("%d.%d", max.Major, max.Minor) incompatible = append(incompatible, s) } @@ -252,7 +253,11 @@ func maxOpenShiftVersion(csv *operatorsv1alpha1.ClusterServiceVersion) (*semver. return nil, fmt.Errorf(`Failed to parse "%s" as semver: %w`, value, err) } - return &version, nil + truncatedVersion := semver.Version{Major: version.Major, Minor: version.Minor} + if !version.EQ(truncatedVersion) { + return nil, fmt.Errorf("property %s must specify only . version, got invalid value %s", MaxOpenShiftVersionProperty, version) + } + return &truncatedVersion, nil } func notCopiedSelector() (labels.Selector, error) {