<p>I am using Velero to create and backup and restore, Velero has controllers which get triggered when I can create the custom objects.</p>
<pre><code>import veleroApi &quot;github.com/vmware-tanzu/velero/pkg/apis/velero/v1&quot;

restoreObj := veleroApi.Restore{
    TypeMeta:   metav1.TypeMeta{},
    ObjectMeta: metav1.ObjectMeta{
        DeletionGracePeriodSeconds: &amp;gracePeriodSeconds,
    },
    Spec:       veleroApi.RestoreSpec{
        BackupName:              &quot;backup-name-20211101&quot;,
        RestorePVs:              &amp;restorePV,
    },
    Status:     veleroApi.RestoreStatus{},
}
</code></pre>
<p>But how can I submit this custom object to the Kube API server?</p>
<p>I used API client to apply the changes:</p>
<pre><code>apiClient.CoreV1().RESTClient().Patch(types.ApplyPatchType).Body(restoreObj).Do(context)
</code></pre>
<p>But I am getting:</p>
<pre><code>unknown type used for body: {TypeMeta:{Kind:Restore APIVersion:velero.io/v1} ObjectMeta:{Name: GenerateName: Namespace:velero SelfLink: UID: ResourceVersion: Generation:0 CreationTimestamp:0001-01-01 00:00:00 +0000 UTC DeletionTimestamp:&lt;nil&gt; DeletionGracePeriodSeconds:0xc000256018 Labels:map[] Annotations:map[] OwnerReferences:[] Finalizers:[] ClusterName: ManagedFields:[]} Spec:{BackupName:backup-name-20211101 ScheduleName: IncludedNamespaces:[] ExcludedNamespaces:[] IncludedResources:[] ExcludedResources:[] NamespaceMapping:map[] LabelSelector:nil RestorePVs:0xc0007a9088 PreserveNodePorts:&lt;nil&gt; IncludeClusterResources:&lt;nil&gt; Hooks:{Resources:[]}} Status:{Phase: ValidationErrors:[] Warnings:0 Errors:0 FailureReason: StartTimestamp:&lt;nil&gt; CompletionTimestamp:&lt;nil&gt; Progress:&lt;nil&gt;}}
</code></pre>

<p>If you would like to create a client for custom object follow the following steps:</p>
<ol>
<li>Describe the custom resource for which you would like to create a rest client:</li>
</ol>
<pre><code>kubectl describe CustomResourceDefinition &lt;custom resource definition name&gt;
</code></pre>
<p>Note down the <code>API and version</code> and the <code>Kind</code>, as an example it would look like:</p>
<pre><code>API Version:  apiextensions.k8s.io/v1
Kind:         CustomResourceDefinition
</code></pre>
<p>Here, <code>apiextensions.k8s.io</code> is API and <code>v1</code> is the version.</p>
<ol start="2">
<li>Check if the <code>API version</code> that you got from step 1 is in the list of APIs:</li>
</ol>
<pre><code>kubectl get --raw &quot;/&quot;
</code></pre>
<ol start="3">
<li>Create the client:</li>
</ol>
<pre><code>func getClusterConfig() *rest.Config {
    config, err := rest.InClusterConfig()
    if err != nil {
        glog.Fatal(err.Error())
    }
    return config
}

func getRestClient() *rest.RESTClient {

    cfg := getClusterConfig()

    gv := schema.GroupVersion{Group: &quot;&lt;API&gt;&quot;, Version: &quot;&lt;version&gt;&quot;}
    cfg.GroupVersion = &amp;gv
    cfg.APIPath = &quot;/apis&quot; // you can verify the path from step 2

    var Scheme = runtime.NewScheme()
    var Codecs = serializer.NewCodecFactory(Scheme)
    cfg.NegotiatedSerializer = Codecs.WithoutConversion()

    restClient, err := rest.RESTClientFor(cfg)

    if err != nil {
        panic(err.Error())
    }
    return restClient
}

</code></pre>
<p>Alternatively, check the answer from kozmo <a href="https://stackoverflow.com/a/63424133/2704032">here</a></p>
<hr />
<p>For Velero you can reuse the client they have.</p>
<p>As an example take a look at <a href="https://github.com/vmware-tanzu/velero/blob/3b2e9036d178831e9be9aa90403c4aad42793cb6/pkg/cmd/cli/restore/create.go#L319" rel="nofollow noreferrer">this code</a>:</p>
<pre><code>restore, err := o.client.VeleroV1().Restores(restore.Namespace).Create(context.TODO(), restore, metav1.CreateOptions{})
</code></pre>
