Commit 1c25c2cd authored by gmarek's avatar gmarek

Refactor KubeProxy to allow mocking of all moving parts.

parent 45a8b5f9
...@@ -19,24 +19,35 @@ limitations under the License. ...@@ -19,24 +19,35 @@ limitations under the License.
package main package main
import ( import (
"fmt"
"os"
kubeproxy "k8s.io/kubernetes/cmd/kube-proxy/app" kubeproxy "k8s.io/kubernetes/cmd/kube-proxy/app"
) )
// NewKubeProxy creates a new hyperkube Server object that includes the // NewKubeProxy creates a new hyperkube Server object that includes the
// description and flags. // description and flags.
func NewKubeProxy() *Server { func NewKubeProxy() *Server {
s := kubeproxy.NewProxyServer() config := kubeproxy.NewProxyConfig()
hks := Server{ hks := Server{
SimpleUsage: "proxy", SimpleUsage: "proxy",
Long: `The Kubernetes proxy server is responsible for taking traffic directed at Long: `The Kubernetes proxy server is responsible for taking traffic directed at
services and forwarding it to the appropriate pods. It generally runs on services and forwarding it to the appropriate pods. It generally runs on
nodes next to the Kubelet and proxies traffic from local pods to remote pods. nodes next to the Kubelet and proxies traffic from local pods to remote pods.
It is also used when handling incoming external traffic.`, It is also used when handling incoming external traffic.`,
Run: func(_ *Server, args []string) error {
return s.Run(args)
},
} }
s.AddFlags(hks.Flags())
config.AddFlags(hks.Flags())
s, err := kubeproxy.NewProxyServerDefault(config)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
hks.Run = func(_ *Server, args []string) error {
return s.Run(args)
}
return &hks return &hks
} }
...@@ -35,8 +35,8 @@ func init() { ...@@ -35,8 +35,8 @@ func init() {
func main() { func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
s := app.NewProxyServer() config := app.NewProxyConfig()
s.AddFlags(pflag.CommandLine) config.AddFlags(pflag.CommandLine)
util.InitFlags() util.InitFlags()
util.InitLogs() util.InitLogs()
...@@ -44,7 +44,13 @@ func main() { ...@@ -44,7 +44,13 @@ func main() {
verflag.PrintAndExitIfRequested() verflag.PrintAndExitIfRequested()
if err := s.Run(pflag.CommandLine.Args()); err != nil { s, err := app.NewProxyServerDefault(config)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
if err = s.Run(pflag.CommandLine.Args()); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err) fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1) os.Exit(1)
} }
......
...@@ -18,25 +18,37 @@ limitations under the License. ...@@ -18,25 +18,37 @@ limitations under the License.
package main package main
import ( import (
"fmt"
"os"
kubeproxy "k8s.io/kubernetes/cmd/kube-proxy/app" kubeproxy "k8s.io/kubernetes/cmd/kube-proxy/app"
"k8s.io/kubernetes/contrib/mesos/pkg/hyperkube" "k8s.io/kubernetes/contrib/mesos/pkg/hyperkube"
) )
// NewKubeProxy creates a new hyperkube Server object that includes the // NewKubeProxy creates a new hyperkube Server object that includes the
// description and flags. // description and flags.
func NewKubeProxy() *Server { func NewKubeProxy() *Server {
s := kubeproxy.NewProxyServer() config := kubeproxy.NewProxyConfig()
hks := Server{ hks := Server{
SimpleUsage: hyperkube.CommandProxy, SimpleUsage: hyperkube.CommandProxy,
Long: `The Kubernetes proxy server is responsible for taking traffic directed at Long: `The Kubernetes proxy server is responsible for taking traffic directed at
services and forwarding it to the appropriate pods. It generally runs on services and forwarding it to the appropriate pods. It generally runs on
nodes next to the Kubelet and proxies traffic from local pods to remote pods. nodes next to the Kubelet and proxies traffic from local pods to remote pods.
It is also used when handling incoming external traffic.`, It is also used when handling incoming external traffic.`,
Run: func(_ *Server, args []string) error {
return s.Run(args)
},
} }
s.AddFlags(hks.Flags())
config.AddFlags(hks.Flags())
s, err := kubeproxy.NewProxyServerDefault(config)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
hks.Run = func(_ *Server, args []string) error {
return s.Run(args)
}
return &hks return &hks
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment