@@ -415,13 +415,13 @@ func (g *DataGathererDynamic) Fetch() (any, int, error) {
415415
416416 // filter by labels
417417 labels := resource .GetLabels ()
418- if ! matchesLabelFilter (labels , g .includeLabels , g .excludeLabels ) {
418+ if ! matchesFilter (labels , g .includeLabels , g .excludeLabels ) {
419419 continue
420420 }
421421
422422 // filter by annotations
423423 annotations := resource .GetAnnotations ()
424- if ! matchesAnnotationFilter (annotations , g .includeAnnotations , g .excludeAnnotations ) {
424+ if ! matchesFilter (annotations , g .includeAnnotations , g .excludeAnnotations ) {
425425 continue
426426 }
427427
@@ -619,15 +619,15 @@ func isIncludedNamespace(namespace string, namespaces []string) bool {
619619 return slices .Contains (namespaces , namespace )
620620}
621621
622- // matchesLabelFilter checks if the resource labels match the include/exclude filters.
623- // If includeLabels is set, all key-value pairs must match for the resource to be included.
622+ // matchesFilter checks if the resource metadata ( labels or annotations) match the include/exclude filters.
623+ // If includeFilters is set, all key-value pairs must match for the resource to be included.
624624// An empty string value means "match any value for this key" (key-only matching).
625- // If excludeLabels is set, any matching key-value pair will exclude the resource.
626- func matchesLabelFilter ( resourceLabels , includeLabels , excludeLabels map [string ]string ) bool {
627- // Check exclude labels first
628- if len (excludeLabels ) > 0 {
629- for key , value := range excludeLabels {
630- if resourceValue , exists := resourceLabels [key ]; exists {
625+ // If excludeFilters is set, any matching key-value pair will exclude the resource.
626+ func matchesFilter ( resourceMetadata , includeFilters , excludeFilters map [string ]string ) bool {
627+ // Check exclude filters first
628+ if len (excludeFilters ) > 0 {
629+ for key , value := range excludeFilters {
630+ if resourceValue , exists := resourceMetadata [key ]; exists {
631631 // If exclude value is empty, exclude any resource with this key
632632 // Otherwise, only exclude if the value also matches
633633 if value == "" || resourceValue == value {
@@ -637,49 +637,12 @@ func matchesLabelFilter(resourceLabels, includeLabels, excludeLabels map[string]
637637 }
638638 }
639639
640- // Check include labels
641- if len (includeLabels ) > 0 {
642- for key , value := range includeLabels {
643- resourceValue , exists := resourceLabels [key ]
640+ // Check include filters
641+ if len (includeFilters ) > 0 {
642+ for key , value := range includeFilters {
643+ resourceValue , exists := resourceMetadata [key ]
644644 if ! exists {
645- // Required label key is missing, filter it out
646- return false
647- }
648- // If include value is empty, we only care that the key exists
649- // Otherwise, the value must also match
650- if value != "" && resourceValue != value {
651- return false
652- }
653- }
654- }
655-
656- return true
657- }
658-
659- // matchesAnnotationFilter checks if the resource annotations match the include/exclude filters.
660- // If includeAnnotations is set, all key-value pairs must match for the resource to be included.
661- // An empty string value means "match any value for this key" (key-only matching).
662- // If excludeAnnotations is set, any matching key-value pair will exclude the resource.
663- func matchesAnnotationFilter (resourceAnnotations , includeAnnotations , excludeAnnotations map [string ]string ) bool {
664- // Check exclude annotations first
665- if len (excludeAnnotations ) > 0 {
666- for key , value := range excludeAnnotations {
667- if resourceValue , exists := resourceAnnotations [key ]; exists {
668- // If exclude value is empty, exclude any resource with this key
669- // Otherwise, only exclude if the value also matches
670- if value == "" || resourceValue == value {
671- return false
672- }
673- }
674- }
675- }
676-
677- // Check include annotations
678- if len (includeAnnotations ) > 0 {
679- for key , value := range includeAnnotations {
680- resourceValue , exists := resourceAnnotations [key ]
681- if ! exists {
682- // Required annotation key is missing, filter it out
645+ // Required key is missing, filter it out
683646 return false
684647 }
685648 // If include value is empty, we only care that the key exists
0 commit comments