Refactor KubeProxy to allow mocking of all moving parts.
This commit is contained in:
@@ -19,24 +19,35 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
kubeproxy "k8s.io/kubernetes/cmd/kube-proxy/app"
|
||||
)
|
||||
|
||||
// NewKubeProxy creates a new hyperkube Server object that includes the
|
||||
// description and flags.
|
||||
func NewKubeProxy() *Server {
|
||||
s := kubeproxy.NewProxyServer()
|
||||
config := kubeproxy.NewProxyConfig()
|
||||
|
||||
hks := Server{
|
||||
SimpleUsage: "proxy",
|
||||
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.
|
||||
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
|
||||
}
|
||||
|
Reference in New Issue
Block a user