Commit graph

7 commits

Author SHA1 Message Date
hunshcn
b528be0a56
kubectl: strict check for exec command (#138214)
* kubectl: strict check for exec command

Fix https://github.com/kubernetes/kubectl/issues/1745

The current implementation doesn't properly check for arguments between
the resource name and the dash separator. This can lead to unexpected
behavior when using commands like 'kubectl exec -it pod-0 bash -- run.sh',
which should raise an error but doesn't.

This fix ensures that when a dash separator (--) is used, there are no
extra arguments between the resource name and the dash.

- Only allow argsLenAtDash == 0 or == 1 (exactly one arg before --)
- Add test for extra args between pod and --
- Add test for flag-like args without dash separator

* test: add kubectl exec container flag coverage

* Apply suggestion from @soltysh

Co-authored-by: Maciej Szulik <soltysh@gmail.com>

---------

Co-authored-by: Maciej Szulik <soltysh@gmail.com>
2026-04-23 06:07:14 +05:30
Arda Güçlü
94047f3cfb List containers when given container is not found 2026-02-12 09:47:30 +03:00
杨军10092085
9fb1ef4dd0 fix kubectl exec command in cmd test 2025-09-02 20:04:46 +08:00
Arda Güçlü
6f4e97e905
Remove deprecated kubectl exec command execution without dash (#125437)
* Remove deprecated kubectl exec command execution without dash

* Use command execution with dash in kubectl exec

* Modify unit tests to only use command after dash
2024-06-21 09:22:55 -07:00
Arda Güçlü
832644f0b3 kubectl exec: return descriptive error message when multi resource passed
`kubectl exec` command supports getting files as inputs. However,
if the file contains multiple resources, it returns unclear error message;
`cannot attach to *v1.List: selector for *v1.List not implemented`.

Since `exec` command does not support multi resources, this PR
handles that and returns descriptive error message earlier.
2022-12-02 14:05:11 +03:00
Maciej Szulik
9dac1699bf
Wire --filename flag to exec 2020-03-03 12:16:52 +01:00
Ahmad Nurus S
0c39d7d380 Kubectl exec support resource/name format 2019-04-25 17:44:01 +07:00