How to watch a Pod api endpoint in a Kubernetes Operator using the SDK

3/13/2019

Description

I have a CR associated with a POD with a container that is exposing an API, eg:

/available

returning for example

{"available":"true"}

Is there a way to create a controller watcher on that API call that whenever the response changes will trigger the reconcile function? I believe it could be possible using a channel with the controller watcher, but I don't see any similar examples out there

Using

Kubernetes operator-sdk version v0.5.0+git

-- MarMan
kubernetes

1 Answer

5/14/2019

I'm afraid it's not as easy as you hope. The Kubernetes controller objects react to add/edit/delete operations of some kind of resource in the cluster. A value exposed inside an API of something running inside the Pod is not visible in the resource database. There is not event going off, notifying about the change either.

I see two things you can consider doing:

  1. Create a regular controller that would have the reconcile function triggered fairly often, but would check the availability value inside it's reconcile function. If it changed, it would do something, if it didn't it would do nothing.
  2. Just create a separate task, outside the controller domain, that would monitor this API value and do something.

Controllers work using notifications, they don't actively watch for changes, they are notified about them. That's different than what you want to do - periodically check the API response.

-- Maciek
Source: StackOverflow