<p>We are using the kubernetes mutating webhook to mutate a request on creation of a pod. From what I understand, the api server makes a callback to an endpoint of a mutating web hook that matches certain rules of a request. The webhook now mutates the request by adding patches to it and sending it back to the api server. </p>

<p>An example patch:</p>

<pre><code>[
  {
    "op": "add",
    "path": "/metadata/annotations",
    "value": {
      "injected": "true"
    }
  }
]
</code></pre>

<p>My question is this - Is there a reference or a doc that shows how the patch endpoints work. I am referring to <code>metadata/annotations</code> here.</p>

<p>I have questions like - </p>

<ul>
<li>does it update the existing object or does it replace it? </li>
<li>what other operations are possible other than <code>add</code></li>
</ul>

<p>There are several more patch endpoints for different objects. I have been trying to find these docs for some time now and couldn't. </p>

<p>I am not sure if this is the right place to ask this. Sorry if it isn't. Kindly point me to the right forum if there is one.</p>

leoOrion
<p>Mutating webhook does not patch an object because the object is not yet persisted in ETCD. Mutating web hooks gets a <a href="https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#request" rel="nofollow noreferrer">request</a> from API Server. This request has AdmissionReview object in it.Mutating Webhook unmarshalls the AdmissionReview object, mutates it and then send back a <a href="https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#response" rel="nofollow noreferrer">response</a> to API Server.</p>

<p>You will start with a basic web server, that supports SSL/TLS, and can read and respond in JSON format.In practice, you can use whatever programming language you’d like for this.Ideally though, use a language that already has K8S libraries so you don’t have to create our own object types; Go (naturally) has these, but there are also at least Python libraries you could use.</p>

<p>Here is an <a href="https://github.com/kubernetes/kubernetes/blob/v1.13.0/test/images/webhook/main.go" rel="nofollow noreferrer">example</a> in go.</p>
