Home >Backend Development >Golang >Equivalent to 'kubectl get crds' in golang

Equivalent to 'kubectl get crds' in golang

WBOY
WBOYforward
2024-02-10 21:30:22520browse

相当于golang中的“kubectl get crds”

Equivalent to "kubectl get crds" in golang, this is a concise and powerful command used to get a list of custom resource definitions (CRDs). In golang, kubectl is a very useful command line tool for interacting with Kubernetes clusters. We can easily get a list of all defined CRDs in the current cluster by using the "kubectl get crds" command. This provides us with the ability to better visualize and understand custom resources in the cluster. The function and usage of this command are very similar to a function in php, which we call something. In PHP, we can use this command to get a list of custom resource definitions, which allows us to better manage and operate custom resources.

Question content

If I want to use client-go to list the namespaces on the cluster, I can do this with a simple command:

clientset.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{})

What is the equivalent command to the kubectl get crd command? is it possible?

I tried to find a solution, but most of the answers I found answered how to query for specific crds, rather than getting a list of them.

Workaround

apiextensionsv1beta1 api is part of the apiextensions-apiserver library, not the kubernetes library. To access the apiextensionsv1beta1 api, you need to import the apiextensions-apiserver library as follows:

import (
    apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
)

The above is the detailed content of Equivalent to 'kubectl get crds' in golang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete