Skip to content

add examples to demonstrate the usage of dynamic client #1448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Priyankasaggu11929
Copy link
Contributor

@Priyankasaggu11929 Priyankasaggu11929 commented May 1, 2021

What type of PR is this?

/kind documentation

What this PR does / why we need it:

This PR adds example python scripts to demonstrate the usage of dynamic client. Below are the files, I've added:

  • cluster_scoped_custom_resource.py
    Output:
    Screenshot from 2021-05-03 13-33-21

  • namespaced_custom_resource.py
    Output:
    Screenshot from 2021-05-03 13-33-15

  • configmap.py
    Output:
    configmap

  • node.py
    Output:
    node

  • replication_controller.py
    Output:
    replication-controller

  • service.py
    Output:
    service

Which issue(s) this PR fixes:

Fixes #1429

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/documentation Categorizes issue or PR as related to documentation. labels May 1, 2021
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please sign in with your organization's credentials at https://identity.linuxfoundation.org/projects/cncf to be authorized.
  • If you have done the above and are still having issues with the CLA being reported as unsigned, please log a ticket with the Linux Foundation Helpdesk: https://support.linuxfoundation.org/
  • Should you encounter any issues with the Linux Foundation Helpdesk, send a message to the backup e-mail support address at: [email protected]

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 understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label May 1, 2021
@k8s-ci-robot k8s-ci-robot requested review from roycaihw and yliaog May 1, 2021 17:18
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 1, 2021
@Priyankasaggu11929 Priyankasaggu11929 changed the title add-dynamic-client-examples add examples to demonstrate the usage of dynamic client May 1, 2021
@Priyankasaggu11929 Priyankasaggu11929 force-pushed the psaggu-add-dynamic-client-examples branch from 1d75c7b to c936623 Compare May 1, 2021 17:44
@Priyankasaggu11929 Priyankasaggu11929 force-pushed the psaggu-add-dynamic-client-examples branch from c936623 to 553f6ae Compare May 1, 2021 17:56
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 1, 2021
ingressroute_manifest_second["spec"]["entrypoints"] = ["web"]

patch_ingressroute_one = ingressroute_api.patch(
body=ingressroute_manifest_one, content_type="application/merge-patch+json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use strategic-merge-patch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yliaog, thanks for all your useful pointers.
In case of applying a patch on a custom_object with content_type="application/strategic-merge-patch" as you suggested,

   patch_ingressroute_second = ingressroute_api.patch(
        body=ingressroute_manifest_second, content_type="application/strategic-merge-patch+json"
    )

it throws the following error:

Reason: Unsupported Media Type
HTTP response headers: HTTPHeaderDict({'Audit-Id': 'a7b2fb82-0b68-40ee-8439-183cc9c1c0f0', 'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'X-Kubernetes-Pf-Flowschema-Uid': 'd4c6d349-a9e2-454c-b88f-5beb06b64c0b', 'X-Kubernetes-Pf-Prioritylevel-Uid': 'fa2d2d6c-312f-41bb-bc32-d00c53695884', 'Date': 'Mon, 03 May 2021 07:14:43 GMT', 'Content-Length': '293'})
HTTP response body: b'{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"the body of the request was in an unknown format - accepted media types include: application/json-patch+json, application/merge-patch+json, application/apply-patch+yaml","reason":"UnsupportedMediaType","code":415}\n'

I also see in the CustomObjectApi not mentioning application/strategic-merge-patch anywhere in the content-type headers: https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CustomObjectsApi.md#http-request-headers-18

Could you please point me if content_type="application/strategic-merge-patch" is actually not supported & needs to be implemented in the CustomObjectApi or I'm doing something wrong here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

789e374#diff-5a785a7fc5b19b934975d4d49eb71d730de127362b35f89e368179b8355796c8 is the patch to support strategic merge patch.

@roycaihw do you know why is this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yliaog @roycaihw just adding information

The kubernetes python module (I'm using locally) is version 12.0.1

>>> import kubernetes
>>> kubernetes.__version__
'12.0.1'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, strategic merge patch is not supported currently for custom resources

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yliaog, for confirming.

One question: as you pointed in the comments above, that there is already a patch for supporting strategic-merge-patch. Is that something that would be available in the upcoming releases? Or that is not a patch for supporting strategic-merge-patch using dynamic-client?

Thank you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

native k8s resources like "deployment" support strategic-merge-patch. CR does not currently have that support. The support needs to be on the k8s server side, not on the python client side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood. Thank you. :)

body=ingressroute_manifest_one, content_type="application/merge-patch+json"
)
patch_ingressroute_second = ingressroute_api.patch(
body=ingressroute_manifest_second, content_type="application/merge-patch+json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

ingressroute_manifest_second["spec"]["entrypoints"] = ["web"]

patch_ingressroute_one = ingressroute_api.patch(
body=ingressroute_manifest_one, content_type="application/merge-patch+json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use strategic-merge-patch.

body=ingressroute_manifest_one, content_type="application/merge-patch+json"
)
patch_ingressroute_second = ingressroute_api.patch(
body=ingressroute_manifest_second, content_type="application/merge-patch+json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@Priyankasaggu11929 Priyankasaggu11929 force-pushed the psaggu-add-dynamic-client-examples branch 2 times, most recently from fa40565 to 62fd897 Compare May 3, 2021 19:56
@yliaog
Copy link
Contributor

yliaog commented May 4, 2021

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 4, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Priyankasaggu11929, yliaog

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 4, 2021
@Priyankasaggu11929 Priyankasaggu11929 force-pushed the psaggu-add-dynamic-client-examples branch from 62fd897 to 1d9ba9f Compare May 4, 2021 16:30
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 4, 2021
@yliaog
Copy link
Contributor

yliaog commented May 4, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 4, 2021
@Priyankasaggu11929 Priyankasaggu11929 force-pushed the psaggu-add-dynamic-client-examples branch from 1d9ba9f to 22bb5b2 Compare May 4, 2021 17:49
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 4, 2021
@Priyankasaggu11929 Priyankasaggu11929 force-pushed the psaggu-add-dynamic-client-examples branch from 22bb5b2 to 1ff6ece Compare May 4, 2021 18:07
@Priyankasaggu11929
Copy link
Contributor Author

Hi @yliaog , could you please mark it /lgtm again. The tests passed after the PR was approved.

Thank you!

@yliaog
Copy link
Contributor

yliaog commented May 5, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 5, 2021
@k8s-ci-robot k8s-ci-robot merged commit def8b28 into kubernetes-client:master May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/documentation Categorizes issue or PR as related to documentation. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic client example
4 participants