1

I use kubectl to list Kubernetes custom resources of a kind mykind with an additional table column LABEL that contains the value of a label a.b.c.com/key if present:

kubectl get mykind -o=custom-columns=LABEL:.metadata.labels.'a\.b\.c\.com/key'

This works, i.e., the label value is properly displayed.

Subsequently, I wanted to add a corresponding additional printer column to the custom resource definition of mykind:

- description: Label value
  jsonPath: .metadata.labels.'a\.b\.c\.com/key'
  name: LABEL
  type: string

Although the additional column is added to kubectl get mykind, it is empty and no label value is shown (in contrast to above kubectl command). My only suspicion were problems with escaping of the special characters - but no variation helped.

Are you aware of any difference between the JSON path handling in kubectl and additional printer columns? I expected strongly that they are exactly the same.

anekdoti
  • 135
  • 7
  • 1
    Including those `'` characters is a shell concession, and are not part of jsonpath; you can change it in yaml to be `jsonPath: '.metadata.labels.a\.b\.c\.com/key'` and it will become legal yaml again, although I don't know that it will solve your problem – mdaniel Nov 16 '22 at 19:58

1 Answers1

1

mdaniel's comment works!

- description: Label value
  jsonPath: '.metadata.labels.a\.b\.c\.com/key'
  name: LABEL
  type: string

You need to use \. instead of . and use single quotes ' '. It doesn't work with double quotes for the reasons I don't understand