<p>I am trying to generate client code using k8s.io/code-generator.
These are the instructions that I am following: <a href="https://itnext.io/how-to-generate-client-codes-for-kubernetes-custom-resource-definitions-crd-b4b9907769ba" rel="nofollow noreferrer">https://itnext.io/how-to-generate-client-codes-for-kubernetes-custom-resource-definitions-crd-b4b9907769ba</a></p>

<p>My question is, does my go module need to be present on a repository or can I simply run the generate-groups.sh script on a go module that is ONLY present on my local system and not on any repository?</p>

<p>I have already tried running it and from what I understand, there needs to be a repository having ALL the contents of my local go module. Is my understanding correct? </p>

codego123
<p>You CAN run <a href="https://github.com/kubernetes/code-generator" rel="noreferrer">kubernetes/code-generator</a>'s generate-groups.sh on a go module that is only present on your local system. Neither code-generator nor your module needs to be in your <code>GOPATH</code>.</p>

<h3>Verification</h3>

<p>Cloned <a href="https://github.com/kubernetes/code-generator" rel="noreferrer">kubernetes/code-generator</a> into a new directory.</p>

<pre class="lang-golang prettyprint-override"><code>$HOME/somedir
├── code-generator
</code></pre>

<p>Created a project called <code>myrepo</code> and mocked it with content to resemble <a href="https://github.com/kubernetes/sample-controller" rel="noreferrer">sample-controller</a>. Did this in the same directory to keep it simple.</p>

<pre class="lang-sh prettyprint-override"><code>somedir
├── code-generator
└── myorg.com
    └── myrepo        # mock of sample-controller
        ├── go.mod
        ├── go.sum
        └── pkg
            └── apis
                └── myorg
                    ├── register.go
                    └── v1alpha1
                        ├── doc.go
                        ├── register.go
                        └── types.go
</code></pre>

<p>My go.mod looked like</p>

<pre><code>module myorg.com/myrepo

go 1.14

require k8s.io/apimachinery v0.17.4
</code></pre>

<p>Ran <code>generate-group.sh</code>. The <code>-h</code> flag specifies which header file to use. The <code>-o</code> flag specifies the output base which is necessary here because we're not in GOPATH.</p>

<pre class="lang-sh prettyprint-override"><code>$HOME/somedir/code-generator/generate-groups.sh all myorg.com/myrepo/pkg/client myorg.com/myrepo/pkg/apis "myorg:v1alpha1" \
-h $HOME/somedir/code-generator/hack/boilerplate.go.txt \
-o $HOME/somedir
</code></pre>

<p>Confirmed code generated in correct locations</p>

<pre class="lang-sh prettyprint-override"><code>myrepo
├── go.mod
├── go.sum
└── pkg
    ├── apis
    │   └── myorg
    │       ├── register.go
    │       └── v1alpha1
    │           ├── doc.go
    │           ├── register.go
    │           ├── types.go
    │           └── zz_generated.deepcopy.go
    └── client
        ├── clientset
        │   └── versioned
        │       ├── clientset.go
        │       ├── doc.go
        │       ├── fake
        │       ├── scheme
        │       └── typed
        ├── informers
        │   └── externalversions
        │       ├── factory.go
        │       ├── generic.go
        │       ├── internalinterfaces
        │       └── myorg
        └── listers
            └── myorg
                └── v1alpha1
</code></pre>

<h3>Sources</h3>

<ul>
<li>Go modules support <a href="https://github.com/kubernetes/code-generator/issues/57" rel="noreferrer">https://github.com/kubernetes/code-generator/issues/57</a></li>
<li>Documentation or support for Go modules <a href="https://github.com/kubernetes/sample-controller/issues/47" rel="noreferrer">https://github.com/kubernetes/sample-controller/issues/47</a></li>
</ul>
