Kazan v0.9.0 Kazan.Watcher View Source
Watches for changes on a resource. This works by creating a HTTPoison ASync request. The request will eventually timeout, however the Watcher handles recreating the request when this occurs and requesting new events that have occurred since the last resource_version received.
To use:
- Create a request in the normal way that supports the
watch
parameter. Alternatively create a watch request.
request = Kazan.Apis.Core.V1.list_namespace!() # No need to add watch: true
or
request = Kazan.Apis.Core.V1.watch_namespace_list!()
- Start a watcher using the request, and passing the initial resource version and a pid to which to send received messages.
Kazan.Watcher.start_link(request, resource_version: rv, send_to: self())
If no resource_version
is passed then the watcher initially makes a normal
request to get the starting value. This will only work if a non watch
request
is used. i.e. Kazan.Apis.Core.V1.list_namespace!()
rather than Kazan.Apis.Core.V1.watch_namespace_list!()
- In your client code you receive messages for each
%WatchEvent{}
. You can pattern match on the object type if you have multiple watchers configured. For example, if the client is aGenServer
alias Kazan.Models.Apimachinery.Meta.V1.WatchEvent
# type is "ADDED", "DELETED" or "MODIFIED"
def handle_info(%WatchEvent{object: object, type: type}, state) do
case object do
%Kazan.Apis.Core.V1.Namespace{} = namespace ->
process_namespace_event(type, namespace)
%Kazan.Apis.Batch.V1.Job{} = job ->
process_job_event(type, job)
end
{:noreply, state}
end
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor
Starts a watch request to the kube server
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Starts a watch request to the kube server
The server should be set in the kazan config or provided in the options.
Options
send_to
- Apid
to which events are sent. Defaults toself()
.resource_version
- The version from which to start watching.name
- An optional name for the watcher. Displayed in logs.debug
- A boolean indicating whether we should log debugging info.- Other options are passed directly to
Kazan.Client.run/2