mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
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.
This commit is contained in:
parent
3e26e104bd
commit
832644f0b3
@ -33,6 +33,7 @@ import (
|
|||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/remotecommand"
|
"k8s.io/client-go/tools/remotecommand"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
"k8s.io/kubectl/pkg/cmd/util/podcmd"
|
"k8s.io/kubectl/pkg/cmd/util/podcmd"
|
||||||
"k8s.io/kubectl/pkg/polymorphichelpers"
|
"k8s.io/kubectl/pkg/polymorphichelpers"
|
||||||
@ -310,6 +311,10 @@ func (p *ExecOptions) Run() error {
|
|||||||
return err
|
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)
|
p.Pod, err = p.ExecutablePodFn(p.restClientGetter, obj, p.GetPodTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -30,6 +30,29 @@ run_kubectl_exec_pod_tests() {
|
|||||||
# POD abc should error since it doesn't exist
|
# POD abc should error since it doesn't exist
|
||||||
kube::test::if_has_string "${output_message}" 'pods "abc" not found'
|
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
|
### Test execute existing POD
|
||||||
# Create test-pod
|
# Create test-pod
|
||||||
kubectl create -f hack/testdata/pod.yaml
|
kubectl create -f hack/testdata/pod.yaml
|
||||||
|
Loading…
Reference in New Issue
Block a user