Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: buggy nextY logic for maxOCPVersion #3416

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
33 changes: 11 additions & 22 deletions pkg/controller/operators/openshift/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ func (s skews) String() string {
j--
}

return "ClusterServiceVersions blocking cluster upgrade: " + strings.Join(msg, ",")
// it is safe to ignore the error here, with the assumption
// that we build each skew object only after verifying that the
// version string is parseable safely.
maxOCPVersion, _ := semver.ParseTolerant(s[0].maxOpenShiftVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, will here be panic if the s is an empty slice?

nextY := nextY(maxOCPVersion).String()
return fmt.Sprintf("ClusterServiceVersions blocking minor version upgrades to %s or higher:\n%s", nextY, strings.Join(msg, "\n"))
}

type skew struct {
Expand All @@ -103,10 +108,9 @@ type skew struct {

func (s skew) String() string {
if s.err != nil {
return fmt.Sprintf("%s/%s has invalid %s properties: %s", s.namespace, s.name, MaxOpenShiftVersionProperty, s.err)
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 minor versions greater than %s", s.namespace, s.name, s.maxOpenShiftVersion)
return fmt.Sprintf("- maximum supported OCP version for %s/%s is %s", s.namespace, s.name, s.maxOpenShiftVersion)
}

type transientError struct {
Expand All @@ -131,11 +135,6 @@ func incompatibleOperators(ctx context.Context, cli client.Client) (skews, error
return nil, fmt.Errorf("failed to determine current OpenShift Y-stream release")
}

next, err := nextY(*current)
if err != nil {
return nil, err
}

csvList := &operatorsv1alpha1.ClusterServiceVersionList{}
if err := cli.List(ctx, csvList); err != nil {
return nil, &transientError{fmt.Errorf("failed to list ClusterServiceVersions: %w", err)}
Expand All @@ -158,7 +157,7 @@ func incompatibleOperators(ctx context.Context, cli client.Client) (skews, error
continue
}

if max == nil || max.GTE(next) {
if max == nil || max.GTE(nextY(*current)) {
continue
}

Expand Down Expand Up @@ -224,18 +223,8 @@ func getCurrentRelease() (*semver.Version, error) {
return currentRelease.version, nil
}

func nextY(v semver.Version) (semver.Version, error) {
v.Build = nil // Builds are irrelevant

if len(v.Pre) > 0 {
// Dropping pre-releases is equivalent to incrementing Y
v.Pre = nil
v.Patch = 0

return v, nil
}

return v, v.IncrementMinor() // Sets Y=Y+1 and Z=0
func nextY(v semver.Version) semver.Version {
return semver.Version{Major: v.Major, Minor: v.Minor + 1} // Sets Y=Y+1
}

const (
Expand Down
36 changes: 33 additions & 3 deletions pkg/controller/operators/openshift/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func TestIncompatibleOperators(t *testing.T) {
},
{
description: "ClusterPre",
version: "1.1.0-pre", // Next Y-stream is 1.1.0, NOT 1.2.0
version: "1.1.0-pre", // Next Y-stream is 1.2.0
in: skews{
{
name: "almond",
Expand All @@ -432,8 +432,14 @@ func TestIncompatibleOperators(t *testing.T) {
},
},
expect: expect{
err: false,
incompatible: nil,
err: false,
incompatible: skews{
{
name: "almond",
namespace: "default",
maxOpenShiftVersion: "1.1",
},
},
},
},
} {
Expand Down Expand Up @@ -597,3 +603,27 @@ func TestNotCopiedSelector(t *testing.T) {
})
}
}

func TestOCPVersionNextY(t *testing.T) {
for _, tc := range []struct {
description string
inVersion semver.Version
expectedVersion semver.Version
}{
{
description: "Version: 4.16.0. Expected output: 4.17",
inVersion: semver.MustParse("4.16.0"),
expectedVersion: semver.MustParse("4.17.0"),
},
{
description: "Version: 4.16.0-rc1. Expected output: 4.17",
inVersion: semver.MustParse("4.16.0-rc1"),
expectedVersion: semver.MustParse("4.17.0"),
},
} {
t.Run(tc.description, func(t *testing.T) {
outVersion := nextY(tc.inVersion)
require.Equal(t, outVersion, tc.expectedVersion)
})
}
}