Skip to content

Commit 337546f

Browse files
community-validator: improve msgs raised (#124)
1 parent 083a907 commit 337546f

File tree

4 files changed

+50
-35
lines changed

4 files changed

+50
-35
lines changed

pkg/validation/internal/community.go

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func communityValidator(objs ...interface{}) (results []errors.ManifestResult) {
5555
type CommunityOperatorChecks struct {
5656
bundle manifests.Bundle
5757
indexImagePath string
58-
indexImage string
5958
errs []error
6059
warns []error
6160
}
@@ -108,12 +107,11 @@ func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResou
108107
if len(properties) == 0 {
109108
checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations not specified %s for an "+
110109
"OCP version < %s. This annotation is required to prevent the user from upgrading their OCP cluster "+
111-
"before they have installed a version of their operator which is compatible with %s. This bundle is %s which are no "+
110+
"before they have installed a version of their operator which is compatible with %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 which are no "+
112111
"longer supported on %s. Migrate the API(s) for %s or use the annotation",
113112
olmmaxOpenShiftVersion,
114113
ocpVerV1beta1Unsupported,
115114
ocpVerV1beta1Unsupported,
116-
k8sApiDeprecatedInfo,
117115
ocpVerV1beta1Unsupported,
118116
v1beta1MsgForResourcesFound))
119117
return checks
@@ -141,11 +139,10 @@ func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResou
141139
if !hasOlmMaxOpenShiftVersion {
142140
checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations.%s with the "+
143141
"key `%s` and a value with an OCP version which is < %s is required for any operator "+
144-
"bundle that is %s. Migrate the API(s) for %s or use the annotation",
142+
"bundle that 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 use the annotation",
145143
olmproperties,
146144
olmmaxOpenShiftVersion,
147145
ocpVerV1beta1Unsupported,
148-
k8sApiDeprecatedInfo,
149146
v1beta1MsgForResourcesFound))
150147
return checks
151148
}
@@ -160,14 +157,13 @@ func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResou
160157

161158
if semVerVersionMaxOcp.GE(semVerOCPV1beta1Unsupported) {
162159
checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations.%s with the "+
163-
"key and value for %s has the OCP version value %s which is >= of %s. This bundle is %s. "+
160+
"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. "+
164161
"Migrate the API(s) for %s "+
165162
"or inform in this property an OCP version which is < %s",
166163
olmproperties,
167164
olmmaxOpenShiftVersion,
168165
olmMaxOpenShiftVersionValue,
169166
ocpVerV1beta1Unsupported,
170-
k8sApiDeprecatedInfo,
171167
v1beta1MsgForResourcesFound,
172168
ocpVerV1beta1Unsupported))
173169
return checks
@@ -179,15 +175,14 @@ func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResou
179175
// checkOCPLabels will ensure that OCP labels are set and with a ocp target < 4.9
180176
func checkOCPLabelsWithHasDeprecatedAPIs(checks CommunityOperatorChecks, deprecatedAPImsg string) CommunityOperatorChecks {
181177
// Note that we cannot make mandatory because the package format still valid
182-
if len(checks.indexImagePath) == 0 && len(checks.indexImage) == 0 {
178+
if len(checks.indexImagePath) == 0 {
183179
checks.warns = append(checks.errs, fmt.Errorf("please, inform the path of "+
184180
"its index image file via the the optional key values and the key %s to allow this validator check the labels "+
185181
"configuration or migrate the API(s) for %s. "+
186-
"(e.g. %s=./mypath/bundle.Dockerfile). This bundle is %s ",
182+
"(e.g. %s=./mypath/bundle.Dockerfile). 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 ",
187183
IndexImagePathKey,
188184
deprecatedAPImsg,
189-
IndexImagePathKey,
190-
k8sApiDeprecatedInfo))
185+
IndexImagePathKey))
191186
return checks
192187
}
193188

@@ -229,11 +224,8 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
229224
for i := 0; i < len(line); i++ {
230225
if strings.Contains(line[i], ocpLabelindex) {
231226
if !strings.Contains(line[i], "=") {
232-
checks.errs = append(checks.errs, fmt.Errorf("invalid syntax (%s) on the LABEL %s. Migrate the API(s) "+
233-
"for %s or use the OCP labels. (e.g. LABEL %s='4.6-4.8')",
227+
checks.errs = append(checks.errs, fmt.Errorf("invalid syntax (%s) for (%s)",
234228
line[i],
235-
deprecatedAPImsg,
236-
ocpLabelindex,
237229
ocpLabelindex))
238230
return checks
239231
}
@@ -256,23 +248,32 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
256248
}
257249

258250
if verParsed.GE(semVerOCPV1beta1Unsupported) {
259-
checks.errs = append(checks.errs, fmt.Errorf("this bundle is %s. Migrate the API(s) "+
260-
"for %s or use the OCP labels for compatible version(s). (e.g. LABEL %s='=v4.8')",
261-
k8sApiDeprecatedInfo,
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. " +
254+
"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 " +
257+
"with its label. (e.g. LABEL %s='4.6-4.8')",
262258
deprecatedAPImsg,
259+
ocpLabelindex,
263260
ocpLabelindex))
264261
return checks
265262
}
266263
} else {
267264
// if not has not the = then the value needs contains - value less < 4.9
268265
if !strings.Contains(indexRange, "-") {
269-
checks.errs = append(checks.errs, fmt.Errorf("this bundle is %s. "+
266+
checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were " +
267+
"deprecated and removed in v1.22. " +
268+
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22 "+
270269
"The %s allows to distribute it on >= %s. Migrate the API(s) for "+
271-
"%s or provide comatible version(s) via the labels. (e.g. LABEL %s='4.6-4.8')",
272-
deprecatedAPImsg,
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 " +
272+
"with its label. (e.g. LABEL %s='4.6-4.8')",
273273
indexRange,
274274
ocpVerV1beta1Unsupported,
275275
deprecatedAPImsg,
276+
ocpLabelindex,
276277
ocpLabelindex))
277278
return checks
278279
}
@@ -286,10 +287,15 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
286287
}
287288

288289
if verParsed.GE(semVerOCPV1beta1Unsupported) {
289-
checks.errs = append(checks.errs, fmt.Errorf("this bundle is %s. Upgrade the APIs from "+
290-
"(v1beta1) to (v1) for %s or provide com[atible version(s) via the labels. (e.g. LABEL %s='4.6-4.8')",
291-
k8sApiDeprecatedInfo,
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. " +
293+
"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 " +
296+
"be generated with its label. (e.g. LABEL %s='4.6-4.8')",
292297
deprecatedAPImsg,
298+
ocpLabelindex,
293299
ocpLabelindex))
294300
return checks
295301
}
@@ -304,9 +310,10 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
304310
}
305311
}
306312
} else {
307-
checks.errs = append(checks.errs, fmt.Errorf("this bundle is %s. Migrate the APIs "+
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. " +
315+
"Migrate the APIs "+
308316
"for %s or provide compatible version(s) via the labels. (e.g. LABEL %s='4.6-4.8')",
309-
k8sApiDeprecatedInfo,
310317
deprecatedAPImsg,
311318
ocpLabelindex))
312319
return checks

pkg/validation/internal/operatorhub.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,11 @@ func validateHubDeprecatedAPIS(bundle *manifests.Bundle, versionProvided string)
212212
semverMinKube.GE(semVerK8sVerV1betav1Unsupported)
213213
// We only raise an error when the version >= 1.22 was informed via
214214
// the k8s key/value option or is specifically defined in the CSV
215+
msg := 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", deprecatedAPIsMessage)
215216
if isUnsupported {
216-
errs = append(errs, fmt.Errorf("this bundle is %s. Migrate the API(s) for %s", k8sApiDeprecatedInfo, deprecatedAPIsMessage))
217+
errs = append(errs, msg)
217218
} else {
218-
warns = append(warns, fmt.Errorf("this bundle is %s. Migrate the API(s) for %s", k8sApiDeprecatedInfo, deprecatedAPIsMessage))
219+
warns = append(warns, msg)
219220
}
220221
}
221222
}

pkg/validation/internal/operatorhub_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ func TestValidateHubDeprecatedAPIS(t *testing.T) {
375375
directory: "./testdata/valid_bundle_v1beta1",
376376
},
377377
wantWarning: true,
378-
warnStrings: []string{"this bundle is " + k8sApiDeprecatedInfo + ". Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"])"},
378+
warnStrings: []string{"this bundle is using APIs which were deprecated and removed in v1.22. " +
379+
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
380+
"Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" " +
381+
"\"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"])"},
379382
},
380383
{
381384
name: "should not return a warning or error when has minKubeVersion but the k8sVersion informed is <= 1.15",
@@ -395,7 +398,10 @@ func TestValidateHubDeprecatedAPIS(t *testing.T) {
395398
directory: "./testdata/valid_bundle_v1beta1",
396399
},
397400
wantError: true,
398-
errStrings: []string{"this bundle is " + k8sApiDeprecatedInfo + ". Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"])"},
401+
errStrings: []string{"this bundle is using APIs which were deprecated and removed in v1.22. " +
402+
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
403+
"Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\"" +
404+
" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"])"},
399405
wantWarning: true,
400406
warnStrings: []string{"checking APIs against Kubernetes version : 1.22"},
401407
},
@@ -417,8 +423,12 @@ func TestValidateHubDeprecatedAPIS(t *testing.T) {
417423
},
418424
wantError: true,
419425
wantWarning: true,
420-
errStrings: []string{"unable to use csv.Spec.MinKubeVersion to verify the CRD/Webhook apis because it has an invalid value: invalid"},
421-
warnStrings: []string{"this bundle is " + k8sApiDeprecatedInfo + ". Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"])"},
426+
errStrings: []string{"unable to use csv.Spec.MinKubeVersion to verify the CRD/Webhook apis because it " +
427+
"has an invalid value: invalid"},
428+
warnStrings: []string{"this bundle is using APIs which were deprecated and removed in v1.22. " +
429+
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
430+
"Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" " +
431+
"\"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"])"},
422432
},
423433
}
424434
for _, tt := range tests {

pkg/validation/internal/removed_apis.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
88
)
99

10-
// k8sApiDeprecatedInfo define the message which will appears by default when is possible to identify that the project has deprecated API(s)
11-
const k8sApiDeprecatedInfo = "using APIs which were deprecated and removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22"
12-
1310
// OCP version where the apis v1beta1 is no longer supported
1411
const ocpVerV1beta1Unsupported = "4.9"
1512

0 commit comments

Comments
 (0)