Skip to content

Commit 275301b

Browse files
authoredJun 11, 2020
Merge pull request operator-framework#358 from estroz/bugfix/annotation-compare-validation
pkg/lib/bundle/generate.go: do not compare number of annotations
2 parents b3fdc91 + a434c6f commit 275301b

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed
 

‎pkg/lib/bundle/generate.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
log "github.com/sirupsen/logrus"
1212
"gopkg.in/yaml.v2"
1313
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14+
utilerrors "k8s.io/apimachinery/pkg/util/errors"
1415
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
1516
)
1617

@@ -274,24 +275,22 @@ func ValidateAnnotations(existing, expected []byte) error {
274275
return err
275276
}
276277

277-
if len(fileAnnotations.Annotations) != len(expectedAnnotations.Annotations) {
278-
return fmt.Errorf("Unmatched number of fields. Expected (%d) vs existing (%d)",
279-
len(expectedAnnotations.Annotations), len(fileAnnotations.Annotations))
280-
}
281-
278+
// Ensure each expected annotation key and value exist in existing.
279+
var errs []error
282280
for label, item := range expectedAnnotations.Annotations {
283-
value, ok := fileAnnotations.Annotations[label]
284-
if ok == false {
285-
return fmt.Errorf("Missing field: %s", label)
281+
value, hasAnnotation := fileAnnotations.Annotations[label]
282+
if !hasAnnotation {
283+
errs = append(errs, fmt.Errorf("Missing field: %s", label))
284+
continue
286285
}
287286

288287
if item != value {
289-
return fmt.Errorf(`Expect field "%s" to have value "%s" instead of "%s"`,
290-
label, item, value)
288+
errs = append(errs, fmt.Errorf("Expect field %q to have value %q instead of %q",
289+
label, item, value))
291290
}
292291
}
293292

294-
return nil
293+
return utilerrors.NewAggregate(errs)
295294
}
296295

297296
// ValidateChannelDefault validates provided default channel to ensure it exists in

‎pkg/lib/bundle/generate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestValidateAnnotations(t *testing.T) {
117117
"test1": "stable",
118118
"test2": "stable,beta",
119119
}),
120-
fmt.Errorf("Unmatched number of fields. Expected (2) vs existing (3)"),
120+
nil,
121121
},
122122
{
123123
buildTestAnnotations("annotations",

0 commit comments

Comments
 (0)
Please sign in to comment.