<p>I am trying to run the Kubernetes sample controller example by following the link <a href="https://github.com/kubernetes/sample-controller" rel="nofollow noreferrer">https://github.com/kubernetes/sample-controller</a>. I have the repo set up on an Ubuntu 18.04 system and was able to build the sample-controller package.
However, when I try to run the go package, I am getting some errors and am unable to debug the issue. Can someone please help me with this?</p>

<p>Here are the steps that I followed : </p>

<pre><code>user@ubuntu-user:~$ go get k8s.io/sample-controller
user@ubuntu-user:~$ cd $GOPATH/src/k8s.io/sample-controller
</code></pre>

<p>Here's the error that I get on running the controller:</p>

<pre><code>user@ubuntu-user:~/go/src/k8s.io/sample-controller$ ./sample-controller -kubeconfig=$HOME/.kube/config
E0426 15:05:57.721696   31517 reflector.go:125] k8s.io/sample-controller/pkg/generated/informers/externalversions/factory.go:117: Failed to list *v1alpha1.Foo: the server could not find the requested resource (get foos.samplecontroller.k8s.io)
</code></pre>

<p>Kubectl Version : </p>

<pre><code>user@ubuntu-user:~$ kubectl version 
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:02:58Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"```
</code></pre>

<p>I have reproduced your issue. The order of commands in this tutorial is wrong.</p>

<p>In this case you received this error due to lack of resource (samplecontroller)</p>

<pre><code>$ ./sample-controller -kubeconfig=$HOME/.kube/config
E0430 12:55:05.089624  147744 reflector.go:125] k8s.io/sample-controller/pkg/generated/informers/externalversions/factory.go:117: Failed to list *v1alpha1.Foo: the server could not find the requested resource (get foos.samplecontroller.k8s.io)
^CF0430 12:55:05.643778  147744 main.go:74] Error running controller: failed to wait for caches to sync
goroutine 1 [running]:
k8s.io/klog.stacks(0xc0002feb00, 0xc000282200, 0x66, 0x1f5)
    /usr/local/google/home/user/go/src/k8s.io/klog/klog.go:840 +0xb1
k8s.io/klog.(*loggingT).output(0x2134040, 0xc000000003, 0xc0002e12d0, 0x20afafb, 0x7, 0x4a, 0x0)
    /usr/local/google/home/user/go/src/k8s.io/klog/klog.go:791 +0x303
k8s.io/klog.(*loggingT).printf(0x2134040, 0x3, 0x14720f2, 0x1c, 0xc0003c1f48, 0x1, 0x1)
    /usr/local/google/home/user/go/src/k8s.io/klog/klog.go:690 +0x14e
k8s.io/klog.Fatalf(...)
    /usr/local/google/home/user/go/src/k8s.io/klog/klog.go:1241
main.main()
    /usr/local/google/home/user/go/src/k8s.io/sample-controller/main.go:74 +0x3f5
</code></pre>

<p>You can verify that this api was not created</p>

<pre><code>$ kubectl api-versions | grep sample
$ &lt;emptyResult&gt;
</code></pre>

<p>In the tutorial you have command to create <strong>Custom Resource Definition</strong></p>

<pre><code>$ kubectl create -f artifacts/examples/crd.yaml
customresourcedefinition.apiextensions.k8s.io/foos.samplecontroller.k8s.io created
</code></pre>

<p>Now you can search this CRD, it will be on the list now.</p>

<pre><code>$ kubectl api-versions | grep sample
samplecontroller.k8s.io/v1alpha1
</code></pre>

<p>Next step is to create Foo resource</p>

<pre><code>$ kubectl create -f artifacts/examples/example-foo.yaml
foo.samplecontroller.k8s.io/example-foo created
</code></pre>

<p>Those commands will not create any objects yet. </p>

<pre><code>user@user:~/go/src/k8s.io/sample-controller$ kubectl get all
NAME                 TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   XX.XXX.XXX.XX   &lt;none&gt;        443/TCP   14d
</code></pre>

<p>All resources will be created after you will run <code>./sample-controller -kubeconfig=$HOME/.kube/config</code></p>

<pre><code>user@user:~/go/src/k8s.io/sample-controller$ ./sample-controller -kubeconfig=$HOME/.kube/config
user@user:~/go/src/k8s.io/sample-controller$ kubectl get all
NAME                               READY   STATUS    RESTARTS   AGE
pod/example-foo-6cbc69bf5d-8k59h   1/1     Running   0          43s

NAME                 TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.39.240.1   &lt;none&gt;        443/TCP   14d

NAME                          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/example-foo   1         1         1            1           43s

NAME                                     DESIRED   CURRENT   READY   AGE
replicaset.apps/example-foo-6cbc69bf5d   1         1         1       43s
</code></pre>

<p><strong>Correct order:</strong></p>

<pre><code>$ go get k8s.io/sample-controller
$ cd $GOPATH/src/k8s.io/sample-controller
$ go build -o sample-controller .
$ kubectl create -f artifacts/examples/crd.yaml
$ kubectl create -f artifacts/examples/example-foo.yaml
$ ./sample-controller -kubeconfig=$HOME/.kube/config
$ kubectl get deployments
</code></pre>
