Commit a0872fbd authored by Brian Grant's avatar Brian Grant

Merge pull request #14287 from gmarek/mock-proxy

Refactor KubeProxy to allow mocking of all moving parts.
parents 95d4c70a 1c25c2cd
...@@ -19,13 +19,16 @@ limitations under the License. ...@@ -19,13 +19,16 @@ 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",
...@@ -33,10 +36,18 @@ func NewKubeProxy() *Server { ...@@ -33,10 +36,18 @@ func NewKubeProxy() *Server {
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 { }
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 s.Run(args)
},
} }
s.AddFlags(hks.Flags())
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,14 +18,18 @@ limitations under the License. ...@@ -18,14 +18,18 @@ 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,
...@@ -33,10 +37,18 @@ func NewKubeProxy() *Server { ...@@ -33,10 +37,18 @@ func NewKubeProxy() *Server {
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 { }
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 s.Run(args)
},
} }
s.AddFlags(hks.Flags())
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