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
42 changes: 25 additions & 17 deletions pkg/validation/internal/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,20 @@ func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResou

semVerVersionMaxOcp, err := semver.ParseTolerant(olmMaxOpenShiftVersionValue)
if err != nil {
checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations.%s has an invalid value."+
checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations.%s has an invalid value. "+
"Unable to parse (%s) using semver : %s",
olmproperties, olmMaxOpenShiftVersionValue, err))
return checks
}

truncatedMaxOcp := semver.Version{Major: semVerVersionMaxOcp.Major, Minor: semVerVersionMaxOcp.Minor}
if !semVerVersionMaxOcp.EQ(truncatedMaxOcp) {
Copy link
Member

Choose a reason for hiding this comment

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

If olmMaxOpenShiftVersionValue is 4.8.0 it looks like this will not be tripped, right?

Is that okay, or do we want to do something like this:

regexp.MustCompile("^v?\d+\.\d+$").MatchString(olmMaxOpenShiftVersionValue)

checks.warns = append(checks.warns, fmt.Errorf("csv.Annotations.%s has an invalid value. "+
"%s must specify only major.minor versions, %s will be truncated to %s",
olmproperties, olmmaxOpenShiftVersion, semVerVersionMaxOcp, truncatedMaxOcp))
return checks
}

if semVerVersionMaxOcp.GE(semVerOCPV1beta1Unsupported) {
checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations.%s with the "+
"key and value for %s has the OCP version value %s which is >= of %s. This bundle is using APIs which were deprecated and removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+
Expand Down Expand Up @@ -248,12 +256,12 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
}

if verParsed.GE(semVerOCPV1beta1Unsupported) {
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were " +
"deprecated and removed in v1.22. " +
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were "+
"deprecated and removed in v1.22. "+
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+
"Migrate the API(s) for "+
"%s or provide compatible version(s) by using the %s annotation in " +
"`metadata/annotations.yaml` to ensure that the index image will be geneared " +
"%s or provide compatible version(s) by using the %s annotation in "+
"`metadata/annotations.yaml` to ensure that the index image will be geneared "+
"with its label. (e.g. LABEL %s='4.6-4.8')",
deprecatedAPImsg,
ocpLabelindex,
Expand All @@ -263,12 +271,12 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
} else {
// if not has not the = then the value needs contains - value less < 4.9
if !strings.Contains(indexRange, "-") {
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were " +
"deprecated and removed in v1.22. " +
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were "+
"deprecated and removed in v1.22. "+
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22 "+
"The %s allows to distribute it on >= %s. Migrate the API(s) for "+
"%s or provide compatible version(s) by using the %s annotation in " +
"`metadata/annotations.yaml` to ensure that the index image will be generated " +
"%s or provide compatible version(s) by using the %s annotation in "+
"`metadata/annotations.yaml` to ensure that the index image will be generated "+
"with its label. (e.g. LABEL %s='4.6-4.8')",
indexRange,
ocpVerV1beta1Unsupported,
Expand All @@ -287,12 +295,12 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
}

if verParsed.GE(semVerOCPV1beta1Unsupported) {
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were " +
"deprecated and removed in v1.22. " +
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were "+
"deprecated and removed in v1.22. "+
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+
"Upgrade the APIs from "+
"for %s or provide compatible distribution version(s) by using the %s " +
"annotation in `metadata/annotations.yaml` to ensure that the index image will " +
"for %s or provide compatible distribution version(s) by using the %s "+
"annotation in `metadata/annotations.yaml` to ensure that the index image will "+
"be generated with its label. (e.g. LABEL %s='4.6-4.8')",
deprecatedAPImsg,
ocpLabelindex,
Expand All @@ -310,8 +318,8 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
}
}
} else {
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were deprecated and " +
"removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were deprecated and "+
"removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+
"Migrate the APIs "+
"for %s or provide compatible version(s) via the labels. (e.g. LABEL %s='4.6-4.8')",
deprecatedAPImsg,
Expand Down
14 changes: 14 additions & 0 deletions pkg/validation/internal/community_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ func Test_communityValidator(t *testing.T) {
"This bundle is using APIs which were deprecated and removed in v1.22. " +
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22 "},
},
{
name: "should warn on patch version in maxOpenShiftVersion",
wantWarning: true,
args: args{
bundleDir: "./testdata/valid_bundle_v1beta1",
imageIndexPath: "./testdata/dockerfile/valid_bundle.Dockerfile",
annotations: map[string]string{
"olm.properties": fmt.Sprintf(`[{"type": "olm.maxOpenShiftVersion", "value": "4.8.1"}]`),
Copy link
Member

Choose a reason for hiding this comment

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

Add a test for 4.8.0 just to tell our future selves what the expectation is?

},
},
warnStrings: []string{
"Warning: Value : (etcdoperator.v0.9.4) csv.Annotations.olm.properties has an invalid value. olm.maxOpenShiftVersion must specify only major.minor versions, 4.8.1 will be truncated to 4.8.0",
},
},
}

for _, tt := range tests {
Expand Down