Equivalent to 'kubectl get crds' in golang

WBOY
Release: 2024-02-10 21:30:22
forward
486 people have browsed it

相当于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{})
Copy after login

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"
)
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!