Is your feature request related to a problem? Please describe.
I would like my Ansible operator to watch some resources, for example pods, and I want it to run only on some specific pods, for example pods with some label.
Describe the solution you'd like
I would like to be able to add selectors in watches.yaml to specify selectors of the watched resources, e.g. labels.
@fabianvf would be great have your input here?
Yeah this makes a ton of sense, especially if you've got a cluster-wide watch on something like secrets. If it's already easy to establish a watch with a selector in controller-runtime this would be as simple as adding a field to the ansible Watch struct and passing it through when we establish the watch. Might be a good first issue for someone to pick up
/assign @dmvolod
This isn't as simple as it seems unfortunately. See https://github.com/kubernetes-sigs/controller-runtime/issues/244.
A naive workaround now would be to do the filtering client-side using a predicate. The obvious problem is that if your operator is watching chatty resources cluster-wide, there's going to be a lot of unnecessary traffic.
/unassign @dmvolod
@joelanford that's a shame, though we can at least add the config option and add a predicate that will filter based on the config, which will at least save users from needing to do a full python + ansible initialization before skipping the event. In the future when controller-runtime supports it we can replace the predicate with a more proper implementation.
Looks like this is done.
Most helpful comment
Yeah this makes a ton of sense, especially if you've got a cluster-wide watch on something like secrets. If it's already easy to establish a watch with a selector in controller-runtime this would be as simple as adding a field to the ansible
Watchstruct and passing it through when we establish the watch. Might be a good first issue for someone to pick up