<p>Is there a way with a single kubernetes API request to remove a specific node taint by key name? As far as I can see the JSON merge patch spec only allows for modifying arrays by index, which I won't know without an additional request and risking a race condition.</p>

<p>Specifically, I am trying to add/remove <code>dedicated</code> NoSchedule keys. </p>

<p>Patching the following body will wipe away all taints:</p>

<pre><code>spec: {
    taints: []
}
</code></pre>

<p>Or I can query the node then modify the taints array and patch it back in, but that risks another operation occurring which will be overwritten. This is quite low risk, but feels like a risk that should be avoidable regardless of likelihood.</p>

<p><code>kubectl</code> as of 1.16, at least, takes the second approach when adding or removing taints, with two requests each, a GET and a PATCH, so I'm not optimistic this is possible:</p>

<pre><code># following command removes the taint with the key 'dedicated'

kubectl taint nodes my-node-1 dedicated- -v8

# (output clearly shows a GET followed by a PATCH request)
</code></pre>

<hr>

<p>So is there any way to write a single API request that results in a specific named taint being removed while leaving others unaffected (without prior knowledge of the taint's position in the taints array)?</p>

<p>There isn't a way to delete an entry from the <code>taints</code> array in a <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#nodespec-v1-core" rel="nofollow noreferrer">NodeSpec</a> in a single request, short of doing something to data inside the etcd store.</p>

<p>The default array <a href="https://v1-15.docs.kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#notes-on-the-strategic-merge-patch" rel="nofollow noreferrer">patch strategy</a> in the Kubernetes API is to replace the array, so you need to send the complete contents of the taints array. Some arrays in the API allow you to merge new elements in, but I don't think there is even 
an available strategy that does deletion the way you want. </p>

<blockquote>
  <p>but that risks another operation occurring which will be overwritten. This is quite low risk, but feels like a risk that should be avoidable regardless of likelihood.</p>
</blockquote>

<p>The Kuberenetes API provides a generic method to protect against stale data updates. All kubernetes resources include a <code>resourceVersion</code> property in their metadata. </p>

<p>When you send the PATCH, include the received <code>resourceVersion</code> and the update will fail if the server side record has been updated since you retrieved the resource. </p>

<pre><code>{
  "metadata": { "resourceVersion": "27409402" },
  "spec": {
    "taints": [
      { "effect":"NoSchedule", "key":"whatever", "value":"special" }
    ]
  }
}
</code></pre>
