Skip to content

add SecretListWatchSelector to reduce memory and CPU footprint - #3355

Merged
brancz merged 2 commits into
prometheus-operator:masterfrom
Sayrus:master
Jul 24, 2020
Merged

brancz merged 2 commits into
prometheus-operator:masterfrom
Sayrus:master

Conversation

@Sayrus

@Sayrus Sayrus commented Jul 23, 2020 •

Copy link
Copy Markdown
Contributor

Fixes #3298

Supersedes #3299

This PR allows us to set a field selector. This follows the discussion about not wanting an opinionated selector in the code. With this option we can both exclude:

--secret-field-selector='type!=helm.sh/release.v1'

and select:

--secret-field-selector='type=prometheus.io/whatever-we-want'

Because this is a field selector, we can chain the selectors using ,.
The only restriction is that you can't use an OR operator here.

Moreover, the default value (empty string) is equivalent to fields.Everything so this is not a breaking change !

⚠️ Note, some errors may come from the WatchList if the Field Selector is valid but refused by the Kube API (for instance: field label is not supported)
While they are properly reported, it seems that the Prometheus Operator is still considered "healthy".

@brancz

brancz commented Jul 24, 2020

Copy link
Copy Markdown
Contributor

Awesome! Thank you!

@brancz
brancz merged commit ad3571f into prometheus-operator:master Jul 24, 2020
Sayrus added a commit to Sayrus/charts that referenced this pull request Jul 24, 2020
Following prometheus-operator/prometheus-operator#3355, add support for this new
option. This should be released in v0.41.0.
Sayrus added a commit to Sayrus/charts that referenced this pull request Jul 24, 2020
Following prometheus-operator/prometheus-operator#3355, add support for this new
option. This should be released in v0.41.0.

Signed-off-by: Mathis Raguin <[email protected]>
@matthyx

matthyx commented Nov 2, 2020

Copy link
Copy Markdown

⚠️ Note, some errors may come from the WatchList if the Field Selector is valid but refused by the Kube API (for instance: field label is not supported)

@brancz does it mean it's expected to see such errors in the logs:

E1102 14:10:47.388291       1 reflector.go:178] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:125: Failed to list *v1.Secret: field label not supported: "type
E1102 14:11:40.082751       1 reflector.go:178] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:125: Failed to list *v1.Secret: field label not supported: "type

I am trying to filter out secrets of type dockercfg with the setting:
- '--secret-field-selector="type!=kubernetes.io/dockercfg"'

@matthyx

matthyx commented Nov 4, 2020

Copy link
Copy Markdown

I am trying to filter out secrets of type dockercfg with the setting:
- '--secret-field-selector="type!=kubernetes.io/dockercfg"'

Note on that issue... it has been solved by removing the quotes using scalar block chomping:

            - >-
              --secret-field-selector=type!=kubernetes.io/dockercfg

@Sayrus

Sayrus commented Nov 4, 2020 •

Copy link
Copy Markdown
Contributor Author

I am trying to filter out secrets of type dockercfg with the setting:
- '--secret-field-selector="type!=kubernetes.io/dockercfg"'

Note on that issue... it has been solved by removing the quotes using scalar block chomping:

            - >-
              --secret-field-selector=type!=kubernetes.io/dockercfg

Now you make me doubt my own implementation 😨
Does - --secret-field-selector='type!=kubernetes.io/dockercfg' work? (Not using double quotes and only single quoting the value).

Note that the error I was talking about is not related to what you had where it says "type. The parsing failed as you still have a double quote in your value. The error I talked about occurs when you try to filter using a field that is not usable in field selectors. Removing the quotes would not help as it would still be the same field.
You get the same error because the misquoted field is an unknown field, which means it also is an unsupported field label.

@matthyx

matthyx commented Nov 4, 2020

Copy link
Copy Markdown

Single quote doesn't work as well...
E1104 12:46:58.570454 1 reflector.go:178] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:125: Failed to list *v1.Secret: field label not supported: 'type

@matthyx

matthyx commented Nov 4, 2020

Copy link
Copy Markdown

Filtering with type works, so it's clearly a flag parsing issue...

@Sayrus

Sayrus commented Nov 4, 2020 •

Copy link
Copy Markdown
Contributor Author

Then this means that your variables are already quoted, see the following:

$ go run test.go --var='test'
var: test
$ go run test.go "--var='test'"
var: 'test'

(And the shell would remove the quotes)

How do you execute the Prometheus-Operator?

@matthyx

matthyx commented Nov 4, 2020

Copy link
Copy Markdown

As a Kubernetes deployment... but it's not the only argument:

    - args:
        - '--kubelet-service=kube-system/kubelet'
        - '--logtostderr=true'
        - '--prometheus-instance-selector=prometheus=lo'
        - '--alertmanager-instance-selector=prometheus=lo'
        - >-
          --secret-field-selector=type!=kubernetes.io/dockercfg,type!=kubernetes.io/service-account-token

I think quotes are inherited by the yaml handling...

@Sayrus

Sayrus commented Nov 4, 2020

Copy link
Copy Markdown
Contributor Author

Sounds like you should be able to use unquoted values as long as they are valid YAML. Thanks for documenting the issue and providing a workaround.

simonpasquier

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prometheus Operator watching every secret leads to high memory usage

4 participants