How to write a json patch so that it creates a file in /spec/kubeadmConfigSpec/files/-"?

5/14/2021

I'm trying to do patching to kubeadm control plane resource (I'm using kustomize) so that it enables kubernetes auditing. This is my kustomization.yaml file

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../resource
patchesJson6902:
- target:
    group: controlplane.cluster.x-k8s.io
    version: v1alpha3
    kind: KubeadmControlPlane
    name: cluster-controlplane
  path:  audit/audit.json

I want to add audit policy file and its contents to audit/audit.json. If I'm using a auditpatch.yaml instead of audit.json in path of patchesJson6902, I would be doing something like this

- op: add
  path: "/spec/kubeadmConfigSpec/files/-"
  value:
    path: etc/kubernetes/audit-policy.yaml
    content: |
      apiVersion: audit.k8s.io/v1
      kind: Policy
      rules:
      - level: Metadata

How can we do the same in json format, instead of yaml? Does it go something like this?

[
    {
        "op": "add",
        "path": "/spec/kubeadmConfigSpec/files/-",
        "value":{
        // not sure how to add the content field
        }
    }
]
-- estekevin
json
json-patch
kubernetes
kustomize
yaml

0 Answers