<p>I'm using AWS' EKS which is Kubernetes v1.10 and I'm using client-go v7.0.0.</p>

<p>What I'm trying to do is parse a .yml file with multiple Kubernetes resource definitions in a file and submit those resources to the Kubernetes API. I can successfully parse the files using this code <code>scheme.Codecs.UniversalDeserializer().Decode</code>, and I get back an array of <code>runtime.Object</code>.</p>

<p>I know that all the Kubernetes resources conform to the <code>runtime.Object</code> interface, but I can't find a way to submit the generic interface to the API. Most methods I've seen use the methods on the concrete types like Deployment, Pod, etc.</p>

<p>I've seen some code around a generic RESTClient like this <code>clientset.RESTClient().Put().Body(obj).Do()</code>, but that doesn't work and I can't figure it out.</p>

<p>I know my clientset is configured correctly because I can successfully list all Pods.</p>

<p>If you have a "generic" <code>runtime.Object</code>, you can use the <a href="https://github.com/kubernetes/client-go/tree/3dda0e178874793c2401fcf92356ab800727785b/dynamic" rel="noreferrer">dynamic client</a> in client-go for this. The dynamic client deals with <code>unstructured.Unstructured</code> objects and all <code>runtime.Object</code>s can be converted to it. Here is an example:</p>

<pre><code>// create the dynamic client from kubeconfig
dynamicClient, err := dynamic.NewForConfig(kubeconfig)
if err != nil {
    return err
}

// convert the runtime.Object to unstructured.Unstructured
unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
if err != nil {
    return err
}

// create the object using the dynamic client
nodeResource := schema.GroupVersionResource{Version: "v1", Resource: "Node"}
createdUnstructuredObj, err := dynamicClient.Resource(nodeResource).Namespace(ns).Create(unstructuredObj)
if err != nil {
    return err
}

// convert unstructured.Unstructured to a Node
var node *corev1.Node
if err = runtime.DefaultUnstructuredConverter.FromUnstructured(createdUnstructuredObj, node); err != nil {
    return err
}
</code></pre>
