Python: Fix and Update Existing Examples

Created on 17 Jul 2019  路  10Comments  路  Source: kubernetes-client/python

The *.py files in the examples/ directory need updates for various reasons. Some of them could also use better file names and more commenting within the files (alternatively, there could be a README.md that provides more information about setup and each file). Below are the files that I have tested and found issues for.

  • [x] create_deployment.py: seems redundant with deployment_examples.py and create_deployment_from_yaml.py, I think it should be merged with one of those
  • [x] create_deployment_from_yaml.py: fix the associated nginx-deployment.yaml which creates pods that go to a state of crashloopbackoff
  • [x] create_thirdparty_resource.md: in progress of being replaced with a custom resource definition example with https://github.com/kubernetes-client/python/pull/848/
  • [x] deployment_examples.py: add documentation
  • [x] example1.py: add documentation and use more descriptive filename
  • [x] example2.py: add documentation and use more descriptive filename
  • [x] example3.py: add documentation and use more descriptive filename
  • [x] example4.py: add documentation and use more descriptive filename, also the print("Active host is %s" % configuration.host) line throws the error AttributeError: module 'kubernetes.client.configuration' has no attribute 'host' -- in progress with https://github.com/kubernetes-client/python/pull/846/files
  • [x] exec.py: add documentation explaining what this does
  • [x] in_cluster_config.py: create YAML for in-cluster pod
  • [x] manage_node_labels.py: add documentation that it is for minikube only
  • [x] nginx-deployment.yaml: using this with create_deployment_from_yaml.py creates nginx pods that immediately go to a state of crashloopbackoff fixed by https://github.com/kubernetes-client/python/pull/888
  • [x] remote_cluster.py: the list_pod_for_all_namespaces method returns a 401 unauthorized error, probably needs RBAC?

Examples without issues:

  • multiple_clusters.py
  • job_examples.py (https://github.com/kubernetes-client/python/pull/786/files)
help wanted

All 10 comments

This is awesome! Thanks for looking into the examples and putting together this summary.

Some additional thoughts:

The create_deployment and create_deployment_from_yaml does the same thing except that the deployment is performed using different ways.

I wonder what's happening with the yaml deployment though. The source function for calling the yaml method should be the same.

/help

@micw523:
This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

/help

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.

create_deployment_from_yaml.py: fix the associated nginx-deployment.yaml which creates pods that go to a state of crashloopbackoff

The yaml file models from https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment. It's probably something wrong with the container image 1.7.9. Please update the yaml file to be the same as https://k8s.io/examples/controllers/nginx-deployment.yaml

Deployment has been removed from extensions/v1beta1 in 1.15, we should update the examples create_deployment.py and create_deployment_from_yaml.py to use apps/v1 instead

Sounds good. Looks like the e2e tests would need this update too. Let me quickly fix this today.

I will start organizing and fixing these examples in the week after next (busy next week unfortunately) and hopefully most of the pull requests trying to update examples will be merged by then as well.

There is also an issue with the custom_objects.py example, but I am not sure if the issue is with the example or the api itself. I have not been able to call this api without getting an error. Below is the error output when I try to run the custom_objects.py module, and the error is similar when I try to call the API from elsewhere:
zachs-mbp:dzd2 zach$ python3.7 -m examples.custom_object Traceback (most recent call last): File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/Users/zach/Documents/dzd2/examples/custom_object.py", line 93, in <module> main() File "/Users/zach/Documents/dzd2/examples/custom_object.py", line 65, in main body=my_resource, File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/custom_objects_api.py", line 178, in create_namespaced_custom_object (data) = self.create_namespaced_custom_object_with_http_info(group, version, namespace, plural, body, **kwargs) File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/custom_objects_api.py", line 277, in create_namespaced_custom_object_with_http_info collection_formats=collection_formats) File "/usr/local/lib/python3.7/site-packages/kubernetes/client/api_client.py", line 334, in call_api _return_http_data_only, collection_formats, _preload_content, _request_timeout) File "/usr/local/lib/python3.7/site-packages/kubernetes/client/api_client.py", line 168, in __call_api _request_timeout=_request_timeout) File "/usr/local/lib/python3.7/site-packages/kubernetes/client/api_client.py", line 377, in request body=body) File "/usr/local/lib/python3.7/site-packages/kubernetes/client/rest.py", line 266, in POST body=body) File "/usr/local/lib/python3.7/site-packages/kubernetes/client/rest.py", line 222, in request raise ApiException(http_resp=r) kubernetes.client.rest.ApiException: (404) Reason: Not Found HTTP response headers: HTTPHeaderDict({'Audit-Id': 'e1e34583-bc4d-45e2-96ec-9072d3624586', 'Content-Type': 'text/plain; charset=utf-8', 'X-Content-Type-Options': 'nosniff', 'Date': 'Thu, 05 Sep 2019 18:18:33 GMT', 'Content-Length': '19'}) HTTP response body: 404 page not found

@zmunro The 404 error sounds like the apiserver doesn't understand the requested API resource. Have you registered the CRD to apiserver? https://github.com/kubernetes-client/python/blob/a5cb3d788977bcecf43f9be4d4602e7b5bf1e56c/examples/custom_object.py#L18-L36

It's probably better to have the example run the CRD creation for you

@roycaihw the comment is addressed in #948, the issue that the author of the comment raised.

Was this page helpful?
0 / 5 - 0 ratings