kubectl-trace icon indicating copy to clipboard operation
kubectl-trace copied to clipboard

About patching pod spec with additional volumes and volumeMounts

Open mighty1231 opened this issue 2 years ago • 0 comments

How to patch adding volumes and volumeMounts?

What I tried?

$ cat patch.yaml
- op: add
  path: /spec/template/spec/containers/0/volumeMounts
  value:
    - name: trace-result
      mountPath: /tmp/results
- op: add
  path: /spec/template/spec/volumes
  value:
    - name: trace-result
      hostPath:
        path: /tmp/trace-results
        type: DirectoryOrCreate
$ kubectl trace run pod/some-pod \
  --patch-type json \
  --patch patch.yaml \
  -f some.bt --attach

Expected Pod Spec VolumeMounts

$ kubectl get pod kubectl-trace-299c5a64-0ec0-4846-9960-1cb2a4275a05--1-ct4d2 -o jsonpath="{.spec.containers[0].volumeMounts}" | yq . -P
- mountPath: /programs
  name: program
  readOnly: true
- mountPath: /sys
  name: sys
  readOnly: true
- mountPath: /usr-host
  name: usr-host
  readOnly: true
- mountPath: /lib/modules
  name: modules-host
  readOnly: true
- name: trace-result # Here I added
  mountPath: /tmp/results
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
  name: kube-api-access-95fr5
  readOnly: true

Actual Results for Pod Spec VolumeMounts

$ kubectl get pod kubectl-trace-299c5a64-0ec0-4846-9960-1cb2a4275a05--1-ct4d2 -o jsonpath="{.spec.containers[0].volumeMounts}" | yq . -P
- mountPath: /tmp/results
  name: trace-result
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
  name: kube-api-access-lsmjb
  readOnly: true

Where the items program, sys, usr-host, modules-host has gone? I think it replace d items, instead of add which I wrote as the value of op item in patch.yaml.

I just represented for volumeMounts here, but volumes also works in the same way.

Alternative Method?

I tried to fix container name of kubectl-trace pod and tried strategic patch, with creating new PR, but it breaks some integration test - failing TestKubectlTraceSuite/TestDeploymentTarget. Does anyone can help me how to deal integration tests?

Additional feature request

How about adding --dry-run option on kubectl-trace run, to check which resources are going to be deployed?

mighty1231 avatar Mar 02 '23 01:03 mighty1231