Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Pass arbitrary params to the watching GET queries #33

Merged
merged 1 commit into from
Jul 12, 2019

Conversation

nolar
Copy link

@nolar nolar commented Jul 11, 2019

GET queries of K8s API can accept some params, which are especially needed for the watching GET-queries. These params are NOT the request body and not the payload, but the execution modes/flags.

For example, for pod-watching: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#watch-64

The set of these params can change over time. To avoid mapping each and every one of them to pykube's codebase (and resolving the camelCase conventions to Python's snake_case), this PR adds params option to watch() call — and passes them directly to the query params.

For example, this script disables the socket timeouts, but asks the server to limit the query to 10s (server-side!). When the time runs out, the query ends normally, without any exceptions.

import pykube

cfg = pykube.KubeConfig.from_file()
api = pykube.HTTPClient(cfg, timeout=None)
stream = pykube.Pod.objects(api).watch(params=dict(timeoutSeconds=10))

for event in stream:
    print(repr(event))

Whether or not such params should be added to other operations (e.g. listing), is a question to discuss. Most of the writing operations (patch, create, replace) only have pretty param, which is useless; however, delete has gracePeriodSeconds and propagationPolicy, which can be of use.

Issue: related #32

@hjacobs
Copy link
Owner

hjacobs commented Jul 12, 2019

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants