Merge pull request #1440 from Yashks1994/remove-custom-patch1

Removed custom_object.py and created a new file namespaced_custom_object.py which is more specific to usage of namespaced custom resource
This commit is contained in:
Kubernetes Prow Robot 2021-04-30 09:59:59 -07:00 committed by GitHub
commit 36d2108e89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,7 @@ Uses a Custom Resource Definition (CRD) to create a custom object, in this case
a CronTab. This example use an example CRD from this tutorial:
https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/
The following yaml manifest has to be applied first:
The following yaml manifest has to be applied first for namespaced scoped CRD:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
@ -72,6 +72,11 @@ def main():
}
}
# patch to update the `spec.cronSpec` field
patch_body = {
"spec": {"cronSpec": "* * * * */10", "image": "my-awesome-cron-image"}
}
# create the resource
api.create_namespaced_custom_object(
group="stable.example.com",
@ -93,6 +98,18 @@ def main():
print("Resource details:")
pprint(resource)
# patch the namespaced custom object to update the `spec.cronSpec` field
patch_resource = api.patch_namespaced_custom_object(
group="stable.example.com",
version="v1",
name="my-new-cron-object",
namespace="default",
plural="crontabs",
body=patch_body,
)
print("Resource details:")
pprint(patch_resource)
# delete it
api.delete_namespaced_custom_object(
group="stable.example.com",