You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That said, I'm running into an issue with how to use the Python client to emulate the behavior from the command line, specifically kubectl create -f <yaml file>
Is there a way that I can accomplish this currently?
Reacted by Alex Hokanson, Tolik Litovsky, Jon Cormier, Daniel van der Ende, Mumshad Mannambeth, Ferdinand Niedermann, Stojan Jović, Mitar, Nakul Pathak, govind somalal and 2 more
I cannot really believe this functionality is not there. So strange.
I think the purpose of kubernetes-client is to give access to APIs in as flexible a way as possible, not duplicate kubectl. Perhaps higher level functionality like this issue describes would make more sense in a separate library that wraps kubernetes-client.
I don't understand the discussion actually. You can create any object with the python client, you just need to find the correct method for it.
what kubectl does is that it adds a bit of parsing to detect the object kind and post on the correct endpoint. You could right a python wrapper that does the same things with this library. But indeed it is available out of the box.
Exactly, there is a bit of this magic: parsing of YAML files, going over each object in them, determining which type it is, and then calling the appropriate create method. This would be great to have here in Python interface.
I created an application with the idea of using a yaml template to specify values that need to be changed, passing directly to the dictionary that was created in the past
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
I'm not sure how different apply and create are (https://stackoverflow.com/questions/47369351/kubectl-apply-vs-kubectl-create this kinda helped..) but do we need a separate PR/issue for something similar to that in the python client? Or is there a way to combine @micw523's PR with some existing methods to get the same behaviour as kubectl apply -f. I'm trying to replace an apply -f call for a ConfigMap type YAML file.
@nakulpathak3 I think using "apply" is a separate feature and could be possibly filed as another issue. Although, I don't think the implementation would be too different from what I have in #655 ...
Please try out #655 (already merged in Master). This functionality is not perfect yet, subject to an existing issue #376 such as when you need to create a CRD, and it is not able to create lists #671. Otherwise please file complaints here and I’ll tend to it.
Apply would require an internal diff and I’ll see if the repo owners are interested in rolling out this function before I test the waters.
Is apply potentially just an upsert in k8s (i.e., if create gives a 409, do an update)? Or can we get partial objects which can't just replace the older versions and need examining of the old object to figure out the internal diff like you mentioned? Sorry not that familiar with kubernetes yet
kubectl apply is more advanced compared to kubectl create, and it's non-trivial to implement on client side.
I'm interested in the Kubernetes server-side apply feature, which has more capability than client-side (kubectl) apply. Hopefully that feature will rollout in 1.13 as alpha and we can try it out using the python client.
The original feature requested by this issue (create -f) has been added. Closing this issue now
kubectl apply is more advanced compared to kubectl create, and it's non-trivial to implement on client side.
I'm interested in the Kubernetes server-side apply feature, which has more capability than client-side (kubectl) apply. Hopefully that feature will rollout in 1.13 as alpha and we can try it out using the python client.
The original feature requested by this issue (create -f) has been added. Closing this issue now
/close
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Just another point of view to complement the discussion, having the Python client execute YAML files enables the versioning of said YAML files, separate from the script code.
That is in itself very useful, at least for me :) It's wasn't about replicating kubectl per se...
Activity
sebgoa commentedon Apr 5, 2018
The easiest is load the yaml file and use it as body to a specific method, see:
https://github.com/kubernetes-client/python/blob/master/examples/create_deployment.py
viveknair commentedon Apr 5, 2018
Ah, I see that makes a lot of sense thanks.
inc0 commentedon Apr 9, 2018
I will bump this issue - any method that would accept raw datastructure rather than create_namespaced_deployment?
My use case is to create multiple resources of different types in same loop. Think of trying example @sebgoa mentioned, but where https://github.com/kubernetes-client/python/blob/master/examples/nginx-deployment.yaml will have more resources (like Namespace or Service)
mmumshad commentedon Sep 20, 2018
+1 I wonder what is beneath the create_namespaced_* calls. Where can we see the source of these calls?
nerdinand commentedon Sep 20, 2018
I think at this point the easiest thing to do is just to use
kubectl. But I'd really like a built-in solution in the API client too...mitar commentedon Oct 12, 2018
I cannot really believe this functionality is not there. So strange.
JonathanRRogers commentedon Oct 13, 2018
I think the purpose of kubernetes-client is to give access to APIs in as flexible a way as possible, not duplicate kubectl. Perhaps higher level functionality like this issue describes would make more sense in a separate library that wraps kubernetes-client.
sebgoa commentedon Oct 13, 2018
I don't understand the discussion actually. You can create any object with the python client, you just need to find the correct method for it.
what
kubectldoes is that it adds a bit of parsing to detect the object kind and post on the correct endpoint. You could right a python wrapper that does the same things with this library. But indeed it is available out of the box.mitar commentedon Oct 14, 2018
Exactly, there is a bit of this magic: parsing of YAML files, going over each object in them, determining which type it is, and then calling the appropriate create method. This would be great to have here in Python interface.
eagle9527 commentedon Oct 15, 2018
I created an application with the idea of using a yaml template to specify values that need to be changed, passing directly to the dictionary that was created in the past
micw523 commentedon Oct 17, 2018
I'll take a crack at it.
roycaihw commentedon Oct 17, 2018
/assign @micw523
k8s-ci-robot commentedon Oct 17, 2018
@roycaihw: GitHub didn't allow me to assign the following users: micw523.
Note that only kubernetes-client members and repo collaborators can be assigned.
For more information please see the contributor guide
Details
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
nakulpathak3 commentedon Oct 25, 2018
I'm not sure how different
applyandcreateare (https://stackoverflow.com/questions/47369351/kubectl-apply-vs-kubectl-create this kinda helped..) but do we need a separate PR/issue for something similar to that in the python client? Or is there a way to combine @micw523's PR with some existing methods to get the same behaviour askubectl apply -f. I'm trying to replace anapply -fcall for a ConfigMap type YAML file.micw523 commentedon Oct 25, 2018
@nakulpathak3 I think using "apply" is a separate feature and could be possibly filed as another issue. Although, I don't think the implementation would be too different from what I have in #655 ...
micw523 commentedon Nov 1, 2018
Please try out #655 (already merged in Master). This functionality is not perfect yet, subject to an existing issue #376 such as when you need to create a CRD, and it is not able to create lists #671. Otherwise please file complaints here and I’ll tend to it.
Apply would require an internal diff and I’ll see if the repo owners are interested in rolling out this function before I test the waters.
nakulpathak3 commentedon Nov 1, 2018
Is
applypotentially just an upsert in k8s (i.e., if create gives a 409, do an update)? Or can we get partial objects which can't just replace the older versions and need examining of the old object to figure out the internal diff like you mentioned? Sorry not that familiar with kubernetes yetroycaihw commentedon Nov 6, 2018
kubectl applyis more advanced compared tokubectl create, and it's non-trivial to implement on client side.I'm interested in the Kubernetes server-side apply feature, which has more capability than client-side (kubectl) apply. Hopefully that feature will rollout in 1.13 as alpha and we can try it out using the python client.
The original feature requested by this issue (create -f) has been added. Closing this issue now
/close
k8s-ci-robot commentedon Nov 6, 2018
@roycaihw: Closing this issue.
Details
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
davi5e commentedon Dec 18, 2018
Just another point of view to complement the discussion, having the Python client execute YAML files enables the versioning of said YAML files, separate from the script code.
That is in itself very useful, at least for me :) It's wasn't about replicating kubectl per se...
zgfh commentedon Dec 24, 2018
kubectl delete -f <yaml file>is in plan?