title: How to get schema.GroupVersionResource for given k8s resource's json
body: <ul>
  <li>client-go v0.19.2</li>
  <li>golang 1.13</li>
  </ul>
  <p>I'm building a tool to create k8s resources from json(just like kubectl create -f).</p>
  <p>I found that dynamic client can do such things,but when i use it with code bellow,i found it is hard to find schema.GroupVersionResource for given resource's json.Am i missing something or the only way to get resource is through restmapper?</p>
  <pre class="lang-golang prettyprint-override"><code>container := &amp;unstructured.Unstructured{}
  if err := container.UnmarshalJSON([]byte(jsonstring); err != nil {
      return err
  }
  
  _, err := k8sclient.Dynamic.Resource(?).Create(ctx, container, metav1.CreateOptions{})
  if err != nil {
      return err
  }
  </code></pre>
  <p>I know a work around is to write some code like bellow, but i'm sure it's not the best practice and there are too many of them besides crds.</p>
  <pre class="lang-golang prettyprint-override"><code>var kindResourceMap = map[string]schema.GroupVersionResource{
      &quot;Deployment&quot;: {
          Group:    &quot;apps&quot;,
          Version:  &quot;v1&quot;,
          Resource: &quot;deployments&quot;,
      },
      &quot;ConfigMap&quot;: {
          Group:    &quot;apps&quot;,
          Version:  &quot;v1&quot;,
          Resource: &quot;configmaps&quot;,
      },
      &quot;Job&quot;: {
          Group:    &quot;batch&quot;,
          Version:  &quot;v1&quot;,
          Resource: &quot;jobs&quot;,
      },
      &quot;Secret&quot;: {
          Group:    &quot;api&quot;,
          Version:  &quot;v1&quot;,
          Resource: &quot;secrets&quot;,
      },
      &quot;Service&quot;: {
          Group:    &quot;api&quot;,
          Version:  &quot;v1&quot;,
          Resource: &quot;services&quot;,
      },
      &quot;StatefulSet&quot;: {
          Group:    &quot;apps&quot;,
          Version:  &quot;v1&quot;,
          Resource: &quot;statefulsets&quot;,
      },
      &quot;PersistentVolume&quot;: {
          Group:    &quot;api&quot;,
          Version:  &quot;v1&quot;,
          Resource: &quot;persistentvolumes&quot;,
      },
      &quot;CustomResourceDefinition&quot;: {
          Group:    &quot;apiextensions.k8s.io&quot;,
          Version:  &quot;v1beta1&quot;,
          Resource: &quot;customresourcedefinitions&quot;,
      },
  }
  </code></pre>