Skip to content

How to patch a status of a custom resource? #2434

Open
@tom-tuvis

Description

@tom-tuvis

I've been trying to send a patch request to a custom object using the javascript client and it seems that if the status doesn't exist I'm getting rejected. That's the code I'm using:

const update = { state: "synced" }

const body = Object.entries(update).map(([key, val]) => {
      return {
        "op": "replace",
        "path": `/status/${key}`,
        "value": val
      }
    })

  return await k8sApi.patchNamespacedCustomObjectStatus({
    group: GROUP,
    version: VERSION,
    namespace,
    plural: crd,
    name,
    body,
    fieldValidation: "Strict"
  })

What I do to get around it is to make another call before sending the patch to check if the resource has a status subresource, and if it doesn't, I add an add operation at the start. But then I end up with 2 calls where I could have done it with one.

I've been trying to find a way to send it a merge patch, and to my understanding I need to change the Content-Type to application/merge-patch+json - but I couldn't find where to do it. Looking at the [code][1], I see that there's some internal logic to determine the Content-Type header, rather than taking it from the any argument in the call.

Is this a bug or am I doing something wrong? How can I patch the status of a resource that might not have a status yet (and do it with a single call)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions