diff --git a/hack/test-end-to-end.sh b/hack/test-end-to-end.sh index cd3811f5f5f2..4b65d8b7d5af 100755 --- a/hack/test-end-to-end.sh +++ b/hack/test-end-to-end.sh @@ -290,6 +290,14 @@ wait_for_command '[[ "$(osc get endpoints router -t "{{ if .endpoints }}{{ len . echo "[INFO] Validating routed app response..." validate_response "-s -k --resolve www.example.com:443:${CONTAINER_ACCESSIBLE_API_HOST} https://www.example.com" "Hello from OpenShift" 0.2 50 +# Remote command execution +registry_pod=$(osc get pod | grep docker-registry | awk '{print $1}') +osc exec -p ${registry_pod} whoami | grep root + +# Port forwarding +osc port-forward -p ${registry_pod} 5001:5000 & +wait_for_url_timed "http://localhost:5001/" "[INFO] Docker registry says: " $((10*TIME_SEC)) + # UI e2e tests can be found in assets/test/e2e if [[ "$TEST_ASSETS" == "true" ]]; then echo "[INFO] Running UI e2e tests..." diff --git a/pkg/cmd/cli/cli.go b/pkg/cmd/cli/cli.go index dafc77c89e55..a17c00fd61d7 100644 --- a/pkg/cmd/cli/cli.go +++ b/pkg/cmd/cli/cli.go @@ -76,6 +76,8 @@ func NewCommandCLI(name, fullName string) *cobra.Command { cmds.AddCommand(cmd.NewCmdUpdate(fullName, f, out)) cmds.AddCommand(cmd.NewCmdDelete(fullName, f, out)) cmds.AddCommand(cmd.NewCmdLog(fullName, f, out)) + cmds.AddCommand(cmd.NewCmdExec(fullName, f, os.Stdin, out, os.Stderr)) + cmds.AddCommand(cmd.NewCmdPortForward(fullName, f)) cmds.AddCommand(f.NewCmdProxy(out)) cmds.AddCommand(kubecmd.NewCmdNamespace(out)) cmds.AddCommand(cmd.NewCmdProject(f, out)) diff --git a/pkg/cmd/cli/cmd/wrappers.go b/pkg/cmd/cli/cmd/wrappers.go index cab666375c94..e2ffb4c42255 100644 --- a/pkg/cmd/cli/cmd/wrappers.go +++ b/pkg/cmd/cli/cmd/wrappers.go @@ -107,7 +107,7 @@ Examples: func NewCmdCreate(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command { cmd := f.NewCmdCreate(out) longDesc := `Create a resource by filename or stdin. - + JSON and YAML formats are accepted. Examples: @@ -121,3 +121,41 @@ Examples: cmd.Long = fmt.Sprintf(longDesc, fullName) return cmd } + +func NewCmdExec(fullName string, f *clientcmd.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command { + cmd := f.NewCmdExec(cmdIn, cmdOut, cmdErr) + longDesc := `Execute a command in a container. + +Examples: + + # get output from running 'date' in ruby-container from pod 123456-7890 + $ %[1]s exec -p 123456-7890 -c ruby-container date + + # switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod 123456-780 and sends stdout/stderr from 'bash' back to the client + $ %[1]s exec -p 123456-7890 -c ruby-container -i -t -- bash -il +` + cmd.Long = fmt.Sprintf(longDesc, fullName) + return cmd +} + +func NewCmdPortForward(fullName string, f *clientcmd.Factory) *cobra.Command { + cmd := f.NewCmdPortForward() + longDesc := `Forward 1 or more local ports to a pod. + +Examples: + + # listens on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod + $ %[1]s port-forward -p mypod 5000 6000 + + # listens on port 8888 locally, forwarding to 5000 in the pod + $ %[1]s port-forward -p mypod 8888:5000 + + # listens on a random port locally, forwarding to 5000 in the pod + $ %[1]s port-forward -p mypod :5000 + + # listens on a random port locally, forwarding to 5000 in the pod + $ %[1]s port-forward -p mypod 0:5000 +` + cmd.Long = fmt.Sprintf(longDesc, fullName) + return cmd +}