<p>How can I create an empty struct of a certain Kubernetes resource when the resource kind/type is given as string ?</p>

<p>I.e. </p>

<pre class="lang-golang prettyprint-override"><code>var object *runtime.Object

object = factory.NewResourceFromKind("pod")
</code></pre>

<p>and <code>object</code> should then contain <code>&amp;apiv1.Pod{}</code> ?</p>

Roland Huß
<p>Knowing the <code>Kind</code> is not enough, however a combination of API Group + API Version + object Kind (<a href="https://godoc.org/k8s.io/apimachinery/pkg/runtime/schema#GroupVersionKind" rel="nofollow noreferrer"><code>GroupVersionKind</code></a>) would allow you to use the information contained in the default <a href="https://godoc.org/k8s.io/client-go/kubernetes/scheme#pkg-variables" rel="nofollow noreferrer"><code>scheme.Scheme</code></a> variable to generate a new object.</p>

<pre><code>package main

import (
    "fmt"

    "k8s.io/apimachinery/pkg/runtime/schema"
    "k8s.io/client-go/kubernetes/scheme"
)

func main() {
    // apiVersion's syntax is "group/version" for non-core API groups
    // e.g. "apps/v1"
    podGvk := schema.FromAPIVersionAndKind("v1", "Pod")

    obj, err := scheme.Scheme.New(podGvk)  // error handling omitted

    fmt.Printf("%T", obj)
    /* prints '*v1.Pod' */
}
</code></pre>

<p>See godoc for <a href="https://godoc.org/k8s.io/apimachinery/pkg/runtime#Scheme.New" rel="nofollow noreferrer"><code>func (*Scheme) New</code></a></p>
