Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package openshift

import (
"fmt"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this newline should exist to delineate standard library imports.

semver "github.com/blang/semver/v4"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -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
Expand All @@ -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(),
Expand Down Expand Up @@ -270,7 +270,7 @@ var _ = Describe("ClusterOperator controller", func() {
{
namespace: ns.GetName(),
name: incompatible.GetName(),
maxOpenShiftVersion: short + ".0",
maxOpenShiftVersion: short,
},
}.String(),
LastTransitionTime: fixedNow(),
Expand Down
11 changes: 8 additions & 3 deletions pkg/controller/operators/openshift/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe skew.maxOpenShiftVersion is the result of directly stringifying the value of the property, which can specify patch versions. I would take care to format the message so that only major.minor is displayed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the test include a maxOpenShift version that includes a patch and could we ensure that the patch version is omitted from the message?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we just throw a validation error on a patch version? It doesn't seem to me to make a lot of sense to allow users to even set it like that if we can't actually block those upgrades anyway.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about requiring the operators to declare maxOpenShiftVersion: 4.8.9999 if they support all future 4.8.* versions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just think it's confusing and erroneous to do that. OLM functionally can't do anything special with the patch version here, so we should limit it to the minor version with validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified it to drop the build version and complain on a non-zero patch/pre-release version. I've added a warning on the api validation operator-framework/api#146

}

type transientError struct {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 <major>.<minor> version, got invalid value %s", MaxOpenShiftVersionProperty, version)
}
return &truncatedVersion, nil
}

func notCopiedSelector() (labels.Selector, error) {
Expand Down
49 changes: 14 additions & 35 deletions pkg/controller/operators/openshift/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,6 @@ func TestIncompatibleOperators(t *testing.T) {
{
name: "chestnut",
namespace: "default",
maxOpenShiftVersion: "1.2.0-pre+build",
},
{
name: "drupe",
namespace: "default",
maxOpenShiftVersion: "2.0.0",
},
},
Expand Down Expand Up @@ -309,27 +304,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 <major>.<minor> 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 <major>.<minor> version, got invalid value 1.1.0-pre+build"),
},
{
name: "european-hazelnut",
namespace: "default",
maxOpenShiftVersion: "0.1.0",
maxOpenShiftVersion: "0.1",
},
},
},
Expand Down Expand Up @@ -369,12 +364,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",
},
},
},
Expand Down Expand Up @@ -414,7 +409,7 @@ func TestIncompatibleOperators(t *testing.T) {
{
name: "beech",
namespace: "default",
maxOpenShiftVersion: "1.0.0",
maxOpenShiftVersion: "1.0",
},
{
name: "chestnut",
Expand Down Expand Up @@ -469,11 +464,6 @@ func TestIncompatibleOperators(t *testing.T) {
},
},
in: skews{
{
name: "almond",
namespace: "default",
maxOpenShiftVersion: "1.1.2",
},
{
name: "beech",
namespace: "default",
Expand Down Expand Up @@ -503,21 +493,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,
},
},
} {
Expand Down