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

Add flag to http client to allow for the client to be dryrun #43

Merged
merged 1 commit into from Sep 6, 2019

Conversation

lukemassa
Copy link

@lukemassa lukemassa commented Sep 5, 2019

This allows you to create an http client that will only make dry run requests. (https://kubernetes.io/blog/2019/01/14/apiserver-dry-run-and-kubectl-diff/)

>>> import pykube
>>> pod = {'apiVersion': 'v1', 'kind': 'Pod', 'metadata': {'name': 'lmassa-test', 'namespace': 'node-maintenance-api'}, 'spec': {'containers': [{'name': 'uname', 'image': 'alpine', 'command': ['sleep', '10000000']}]}}
>>> api_real = pykube.HTTPClient(pykube.KubeConfig.from_file("config"), dry_run=False)
>>> api_dryrun = pykube.HTTPClient(pykube.KubeConfig.from_file("config"), dry_run=True)
>>> 
>>> pykube.Pod(api_dryrun, pod).exists()
False
>>> pykube.Pod(api_dryrun, pod).create()
>>> pykube.Pod(api_dryrun, pod).exists()
False
>>> pykube.Pod(api_real, pod).create()
>>> pykube.Pod(api_real, pod).exists()
True

@lukemassa
Copy link
Author

Looks like coverage dropped, I'll see if I can add a test

@lukemassa lukemassa changed the title Add flag to http client to allow for the client to be dryrun (wip) Add flag to http client to allow for the client to be dryrun Sep 5, 2019
@hjacobs
Copy link
Owner

hjacobs commented Sep 6, 2019

Thanks for the contribution!

@lukemassa lukemassa changed the title (wip) Add flag to http client to allow for the client to be dryrun Add flag to http client to allow for the client to be dryrun Sep 6, 2019
@lukemassa
Copy link
Author

Removing WIP now that I got tests passing

@hjacobs
Copy link
Owner

hjacobs commented Sep 6, 2019

Thanks! Just one tiny request: can you change the keyword argument to dry_run? This would be more consistent with the Kubernetes parameter (camelCase "dryRun" -> snake_case "dry_run")

@lukemassa
Copy link
Author

@hjacobs updated!

@hjacobs hjacobs merged commit ab9c27e into hjacobs:master Sep 6, 2019
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.

None yet

2 participants