Skip to content

About patching pod spec with additional volumes and volumeMounts #198

@mighty1231

Description

@mighty1231

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?

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