@@ -39,6 +39,8 @@ type ConfigDynamic struct {
39
39
ExcludeNamespaces []string `yaml:"exclude-namespaces"`
40
40
// IncludeNamespaces is a list of namespaces to include.
41
41
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"`
42
44
}
43
45
44
46
// UnmarshalYAML unmarshals the ConfigDynamic resolving GroupVersionResource.
@@ -52,6 +54,7 @@ func (c *ConfigDynamic) UnmarshalYAML(unmarshal func(interface{}) error) error {
52
54
} `yaml:"resource-type"`
53
55
ExcludeNamespaces []string `yaml:"exclude-namespaces"`
54
56
IncludeNamespaces []string `yaml:"include-namespaces"`
57
+ FieldSelectors []string `yaml:"field-selectors"`
55
58
}{}
56
59
err := unmarshal (& aux )
57
60
if err != nil {
@@ -64,6 +67,7 @@ func (c *ConfigDynamic) UnmarshalYAML(unmarshal func(interface{}) error) error {
64
67
c .GroupVersionResource .Resource = aux .ResourceType .Resource
65
68
c .ExcludeNamespaces = aux .ExcludeNamespaces
66
69
c .IncludeNamespaces = aux .IncludeNamespaces
70
+ c .FieldSelectors = aux .FieldSelectors
67
71
68
72
return nil
69
73
}
@@ -79,6 +83,13 @@ func (c *ConfigDynamic) validate() error {
79
83
errors = append (errors , "invalid configuration: GroupVersionResource.Resource cannot be empty" )
80
84
}
81
85
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
+
82
93
if len (errors ) > 0 {
83
94
return fmt .Errorf (strings .Join (errors , ", " ))
84
95
}
@@ -151,26 +162,10 @@ func (c *ConfigDynamic) newDataGathererWithClient(ctx context.Context, cl dynami
151
162
}
152
163
// init shared informer for selected namespaces
153
164
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 ))
174
169
}
175
170
176
171
// init cache to store gathered resources
0 commit comments