Skip to content

Fix and Update Existing Examples #884

Closed

Description

@scottilee

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.

  • 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
  • create_deployment_from_yaml.py: fix the associated nginx-deployment.yaml which creates pods that go to a state of crashloopbackoff
  • create_thirdparty_resource.md: in progress of being replaced with a custom resource definition example with add example of using custom resources #848
  • deployment_examples.py: add documentation
  • example1.py: add documentation and use more descriptive filename
  • example2.py: add documentation and use more descriptive filename
  • example3.py: add documentation and use more descriptive filename
  • 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
  • exec.py: add documentation explaining what this does
  • in_cluster_config.py: create YAML for in-cluster pod
  • manage_node_labels.py: add documentation that it is for minikube only
  • nginx-deployment.yaml: using this with create_deployment_from_yaml.py creates nginx pods that immediately go to a state of crashloopbackoff fixed by Deprecate extensions/v1beta1 deployment #888
  • remote_cluster.py: the list_pod_for_all_namespaces method returns a 401 unauthorized error, probably needs RBAC?

Examples without issues:

Activity

  1. roycaihw commented on Jul 19, 2019

    @roycaihw
    Member

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

    Some additional thoughts:

  2. micw523 commented on Jul 19, 2019

    @micw523
    Contributor

    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.

  3. micw523 commented on Jul 19, 2019

    @micw523
    Contributor

    /help

  4. k8s-ci-robot commented on Jul 19, 2019

    @k8s-ci-robot
    Contributor

    @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.

    Details

    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.

  5. added
    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
    on Jul 19, 2019
  6. roycaihw commented on Jul 22, 2019

    @roycaihw
    Member

    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

  7. micw523 commented on Jul 22, 2019

    @micw523
    Contributor

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

  8. scottilee commented on Aug 2, 2019

    @scottilee
    ContributorAuthor

    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.

  9. zmunro commented on Sep 5, 2019

    @zmunro

    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:

    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```
    
  10. roycaihw commented on Sep 10, 2019

    @roycaihw
    Member

    @zmunro The 404 error sounds like the apiserver doesn't understand the requested API resource. Have you registered the CRD to apiserver?

    # The following yaml manifest has to be applied first:
    #
    # apiVersion: apiextensions.k8s.io/v1beta1
    # kind: CustomResourceDefinition
    # metadata:
    # name: crontabs.stable.example.com
    # spec:
    # group: stable.example.com
    # versions:
    # - name: v1
    # served: true
    # storage: true
    # scope: Namespaced
    # names:
    # plural: crontabs
    # singular: crontab
    # kind: CronTab
    # shortNames:
    # - ct

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

  11. micw523 commented on Sep 11, 2019

    @micw523
    Contributor

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

  12. added a commit that references this issue on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions