@@ -11,6 +11,7 @@ import (
11
11
log "github.com/sirupsen/logrus"
12
12
"gopkg.in/yaml.v2"
13
13
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14
+ utilerrors "k8s.io/apimachinery/pkg/util/errors"
14
15
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
15
16
)
16
17
@@ -274,24 +275,22 @@ func ValidateAnnotations(existing, expected []byte) error {
274
275
return err
275
276
}
276
277
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
282
280
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
286
285
}
287
286
288
287
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 ))
291
290
}
292
291
}
293
292
294
- return nil
293
+ return utilerrors . NewAggregate ( errs )
295
294
}
296
295
297
296
// ValidateChannelDefault validates provided default channel to ensure it exists in
0 commit comments