kubernetes: Makefile-style variable expansion on Pod command/args is surprising and can silently corrupt shell code
What happened?
When creating a pod with this definition, the output of the pod is $:
apiVersion: v1
kind: Pod
metadata:
generateName: minimal-reproduction-
spec:
restartPolicy: Never
containers:
- name: minimal-reproduction
image: busybox
command:
- sh
- '-c'
- |
cat <<'EOF'
$$
EOF
❯ kubectl create -f pod.yaml
pod/minimal-reproduction-qmtpj created
❯ kubectl logs pods/minimal-reproduction-qmtpj
$
However, when inspecting the pod, the values are correct and even funnily, this prints $$:
❯ sh -c "$(kubectl get pod minimal-reproduction-qmtpj -o jsonpath='{.spec.containers[0].command[2]}')"
$$
❯ docker run --rm busybox !!
❯ docker run --rm busybox sh -c "$(kubectl get pod minimal-reproduction-qmtpj -o jsonpath='{.spec.containers[0].command[2]}')"
$$
So the dollar sign is lost somewhere between the kubernetes controller and the pod.
What did you expect to happen?
I expected the pod to print every dollar sign that was provided, namely $$.
How can we reproduce it (as minimally and precisely as possible)?
See above
Anything else we need to know?
No response
Kubernetes version
We are running on an OpenShift cluster (if that matters).
$ kubectl version
Client Version: v1.28.2
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.10+67d3387
$ oc version
Client Version: 4.16.10
Cloud provider
RHOS
OS version
No response
Install tools
No response
Container runtime (CRI) and version (if applicable)
No response
Related plugins (CNI, CSI, …) and versions (if applicable)
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 33 (23 by maintainers)
I’m saying that I do not have time to personally explore the idea right now (or any time in the near future). I am certain there are corner-cases I have not thought of and if someone feels this is valuable enough for them to spend their time on, I won’t stop them. If a KEP is created, I almost certainly want to have a voice in it, but I want to manage expectations - this is not a top-priority 😃
We don’t use union types in our API because the one place we did that requires so much special support. It requires custom encoding and decoding in our various serialization formats (JSON/YAML, Proto, BSON) and confuses clients across languages.
We can’t change the type of existing fields because that will break clients.
We won’t do a breaking change for something not security-critical (and even then we will try to find a different way).
We have no plans for a core/V2 API at the moment.
The only path out of this is additive. If this is something you want to pursue, I am happy to discuss and review proposal options. I am going to reopen this and re-title it.
I appreciate the more detailed explanation - now we have 4 levels of parsing - shell, YAML, helm, and kube 😃