Description
Describe the bug
I can successfully run the following code with kubectl:
kubectl patch pods/POD_NAME -n NAMESPACE --type=json --patch='[{ "op": "test", "path": "/metadata/labels/A", "value": "true" }, { "op": "replace", "path": "/metadata/labels/A", "value": "false" }]'
And the pods label for A
changes to "false"
if the pod originally had the "true"
label otherwise it fails with The request is invalid: the server rejected our request due to an error in our request
.
However, following the patch example here results in the NodeJS client returning 422s for the code below.
const patches: {
op: "replace" | "add" | "test";
path: string;
value: string;
}[] = [
{ op: "test", path: "/metadata/labels/A", value: "true" },
{ op: "replace", path: "/metadata/labels/A", value: "false" },
]
const response = await client.patchNamespacedPod(
podName,
namespace,
patches,
undefined, // pretty
undefined, // dryRun
undefined, // fieldManager
undefined, // force
{
headers: {
"Content-Type": PatchUtils.PATCH_FORMAT_JSON_PATCH,
},
},
);
If I remove either of the patches, it works either testing correctly or patching, but I can't seem to get both to run without a 422.
** Client Version **
0.15.0
I also tried with 0.22.3
and it also doesn't work
** Server Version **
>>> kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27+", GitVersion:"v1.27.8-dispatcher", GitCommit:"0153a2044a32f6ee6844207ec1d2de34710d875b", GitTreeState:"clean", BuildDate:"2023-11-28T19:02:53Z", GoVersion:"go1.20.11", Compiler:"gc", Platform:"darwin/arm64"}
Kustomize Version: v5.0.1
Server Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.3", GitCommit:"25b4e43193bcda6c7328a6d147b1fb73a33f1598", GitTreeState:"clean", BuildDate:"2023-06-15T00:38:14Z", GoVersion:"go1.20.5", Compiler:"gc", Platform:"linux/arm64"}
To Reproduce
See description of bug
Expected behavior
I would expect a valid combination of test + replace + add to work similar to a kubectl version of the command
** Example Code**
Code snippet for what you are doing
Environment (please complete the following information):
- OS: MacOS 14.4 (23E214)
- NodeJS Version: v20.15.0
- Cloud runtime: NA
Additional context
I am running kind (kind version 0.20.0
) locally instead of interacting with a cloud k8s cluster. I created it with kind create cluster --image=kindest/node:v1.27.3