<p>I have an application that runs health checks on pods. Given the health check, I am attempting to patch a pod's label selector from being active: true to active: false. The following is the code for the iteration of pods to change each pod's labels.</p>
<pre><code>CoreV1Api corev1Api = new CoreV1Api();
for (V1Pod pod : fetchPodsByNamespaceAndLabel.getItems()) {
    String jsonPatchBody =  &quot;[{\&quot;op\&quot;:\&quot;replace\&quot;,\&quot;path\&quot;:\&quot;/spec/template/metadata/labels/active\&quot;,\&quot;value\&quot;:\&quot;true\&quot;}]&quot;;
    V1Patch patch = new V1Patch(jsonPatchBody);
    corev1Api.patchNamespacedPodCall(pod.getMetadata.getName(), namespace, patch, null, null, null, null, null);
}
</code></pre>
<p>I have adapted the jsonPatchBody from the <a href="https://github.com/kubernetes-client/java/blob/master/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/PatchExample.java" rel="nofollow noreferrer">Patch Example</a> on the Kubernetes documentation section for examples.</p>
<p>The output of the run spits out no errors. The expected behavior is for the labels of these pods for active to all be set to true. These changes are not reflected. I believe the issue to be caused by the syntax provided by the body of the patch. Is the above the correct syntax for accessing labels in a pod?</p>

<p>After researching more of the current implementation, the client provides the <a href="https://github.com/kubernetes-client/java/blob/master/util/src/main/java/io/kubernetes/client/util/PatchUtils.java" rel="nofollow noreferrer">PatchUtils</a> api that allows me to build a type of patch.</p>
<pre><code>CoreV1Api coreV1Api = new CoreV1Api();
            String body = &quot;{\&quot;metadata\&quot;:{\&quot;labels\&quot;:{\&quot;active\&quot;:\&quot;true\&quot;}}}&quot;;

            V1Pod patch =
                    PatchUtils.patch(
                        V1Pod.class,
                        () -&gt;
                            coreV1Api.patchNamespacedPodCall(
                                    Objects.requireNonNull(pod.getMetadata().getName()),
                                    namespace,
                                    new V1Patch(body),
                                    null,
                                    null,
                                    null,
                                    null,
                                    null),
                            V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH,
                    coreV1Api.getApiClient());
            System.out.println(&quot;Pod name: &quot; + Objects.requireNonNull(pod.getMetadata()).getName() + &quot;Patched by json-patched: &quot; + body);
</code></pre>
<p>I wanted to ensure that the patch updated the current values for a property in my labels selector, so I implemented a <code>PATCH_FORMAT_STRATEGIC_MERGE_PATCH</code> from the <code>V1Patch</code> api. I referenced the Kubernetes <a href="https://github.com/kubernetes-client/java/blob/master/examples/examples-release-15/src/main/java/io/kubernetes/client/examples/PatchExample.java" rel="nofollow noreferrer">Patch Example</a> to build the structure of the Patch.</p>
