<p>I am trying to connect to an OpenShift/K8s cluster from inside a running pod via the Go API. Therfore, i am following the tutorial from <a href="https://docs.openshift.org/latest/go_client/connecting_to_the_cluster.html#connecting-from-within-a-pod-running-in-the-cluster" rel="nofollow noreferrer">here</a>. </p>

<p>Currently i have a problem with creating the OpenShift build client, whose constructor gets a previously created <code>rest.InClusterConfig()</code> as an argument. This <em>should</em> work, since it is shown in the example, but i get this error:</p>

<pre><code>cannot use restconfig (type *"k8s.io/client-go/rest".Config) as type *"github.com/openshift/client-go/vendor/k8s.io/client-go/rest".Config in argument to "github.com/openshift/client-go/build/clientset/versioned/typed/build/v1".NewForConfig
</code></pre>

<p>I am a little confused, since <code>rest.InClusterConfig()</code> returns a <code>*Config</code>. This is accepted in <code>corev1client.NewForConfig()</code> which expects a <code>*rest.Config</code>. But <code>buildv1client.NewForConfig()</code> also expects a <code>*rest.Config</code> - but not exactly the restconfig i am creating with <code>rest.InClusterConfig()</code>. </p>

<p>Where is my mistake? Bonus points for: I am taking my first steps with the API, and all it should do is to generate a second pod, from an image where some parameters are applied. Do i need the <code>buildv1client</code> client? This is pretty much Kubernetes core functionality. </p>

simonszu
<p>The problem is that the package exists in the vendored folder in <code>vendor/</code> and also on your <code>$GOPATH</code>. Vendoring <code>"github.com/openshift/client-go"</code> should solve your problem.</p>

<p>To answer your second question, for the use case you have described, not really. If you want to create an OpenShift build then yes you need to use the client as this API object does not exist in Kubernetes. If you want to simply create a Pod then you don't need the build client. A simple example for the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#pod-v1-core" rel="nofollow noreferrer">API reference</a> might look as follows:</p>

<pre><code>package main

import (
    "k8s.io/api/core/v1"
    "k8s.io/client-go/tools/clientcmd"

    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
)

func main() {
    kubeconfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
        clientcmd.NewDefaultClientConfigLoadingRules(),
        &amp;clientcmd.ConfigOverrides{},
    )
    namespace, _, err := kubeconfig.Namespace()
    if err != nil {
        panic(err)
    }
    restconfig, err := kubeconfig.ClientConfig()
    if err != nil {
        panic(err)
    }
    coreclient, err := corev1client.NewForConfig(restconfig)
    if err != nil {
        panic(err)
    }

    _, err = coreclient.Pods(namespace).Create(&amp;v1.Pod{
        ObjectMeta: metav1.ObjectMeta{
            Name: "example",
        },
        Spec: v1.PodSpec{
            Containers: []v1.Container{
                {
                    Name:    "ubuntu",
                    Image:   "ubuntu:trusty",
                    Command: []string{"echo"},
                    Args:    []string{"Hello World"},
                },
            },
        },
    })
    if err != nil {
        panic(err)
    }

}
</code></pre>
