Adding custom Webhooks to Kubernetes GO Operator

8/24/2020

I am doing a POC around the kubernetes Go Operator to perform some asynchronous actions in an application, and I expect to get a callback from a python application into the Operator, which can then go ahead to update the resource metadata, such as make changes to the Resource status fields.

I know that the controller used by the Kubernetes Go Operator SDK uses an API Server running on a specific port. But can that be used as a custom API server where I can set up paths for the webhook to work on?

Example of an expected callback API:

curl -XPOST http://cyber-operator.svc/application/updateClusterState

I expect to run a procedure inside the operator when this API is called.

I searched the documentation and could not find something relevant. Can I run a separate API Server in the Operator? I am fine if it has to listen to a different port than the in-built controller.

-- Aditya Aggarwal
go
kubernetes
operator-sdk

1 Answer

8/25/2020

operator-sdk doesn't start server, usually it list-watch k8s resources and reconcile, unless you add validating/mutating webhook explicitly (https://github.com/operator-framework/operator-sdk/blob/7e029625dde8f0d4cb88ac914af4deb7f5f85c4a/website/content/en/docs/building-operators/golang/webhooks.md)

Even it's possible, I suggest don't do this, just create a new http server on a new port.

-- jxiewei
Source: StackOverflow