discovery/kubernetes: fix selectors validation for role pod

Signed-off-by: Haley Wang <haley@victoriametrics.com>
This commit is contained in:
Haley Wang 2024-01-18 20:47:59 +08:00
parent 0524b880e7
commit 086fcef42b
No known key found for this signature in database
GPG key ID: C6299A8A1D6CC50C
2 changed files with 8 additions and 2 deletions

View file

@ -7,7 +7,9 @@ scrape_configs:
label: "foo=bar" label: "foo=bar"
field: "metadata.status=Running" field: "metadata.status=Running"
- role: pod - role: pod
attach_metadata:
node: true
selectors: selectors:
- role: "pod" - role: "node"
label: "foo in (bar,baz)" label: "foo=bar"
field: "metadata.status=Running" field: "metadata.status=Running"

View file

@ -222,6 +222,10 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
break break
} }
} }
// The pod role supports node selectors when configured with `attach_metadata: {node: true}`.
if !allowed && selector.Role == RoleNode && c.Role == RolePod && c.AttachMetadata.Node {
allowed = true
}
if !allowed { if !allowed {
return fmt.Errorf("%s role supports only %s selectors", c.Role, strings.Join(allowedSelectors[c.Role], ", ")) return fmt.Errorf("%s role supports only %s selectors", c.Role, strings.Join(allowedSelectors[c.Role], ", "))