mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
Merge pull request #114249 from ardaguclu/improve-exec-multi-error
kubectl exec: return descriptive error message when multi resource passed
This commit is contained in:
commit
9f85f6d1f1
@ -33,6 +33,7 @@ import (
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/remotecommand"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/cmd/util/podcmd"
|
||||
"k8s.io/kubectl/pkg/polymorphichelpers"
|
||||
@ -310,6 +311,10 @@ func (p *ExecOptions) Run() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if meta.IsListType(obj) {
|
||||
return fmt.Errorf("cannot exec into multiple objects at a time")
|
||||
}
|
||||
|
||||
p.Pod, err = p.ExecutablePodFn(p.restClientGetter, obj, p.GetPodTimeout)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -30,6 +30,29 @@ run_kubectl_exec_pod_tests() {
|
||||
# POD abc should error since it doesn't exist
|
||||
kube::test::if_has_string "${output_message}" 'pods "abc" not found'
|
||||
|
||||
### Test execute multiple resources
|
||||
output_message=$(! kubectl exec -f - 2>&1 -- echo test << __EOF__
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: test2
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx
|
||||
__EOF__
|
||||
)
|
||||
kube::test::if_has_string "${output_message}" 'cannot exec into multiple objects at a time'
|
||||
|
||||
### Test execute existing POD
|
||||
# Create test-pod
|
||||
kubectl create -f hack/testdata/pod.yaml
|
||||
|
Loading…
Reference in New Issue
Block a user