diff --git a/pkg/kubectl/cmd/create/create.go b/pkg/kubectl/cmd/create/create.go index d4ae51b77f..e69fe6493b 100644 --- a/pkg/kubectl/cmd/create/create.go +++ b/pkg/kubectl/cmd/create/create.go @@ -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 func NameFromCommandArgs(cmd *cobra.Command, args []string) (string, error) { - if len(args) != 1 { - return "", cmdutil.UsageErrorf(cmd, "exactly one NAME is required, got %d", len(args)) + argsLen := cmd.ArgsLenAtDash() + // 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 } diff --git a/test/cmd/apps.sh b/test/cmd/apps.sh index 2269cf5229..5b4c66aa91 100755 --- a/test/cmd/apps.sh +++ b/test/cmd/apps.sh @@ -212,6 +212,16 @@ run_deployment_tests() { # Clean up 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 # Pre-Condition: No deployment exists. kube::test::get_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" ''