mirror of https://github.com/k3s-io/k3s
Fix kubectl get error when both all-namespaces and namespace are provided.
As per kubectl get help, --namespace should be ignored with all-namespaces, but kubectl get pods --all-namespaces --namespace=<name-space> gives following error: "the namespace from the provided object "default" does not match the namespace "". You must pass '--namespace=default' to perform this operation." This commit fixes this error issue.pull/6/head
parent
1c6a223eaa
commit
c0e1623be2
|
@ -1491,6 +1491,33 @@ __EOF__
|
||||||
# Command
|
# Command
|
||||||
kubectl get pods --sort-by="{metadata.name}"
|
kubectl get pods --sort-by="{metadata.name}"
|
||||||
|
|
||||||
|
############################
|
||||||
|
# Kubectl --all-namespaces #
|
||||||
|
############################
|
||||||
|
|
||||||
|
# Pre-condition: the "default" namespace exists
|
||||||
|
kube::test::get_object_assert namespaces "{{range.items}}{{$id_field}}:{{end}}" 'default:'
|
||||||
|
|
||||||
|
### Create POD
|
||||||
|
# Pre-condition: no POD exists
|
||||||
|
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||||
|
# Command
|
||||||
|
kubectl create "${kube_flags[@]}" -f docs/admin/limitrange/valid-pod.yaml
|
||||||
|
# Post-condition: valid-pod is created
|
||||||
|
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'valid-pod:'
|
||||||
|
|
||||||
|
### Verify a specific namespace is ignored when all-namespaces is provided
|
||||||
|
# Command
|
||||||
|
kubectl get pods --all-namespaces --namespace=default
|
||||||
|
|
||||||
|
### Clean up
|
||||||
|
# Pre-condition: valid-pod exists
|
||||||
|
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'valid-pod:'
|
||||||
|
# Command
|
||||||
|
kubectl delete "${kube_flags[@]}" pod valid-pod --grace-period=0
|
||||||
|
# Post-condition: valid-pod doesn't exist
|
||||||
|
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||||
|
|
||||||
kube::test::clear_all
|
kube::test::clear_all
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,10 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if allNamespaces {
|
||||||
|
enforceNamespace = false
|
||||||
|
}
|
||||||
|
|
||||||
if len(args) == 0 && len(options.Filenames) == 0 {
|
if len(args) == 0 && len(options.Filenames) == 0 {
|
||||||
fmt.Fprint(out, "You must specify the type of resource to get. ", valid_resources)
|
fmt.Fprint(out, "You must specify the type of resource to get. ", valid_resources)
|
||||||
return cmdutil.UsageError(cmd, "Required resource not specified.")
|
return cmdutil.UsageError(cmd, "Required resource not specified.")
|
||||||
|
|
Loading…
Reference in New Issue