k8s-api icon indicating copy to clipboard operation
k8s-api copied to clipboard

Add support for patch strategies

Open RafaeLeal opened this issue 2 years ago • 1 comments

Context

Currently, the body schema for the :patch action is empty, which doesn't allow any valid patch to be done. This happens because the swagger schema itself it's configured simply with the following definition:

    "io.k8s.apimachinery.pkg.apis.meta.v1.Patch": {
      "description": "Patch is provided to give a concrete name and type to the Kubernetes PATCH request body.",
      "type": "object"
    },

What changed

Kubernetes has 4 types of patches, depending on the header "Content-Type" passed:

application/json-patch+json
application/merge-patch+json
application/strategic-merge-patch+json
application/apply-patch+yaml

So this PR changes the swagger schema dynamically to generate the following new actions:

:patch/json
:patch/json-merge
:patch/strategic
:apply/server

So the (k8s/explore client :ConfigMap) looks like this:

[:ConfigMap
 [:list "list or watch objects of kind ConfigMap"]
 [:create "create a ConfigMap"]
 [:deletecollection "delete collection of ConfigMap"]
 [:list-all "list or watch objects of kind ConfigMap"]
 [:get "read the specified ConfigMap"]
 [:update "replace the specified ConfigMap"]
 [:delete "delete a ConfigMap"]
 [:patch/json "update the specified ConfigMap using RFC6902"]
 [:patch/strategic "update the specified ConfigMap using a smart strategy"]
 [:patch/json-merge "update the specified ConfigMap using RFC7286"]
 [:apply/server
  "create or update the specified ConfigMap using server side apply"]]

RafaeLeal avatar Aug 23 '22 06:08 RafaeLeal

This is currently available at 0.2.0-SNAPSHOT https://clojars.org/nubank/k8s-api/versions/0.2.0-SNAPSHOT

RafaeLeal avatar Aug 23 '22 13:08 RafaeLeal