From Kubernetes CRD to Go import
Asked Answered
K

1

6

Imagine you want to get kind/struct called KubeadmControlPlane from the kubernetes API server.

This means you need to import the related struct into your code.

A matching import statement for KubeadmControlPlane would be:

kubeadm "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"

Up to now I need to much time to find a matching import statement.

I use vscode.

How do you get from the CRD kind to an import statement?

Kentigera answered 26/5, 2023 at 6:53 Comment(2)
Are the names of the all CRD kinds and their related structs, same ?Insatiate
@BrokenArmor please elaborate your question. I don't understand it.Kentigera
C
1

Not all Kubernetes CRDs were generated using Go tools, and as such, there may not always be things to import.

If you are unable to find matching type in a repo somewhere, you can use client-go/dynamic to get the values you need.

Refer to this article for detailed examples.

Condole answered 2/8, 2024 at 18:12 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.