<p>Having trouble figuring out what is wrong. I have a remote kubernetes cluster up and have copied the config locally. I know it is correct because I have gotten other commands to work for me.</p>
<p>The one I can't get to work is a deployment patch. My code:</p>
<pre class="lang-golang prettyprint-override"><code>const namespace = &quot;default&quot;
    
var clientset *kubernetes.Clientset

func init() {
    kubeconfig := &quot;/Users/$USER/go/k8s-api/config&quot;
    config, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, kubeconfig)
    if err != nil {
        log.Fatal(err)
    }

    // create the clientset
    clientset, err = kubernetes.NewForConfig(config)
    if err != nil {
        panic(err.Error())
    }
}

func main() {
    deploymentsClient := clientset.ExtensionsV1beta1().Deployments(&quot;default&quot;)

    patch := []byte(`[{&quot;spec&quot;:{&quot;template&quot;:{&quot;spec&quot;:{&quot;containers&quot;:[{&quot;name&quot;:&quot;my-deploy-test&quot;,&quot;image&quot;:&quot;$ORG/$REPO:my-deploy0.0.1&quot;}]}}}}]`)
    res, err := deploymentsClient.Patch(&quot;my-deploy&quot;, types.JSONPatchType, patch)
    if err != nil {
        panic(err)
    }
    fmt.Println(res)

}
</code></pre>
<p>All I get back is:
<code>panic: the server rejected our request due to an error in our request</code></p>
<p>Any help appreciated, thanks!</p>

<p>You have mixed up <a href="https://godoc.org/k8s.io/apimachinery/pkg/types#PatchType" rel="nofollow noreferrer"><code>JSONPatchType with MergePatchType</code></a>; <code>JSONPatchType</code> wants the input to be <a href="https://www.rfc-editor.org/rfc/rfc6902#section-4.3" rel="nofollow noreferrer">RFC 6902</a> formatted &quot;commands&quot;, and in that case can be a JSON array, because there can be multiple commands applied in order to the input document</p>
<p>However, your payload looks much closer to you wanting <code>MergePatchType</code>, in which case the input should <strong>not</strong> be a JSON array because the source document is not an array of <code>&quot;spec&quot;</code> objects.</p>
<p>Thus, I'd bet just dropping the leading <code>[</code> and trailing <code>]</code>, changing the argument to be <code>types.MergePatchType</code> will get you much further along</p>
