Update Exec and Portforward client to use pod subresource

This commit is contained in:
Cesar Wong
2015-05-04 13:13:55 -04:00
parent 619332d58e
commit d954c31b22
5 changed files with 342 additions and 56 deletions

View File

@@ -21,6 +21,7 @@ import (
"os/signal"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/portforward"
cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/golang/glog"
@@ -49,7 +50,7 @@ func NewCmdPortForward(f *cmdutil.Factory) *cobra.Command {
Long: "Forward one or more local ports to a pod.",
Example: portforward_example,
Run: func(cmd *cobra.Command, args []string) {
err := RunPortForward(f, cmd, args)
err := RunPortForward(f, cmd, args, &defaultPortForwarder{})
cmdutil.CheckErr(err)
},
}
@@ -59,12 +60,25 @@ func NewCmdPortForward(f *cmdutil.Factory) *cobra.Command {
return cmd
}
func RunPortForward(f *cmdutil.Factory, cmd *cobra.Command, args []string) error {
type portForwarder interface {
ForwardPorts(req *client.Request, config *client.Config, ports []string, stopChan <-chan struct{}) error
}
type defaultPortForwarder struct{}
func (*defaultPortForwarder) ForwardPorts(req *client.Request, config *client.Config, ports []string, stopChan <-chan struct{}) error {
fw, err := portforward.New(req, config, ports, stopChan)
if err != nil {
return err
}
return fw.ForwardPorts()
}
func RunPortForward(f *cmdutil.Factory, cmd *cobra.Command, args []string, fw portForwarder) error {
podName := cmdutil.GetFlagString(cmd, "pod")
if len(podName) == 0 {
return cmdutil.UsageError(cmd, "POD is required for exec")
}
if len(args) < 1 {
return cmdutil.UsageError(cmd, "at least 1 PORT is required for port-forward")
}
@@ -104,15 +118,10 @@ func RunPortForward(f *cmdutil.Factory, cmd *cobra.Command, args []string) error
}()
req := client.RESTClient.Get().
Prefix("proxy").
Resource("nodes").
Name(pod.Spec.Host).
Suffix("portForward", namespace, podName)
Resource("pods").
Namespace(namespace).
Name(pod.Name).
SubResource("portforward")
pf, err := portforward.New(req, config, args, stopCh)
if err != nil {
return err
}
return pf.ForwardPorts()
return fw.ForwardPorts(req, config, args, stopCh)
}