<p>Imagine you want to get kind/struct called <code>KubeadmControlPlane</code> from the kubernetes API server.</p>
<p>This means you need to import the related struct into your code.</p>
<p>A matching import statement for <code>KubeadmControlPlane</code> would be:</p>
<blockquote>
<p>kubeadm &quot;sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1&quot;</p>
</blockquote>
<p>Up to now I need to much time to find a matching import statement.</p>
<p>I use vscode.</p>
<p>How do you get from the CRD kind to an import statement?</p>

guettli
<p>In principle, a <code>go get sigs.k8s.io/cluster-api@v1.4.2</code> (done in the folder where your <code>go.mod</code> is) should be enough to:</p>
<ul>
<li>update your <code>go.mod</code>,</li>
<li>add the library in your <code>$GOPATH</code> and</li>
<li>enable VSCode auto-import to work.</li>
</ul>
<p>That means, when you start typing the name of a struct, like <code>KubeadmControlPlane</code>, the <a href="https://code.visualstudio.com/docs/languages/go" rel="nofollow noreferrer">VSCode Go extension</a> should suggest an auto-import if it can find a matching package in your <code>GOPATH</code> or in your project's vendor directory.</p>
<hr />
<p>If not, the manual process would be:</p>
<ol>
<li><p><strong>Identify the API Group and Version of the CRD:</strong> This information is usually found in the <code>apiVersion</code> field of the CRD YAML file. For example, the <code>KubeadmControlPlane</code> is part of the <code>controlplane.cluster.x-k8s.io/v1beta1</code> API group and version.</p>
</li>
<li><p><strong>Find the Go Package for the API Group:</strong> You need to find the corresponding Go package for this API group.<br />
In the case of the <code>KubeadmControlPlane</code>, it is part of the <code>sigs.k8s.io/cluster-api</code> project and the specific package path is <code>sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1</code>.<br />
A <a href="https://pkg.go.dev/search?q=KubeadmControlPlane" rel="nofollow noreferrer">search in <code>pkg.go.dev</code></a> works too, pending an official API to lookup packages (<a href="https://github.com/golang/go/issues/36785" rel="nofollow noreferrer">issue 36785</a>).</p>
</li>
<li><p><strong>Identify the Go Struct for the CRD:</strong> The Go struct is usually named similarly to the Kind of the CRD. In this case, it is <code>KubeadmControlPlane</code>.</p>
</li>
<li><p><strong>Create the Go Import Statement:</strong> Once you have the package path and struct name, you can create the Go import statement. For example:</p>
</li>
</ol>
<pre class="lang-golang prettyprint-override"><code>import (
    kubeadm &quot;sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1&quot;
)
</code></pre>
