Removed the custom_object.py file and and added namespaced_custom_object.py

This commit is contained in:
Yash Kumar Singh 2021-04-29 09:44:24 +05:30
parent 68aeb30ae8
commit 9248a90055

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",