mirror of https://github.com/k3s-io/k3s
Fix NameFromCommandArgs when passing command after --
parent
974978a7c7
commit
59fc12006b
|
@ -328,8 +328,13 @@ func createAndRefresh(info *resource.Info) error {
|
||||||
|
|
||||||
// NameFromCommandArgs is a utility function for commands that assume the first argument is a resource name
|
// NameFromCommandArgs is a utility function for commands that assume the first argument is a resource name
|
||||||
func NameFromCommandArgs(cmd *cobra.Command, args []string) (string, error) {
|
func NameFromCommandArgs(cmd *cobra.Command, args []string) (string, error) {
|
||||||
if len(args) != 1 {
|
argsLen := cmd.ArgsLenAtDash()
|
||||||
return "", cmdutil.UsageErrorf(cmd, "exactly one NAME is required, got %d", len(args))
|
// ArgsLenAtDash returns -1 when -- was not specified
|
||||||
|
if argsLen == -1 {
|
||||||
|
argsLen = len(args)
|
||||||
|
}
|
||||||
|
if argsLen != 1 {
|
||||||
|
return "", cmdutil.UsageErrorf(cmd, "exactly one NAME is required, got %d", argsLen)
|
||||||
}
|
}
|
||||||
return args[0], nil
|
return args[0], nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,6 +212,16 @@ run_deployment_tests() {
|
||||||
# Clean up
|
# Clean up
|
||||||
kubectl delete deployment test-nginx-apps "${kube_flags[@]}"
|
kubectl delete deployment test-nginx-apps "${kube_flags[@]}"
|
||||||
|
|
||||||
|
### Test kubectl create deployment with image and command
|
||||||
|
# Pre-Condition: No deployment exists.
|
||||||
|
kube::test::get_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||||
|
# Command
|
||||||
|
kubectl create deployment nginx-with-command --image=k8s.gcr.io/nginx:test-cmd -- /bin/sleep infinity
|
||||||
|
# Post-Condition: Deployment "nginx" is created.
|
||||||
|
kube::test::get_object_assert 'deploy nginx-with-command' "{{$container_name_field}}" 'nginx'
|
||||||
|
# Clean up
|
||||||
|
kubectl delete deployment nginx-with-command "${kube_flags[@]}"
|
||||||
|
|
||||||
### Test kubectl create deployment should not fail validation
|
### Test kubectl create deployment should not fail validation
|
||||||
# Pre-Condition: No deployment exists.
|
# Pre-Condition: No deployment exists.
|
||||||
kube::test::get_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" ''
|
kube::test::get_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||||
|
|
Loading…
Reference in New Issue