@@ -39,6 +39,8 @@ type ConfigDynamic struct {
3939 ExcludeNamespaces []string `yaml:"exclude-namespaces"`
4040 // IncludeNamespaces is a list of namespaces to include.
4141 IncludeNamespaces []string `yaml:"include-namespaces"`
42+ // FieldSelectors is a list of field selectors to use when listing this resource
43+ FieldSelectors []string `yaml:"field-selectors"`
4244}
4345
4446// UnmarshalYAML unmarshals the ConfigDynamic resolving GroupVersionResource.
@@ -52,6 +54,7 @@ func (c *ConfigDynamic) UnmarshalYAML(unmarshal func(interface{}) error) error {
5254 } `yaml:"resource-type"`
5355 ExcludeNamespaces []string `yaml:"exclude-namespaces"`
5456 IncludeNamespaces []string `yaml:"include-namespaces"`
57+ FieldSelectors []string `yaml:"field-selectors"`
5558 }{}
5659 err := unmarshal (& aux )
5760 if err != nil {
@@ -64,6 +67,7 @@ func (c *ConfigDynamic) UnmarshalYAML(unmarshal func(interface{}) error) error {
6467 c .GroupVersionResource .Resource = aux .ResourceType .Resource
6568 c .ExcludeNamespaces = aux .ExcludeNamespaces
6669 c .IncludeNamespaces = aux .IncludeNamespaces
70+ c .FieldSelectors = aux .FieldSelectors
6771
6872 return nil
6973}
@@ -79,6 +83,13 @@ func (c *ConfigDynamic) validate() error {
7983 errors = append (errors , "invalid configuration: GroupVersionResource.Resource cannot be empty" )
8084 }
8185
86+ for _ , selectorString := range c .FieldSelectors {
87+ _ , err := fields .ParseSelector (selectorString )
88+ if err != nil {
89+ errors = append (errors , fmt .Sprintf ("invalid field selector %q: %s" , selectorString , err ))
90+ }
91+ }
92+
8293 if len (errors ) > 0 {
8394 return fmt .Errorf (strings .Join (errors , ", " ))
8495 }
@@ -151,26 +162,10 @@ func (c *ConfigDynamic) newDataGathererWithClient(ctx context.Context, cl dynami
151162 }
152163 // init shared informer for selected namespaces
153164 fieldSelector := generateFieldSelector (c .ExcludeNamespaces )
154- // Reduce the memory usage and reduce the load on the Kubernetes API server
155- // by omitting various common Secret types when listing Secrets.
156- // * https://kubernetes.io/docs/concepts/configuration/secret/#secret-types
157- //
158- // It would be better to include only TLS and Opaque Secrets rather than excluding the other types,
159- // because we can never know all the possible Secret types that a cluster may have,
160- // but field selectors do not yet support set based operators:
161- // * https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/#supported-operators
162- // * https://github.com/kubernetes/kubernetes/issues/32946
163- if c .GroupVersionResource .Group == "" && c .GroupVersionResource .Version == "v1" && c .GroupVersionResource .Resource == "secrets" {
164- fieldSelector = fields .AndSelectors (
165- fieldSelector ,
166- fields .OneTermNotEqualSelector ("type" , "kubernetes.io/service-account-token" ),
167- fields .OneTermNotEqualSelector ("type" , "kubernetes.io/dockercfg" ),
168- fields .OneTermNotEqualSelector ("type" , "kubernetes.io/dockerconfigjson" ),
169- fields .OneTermNotEqualSelector ("type" , "kubernetes.io/basic-auth" ),
170- fields .OneTermNotEqualSelector ("type" , "kubernetes.io/ssh-auth" ),
171- fields .OneTermNotEqualSelector ("type" , "bootstrap.kubernetes.io/token" ),
172- fields .OneTermNotEqualSelector ("type" , "helm.sh/release.v1" ),
173- )
165+
166+ // add any custom field selectors to the namespace selector
167+ for _ , selectorString := range c .FieldSelectors {
168+ fieldSelector = fields .AndSelectors (fieldSelector , fields .ParseSelectorOrDie (selectorString ))
174169 }
175170
176171 // init cache to store gathered resources
0 commit comments