@@ -375,14 +375,24 @@ func FilterList(list client.ObjectList, f func(obj client.Object) bool) error {
375375 return SetList (list , filtered )
376376}
377377
378+ type ObjectLabels interface {
379+ GetLabels () map [string ]string
380+ SetLabels (labels map [string ]string )
381+ }
382+
383+ type ObjectAnnotations interface {
384+ GetAnnotations () map [string ]string
385+ SetAnnotations (annotations map [string ]string )
386+ }
387+
378388// HasLabel checks if the object has a label with the given key.
379- func HasLabel (obj metav1. Object , key string ) bool {
389+ func HasLabel (obj ObjectLabels , key string ) bool {
380390 _ , ok := obj .GetLabels ()[key ]
381391 return ok
382392}
383393
384394// SetLabel sets the given label on the object.
385- func SetLabel (obj metav1. Object , key , value string ) {
395+ func SetLabel (obj ObjectLabels , key , value string ) {
386396 labels := obj .GetLabels ()
387397 if labels == nil {
388398 labels = make (map [string ]string )
@@ -393,7 +403,7 @@ func SetLabel(obj metav1.Object, key, value string) {
393403}
394404
395405// SetLabels sets the given labels on the object.
396- func SetLabels (obj metav1. Object , set map [string ]string ) {
406+ func SetLabels (obj ObjectLabels , set map [string ]string ) {
397407 labels := obj .GetLabels ()
398408 if labels == nil {
399409 labels = set
@@ -406,14 +416,14 @@ func SetLabels(obj metav1.Object, set map[string]string) {
406416}
407417
408418// DeleteLabel deletes the label with the given key from the object.
409- func DeleteLabel (obj metav1. Object , key string ) {
419+ func DeleteLabel (obj ObjectLabels , key string ) {
410420 labels := obj .GetLabels ()
411421 delete (labels , key )
412422 obj .SetLabels (labels )
413423}
414424
415425// DeleteLabels deletes the labels with the given keys from the object.
416- func DeleteLabels (obj metav1. Object , keys []string ) {
426+ func DeleteLabels (obj ObjectLabels , keys []string ) {
417427 labels := obj .GetLabels ()
418428 if len (labels ) == 0 {
419429 return
@@ -425,13 +435,13 @@ func DeleteLabels(obj metav1.Object, keys []string) {
425435}
426436
427437// HasAnnotation checks if the object has an annotation with the given key.
428- func HasAnnotation (obj metav1. Object , key string ) bool {
438+ func HasAnnotation (obj ObjectAnnotations , key string ) bool {
429439 _ , ok := obj .GetAnnotations ()[key ]
430440 return ok
431441}
432442
433443// SetAnnotation sets the given annotation on the object.
434- func SetAnnotation (obj metav1. Object , key , value string ) {
444+ func SetAnnotation (obj ObjectAnnotations , key , value string ) {
435445 annotations := obj .GetAnnotations ()
436446 if annotations == nil {
437447 annotations = make (map [string ]string )
@@ -442,7 +452,7 @@ func SetAnnotation(obj metav1.Object, key, value string) {
442452}
443453
444454// SetAnnotations sets the given annotations on the object.
445- func SetAnnotations (obj metav1. Object , set map [string ]string ) {
455+ func SetAnnotations (obj ObjectAnnotations , set map [string ]string ) {
446456 annotations := obj .GetAnnotations ()
447457 if annotations == nil {
448458 annotations = set
@@ -455,14 +465,14 @@ func SetAnnotations(obj metav1.Object, set map[string]string) {
455465}
456466
457467// DeleteAnnotation deletes the annotation with the given key from the object.
458- func DeleteAnnotation (obj metav1. Object , key string ) {
468+ func DeleteAnnotation (obj ObjectAnnotations , key string ) {
459469 annotations := obj .GetAnnotations ()
460470 delete (annotations , key )
461471 obj .SetAnnotations (annotations )
462472}
463473
464474// DeleteAnnotations deletes the annotations with the given keys from the object.
465- func DeleteAnnotations (obj metav1. Object , keys []string ) {
475+ func DeleteAnnotations (obj ObjectAnnotations , keys []string ) {
466476 annotations := obj .GetAnnotations ()
467477 if len (annotations ) == 0 {
468478 return
0 commit comments