<p>I'm relatively new to golang and need some help pointing to the right direction.</p>

<p>I'm trying to declare a new <code>Deployment</code> type.</p>

<p>My imports look like:</p>

<pre><code>import (
  "encoding/json"
  "fmt"
  yaml "gopkg.in/yaml.v2"
  "io/ioutil"
  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  "k8s.io/kubernetes/pkg/api/v1"
  "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
)
</code></pre>

<p>When I try to create a Deployment Object like:</p>

<pre><code>  test := v1beta1.Deployment{
    Spec: v1beta1.DeploymentSpec{
      Template: v1.PodTemplateSpec{
        Spec: v1.PodSpec{
          Containers: []v1.Container{{
            Name:  "test",
            Image: "image_url",
          },
          },
        },
      },
    },
  }
</code></pre>

<p>It works, but the Deployment Object that returns doesn't have a <code>Kind</code> which is necessary to identify the object.</p>

<p>According to <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/extensions/types.go#L162" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/extensions/types.go#L162</a></p>

<p>There's an embedded <code>metav1.TypeMeta</code> which has the <code>Kind</code> object that I need. (For reference: <a href="https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/v1/types.go#L38" rel="nofollow noreferrer">https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/v1/types.go#L38</a>)</p>

<p>I tried declaring <code>metav1.TypeMeta</code> in the struct literal like:</p>

<pre><code>  test := v1beta1.Deployment{
    metav1.TypeMeta: metav1.TypeMeta{Kind: "Deployment"}
    Spec: v1beta1.DeploymentSpec{
      Template: v1.PodTemplateSpec{
        Spec: v1.PodSpec{
          Containers: []v1.Container{{
            Name:  "test",
            Image: "image_url",
          },
          },
        },
      },
    },
  } 
</code></pre>

<p>But I get a </p>

<p><code>unknown field '"k8s.io/apimachinery/pkg/apis/meta/v1".TypeMeta' in struct literal of type v1beta1.Deployment</code></p>

<p>I suspect it is due to <code>metav1.TypeMeta</code> declaration in the <code>Deployment</code> struct is an unexported field.</p>

<p>How should I declare Kind?</p>

<p>When using an embedded struct, the key is usually the type name without the package. You can declare your <code>TypeMeta</code> like this:</p>

<pre><code>test := v1beta1.Deployment{
  TypeMeta: metav1.TypeMeta{
    APIVersion: "apps/v1beta1",
    Kind: "Deployment",
  },
}
</code></pre>

<p>However, manually setting the <code>TypeMeta</code> on any Kubernetes API object is usually only necessary if you plan to persist these objects yourself (for example, to generate YAML files).</p>

<p>When using the Kubernetes client API (for example, using the k8s.io/client-go package) to talk to an API server, you will not need the <code>TypeMeta</code> property, since all API operations are strongly typed anyway and all metadata can safely be inferred. After all, the API version and kind of a <code>v1beta1.Deployment</code> struct should be (and are, to the client library) obvious.</p>
