1

I'm currently using the Python APIs for Kubernetes and I have to:

  • Retrieve the instance of a custom resource name FADepl.

  • Edit the value of that instance.

In the terminal, I would simply list all FADepls with kubectl get fadepl and then edit the right one using kubectl edit fadepl <fadepl_name>. I checked the K8s APIs for Python but I can't find what I need. Is it something I can do with the APIs?

Thank you in advance!

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
texdade
  • 72
  • 10

3 Answers3

2

You're right. Using get_namespaced_custom_object you can retrieve the instance. This method returns a namespace scoped custom object. By default it uses a synchronous HTTP request.

Since the output of that method returns an object, you can simply replace it using replace_cluster_custom_object.

Here you can find implementation examples.

See also whole list of API Reference for Python.

kkopczak
  • 742
  • 2
  • 8
2

You can use list_cluster_custom_object method from kubernetes.client.CustomObjectsApi.

Let's say that I need to get all calico globalnetworksets instances which are a CRD from calico project.

So first, we need to retrieve some crd data using kubectl as follows:

# get api group, version and plural

> kubectl api-resources -o wide | grep globalnetworkset
    globalnetworksets  crd.projectcalico.org/v1  false  GlobalNetworkSet
     ---------------    -------------------  --
        `plural`             api group       v

With that in mind, we implement list_cluster_custom_object

from kubernetes.client import CustomObjectsApi

group = "crd.projectcalico.org"
v = "v1"
plural = "globalnetworksets"

global_network_sets = CustomObjectsApi.list_cluster_custom_object(group, v, plural)

Juan-Kabbali
  • 1,961
  • 15
  • 20
0

I found the get_namespaced_custom_object call that should do the trick

texdade
  • 72
  • 10