Skip to content

Commit 9caf73f

Browse files
committed
warn on maxOpenShiftVersion specifying more than major.minor (openshift#146)
Signed-off-by: Ankita Thomas <[email protected]> Upstream-repository: api Upstream-commit: 01ed866fe519bd71d8550b3f1a411f819325c422
1 parent cc481df commit 9caf73f

File tree

3 files changed

+64
-34
lines changed

3 files changed

+64
-34
lines changed

staging/api/pkg/validation/internal/community.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,20 @@ func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResou
149149

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

158+
truncatedMaxOcp := semver.Version{Major: semVerVersionMaxOcp.Major, Minor: semVerVersionMaxOcp.Minor}
159+
if !semVerVersionMaxOcp.EQ(truncatedMaxOcp) {
160+
checks.warns = append(checks.warns, fmt.Errorf("csv.Annotations.%s has an invalid value. "+
161+
"%s must specify only major.minor versions, %s will be truncated to %s",
162+
olmproperties, olmmaxOpenShiftVersion, semVerVersionMaxOcp, truncatedMaxOcp))
163+
return checks
164+
}
165+
158166
if semVerVersionMaxOcp.GE(semVerOCPV1beta1Unsupported) {
159167
checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations.%s with the "+
160168
"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. "+
@@ -248,12 +256,12 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
248256
}
249257

250258
if verParsed.GE(semVerOCPV1beta1Unsupported) {
251-
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were " +
252-
"deprecated and removed in v1.22. " +
253-
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
259+
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were "+
260+
"deprecated and removed in v1.22. "+
261+
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+
254262
"Migrate the API(s) for "+
255-
"%s or provide compatible version(s) by using the %s annotation in " +
256-
"`metadata/annotations.yaml` to ensure that the index image will be geneared " +
263+
"%s or provide compatible version(s) by using the %s annotation in "+
264+
"`metadata/annotations.yaml` to ensure that the index image will be geneared "+
257265
"with its label. (e.g. LABEL %s='4.6-4.8')",
258266
deprecatedAPImsg,
259267
ocpLabelindex,
@@ -263,12 +271,12 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
263271
} else {
264272
// if not has not the = then the value needs contains - value less < 4.9
265273
if !strings.Contains(indexRange, "-") {
266-
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were " +
267-
"deprecated and removed in v1.22. " +
274+
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were "+
275+
"deprecated and removed in v1.22. "+
268276
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22 "+
269277
"The %s allows to distribute it on >= %s. Migrate the API(s) for "+
270-
"%s or provide compatible version(s) by using the %s annotation in " +
271-
"`metadata/annotations.yaml` to ensure that the index image will be generated " +
278+
"%s or provide compatible version(s) by using the %s annotation in "+
279+
"`metadata/annotations.yaml` to ensure that the index image will be generated "+
272280
"with its label. (e.g. LABEL %s='4.6-4.8')",
273281
indexRange,
274282
ocpVerV1beta1Unsupported,
@@ -287,12 +295,12 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
287295
}
288296

289297
if verParsed.GE(semVerOCPV1beta1Unsupported) {
290-
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were " +
291-
"deprecated and removed in v1.22. " +
292-
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
298+
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were "+
299+
"deprecated and removed in v1.22. "+
300+
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+
293301
"Upgrade the APIs from "+
294-
"for %s or provide compatible distribution version(s) by using the %s " +
295-
"annotation in `metadata/annotations.yaml` to ensure that the index image will " +
302+
"for %s or provide compatible distribution version(s) by using the %s "+
303+
"annotation in `metadata/annotations.yaml` to ensure that the index image will "+
296304
"be generated with its label. (e.g. LABEL %s='4.6-4.8')",
297305
deprecatedAPImsg,
298306
ocpLabelindex,
@@ -310,8 +318,8 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
310318
}
311319
}
312320
} else {
313-
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were deprecated and " +
314-
"removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
321+
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were deprecated and "+
322+
"removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+
315323
"Migrate the APIs "+
316324
"for %s or provide compatible version(s) via the labels. (e.g. LABEL %s='4.6-4.8')",
317325
deprecatedAPImsg,

staging/api/pkg/validation/internal/community_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ func Test_communityValidator(t *testing.T) {
104104
"This bundle is using APIs which were deprecated and removed in v1.22. " +
105105
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22 "},
106106
},
107+
{
108+
name: "should warn on patch version in maxOpenShiftVersion",
109+
wantWarning: true,
110+
args: args{
111+
bundleDir: "./testdata/valid_bundle_v1beta1",
112+
imageIndexPath: "./testdata/dockerfile/valid_bundle.Dockerfile",
113+
annotations: map[string]string{
114+
"olm.properties": fmt.Sprintf(`[{"type": "olm.maxOpenShiftVersion", "value": "4.8.1"}]`),
115+
},
116+
},
117+
warnStrings: []string{
118+
"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",
119+
},
120+
},
107121
}
108122

109123
for _, tt := range tests {

vendor/github.com/operator-framework/api/pkg/validation/internal/community.go

Lines changed: 25 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)