Watching K8s core APIs

91 views
Skip to first unread message

Jan Werner

unread,
Sep 17, 2022, 10:01:17 AM9/17/22
to Operator Framework
Hi all,

is there a way to watch arbitrary Kubernetes API resources, i.e. resources that are not CRs or resources managed by the operator?

What I'm trying to achieve is triggering the reconciliation loop if a Node object is changed.

Thanks,
Jan

Varsha Prasad Narsing

unread,
Sep 19, 2022, 1:37:02 PM9/19/22
to Jan Werner, Operator Framework
Hi Jan,

We can watch any external resource while building controllers. To do so, controller-runtime provides we can use the `Watches` method (https://github.com/kubernetes-sigs/controller-runtime/blob/v0.13.0/pkg/builder/controller.go#L127). Here is some relevant documentation around that (https://book.kubebuilder.io/reference/watching-resources.html?highlight=watch#watching-resources). Hope it helps.

Thank you
Varsha

--
You received this message because you are subscribed to the Google Groups "Operator Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to operator-framew...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/operator-framework/4db2f769-f82f-4d36-b2da-460d6463d4e0n%40googlegroups.com.


--
Varsha Prasad
Software Engineer
Operator SDK Team
Red Hat Inc. San Francisco

Jan Werner

unread,
Sep 19, 2022, 2:01:50 PM9/19/22
to Operator Framework
Hi Varsha,

thanks a lot for your feedback. ​This is basically what I'm looking for.​ ​However​ I would like to use this with an Ansible operator​ - sorry for not being more specific initially. I couldn't find anything ​on this topic in the documentation (https://sdk.operatorframework.io/docs/building-operators/ansible/).​ ​I guess this is probably something that is only possible with Go-based Operators?

T​hanks,
Jan

Fabian von Feilitzsch

unread,
Sep 19, 2022, 2:09:49 PM9/19/22
to Jan Werner, Operator Framework
On Mon, Sep 19, 2022 at 12:02 PM 'Jan Werner' via Operator Framework <operator-...@googlegroups.com> wrote:
Hi Varsha,

thanks a lot for your feedback. This is basically what I'm looking for. However I would like to use this with an Ansible operator - sorry for not being more specific initially. I couldn't find anything on this topic in the documentation (https://sdk.operatorframework.io/docs/building-operators/ansible/). I guess this is probably something that is only possible with Go-based Operators?

This should work fine with Ansible-based Operators as well, just add the resource to your `watches.yaml` as normal and make sure `manageStatus` is set to false in the watches entry, since another controller is actually managing the resource.
 

Jan Werner

unread,
Sep 21, 2022, 4:11:25 AM9/21/22
to Operator Framework
You're right, working perfectly. Thanks a lot!
Reply all
Reply to author
Forward
0 new messages