Added automatic seletion of userspace proxy mode depending on the OS kube-proxy is running.
This commit is contained in:
		| @@ -29,6 +29,7 @@ go_library( | ||||
|         "//pkg/proxy/config:go_default_library", | ||||
|         "//pkg/proxy/iptables:go_default_library", | ||||
|         "//pkg/proxy/userspace:go_default_library", | ||||
|         "//pkg/proxy/winuserspace:go_default_library", | ||||
|         "//pkg/types:go_default_library", | ||||
|         "//pkg/util/configz:go_default_library", | ||||
|         "//pkg/util/dbus:go_default_library", | ||||
| @@ -36,6 +37,7 @@ go_library( | ||||
|         "//pkg/util/iptables:go_default_library", | ||||
|         "//pkg/util/mount:go_default_library", | ||||
|         "//pkg/util/net:go_default_library", | ||||
|         "//pkg/util/netsh:go_default_library", | ||||
|         "//pkg/util/node:go_default_library", | ||||
|         "//pkg/util/oom:go_default_library", | ||||
|         "//pkg/util/resourcecontainer:go_default_library", | ||||
|   | ||||
| @@ -39,12 +39,14 @@ import ( | ||||
| 	proxyconfig "k8s.io/kubernetes/pkg/proxy/config" | ||||
| 	"k8s.io/kubernetes/pkg/proxy/iptables" | ||||
| 	"k8s.io/kubernetes/pkg/proxy/userspace" | ||||
| 	"k8s.io/kubernetes/pkg/proxy/winuserspace" | ||||
| 	"k8s.io/kubernetes/pkg/types" | ||||
| 	"k8s.io/kubernetes/pkg/util/configz" | ||||
| 	utildbus "k8s.io/kubernetes/pkg/util/dbus" | ||||
| 	"k8s.io/kubernetes/pkg/util/exec" | ||||
| 	utiliptables "k8s.io/kubernetes/pkg/util/iptables" | ||||
| 	utilnet "k8s.io/kubernetes/pkg/util/net" | ||||
| 	utilnetsh "k8s.io/kubernetes/pkg/util/netsh" | ||||
| 	nodeutil "k8s.io/kubernetes/pkg/util/node" | ||||
| 	"k8s.io/kubernetes/pkg/util/oom" | ||||
| 	"k8s.io/kubernetes/pkg/util/resourcecontainer" | ||||
| @@ -136,10 +138,19 @@ func NewProxyServerDefault(config *options.ProxyServerConfig) (*ProxyServer, err | ||||
| 		protocol = utiliptables.ProtocolIpv6 | ||||
| 	} | ||||
|  | ||||
| 	var netshInterface utilnetsh.Interface | ||||
| 	var iptInterface utiliptables.Interface | ||||
| 	var dbus utildbus.Interface | ||||
|  | ||||
| 	// Create a iptables utils. | ||||
| 	execer := exec.New() | ||||
| 	dbus := utildbus.New() | ||||
| 	iptInterface := utiliptables.New(execer, dbus, protocol) | ||||
|  | ||||
| 	if runtime.GOOS == "windows" { | ||||
| 		netshInterface = utilnetsh.New(execer) | ||||
| 	} else { | ||||
| 		dbus = utildbus.New() | ||||
| 		iptInterface = utiliptables.New(execer, dbus, protocol) | ||||
| 	} | ||||
|  | ||||
| 	// We omit creation of pretty much everything if we run in cleanup mode | ||||
| 	if config.CleanupAndExit { | ||||
| @@ -223,24 +234,44 @@ func NewProxyServerDefault(config *options.ProxyServerConfig) (*ProxyServer, err | ||||
| 		// set EndpointsConfigHandler to our loadBalancer | ||||
| 		endpointsHandler = loadBalancer | ||||
|  | ||||
| 		proxierUserspace, err := userspace.NewProxier( | ||||
| 			loadBalancer, | ||||
| 			net.ParseIP(config.BindAddress), | ||||
| 			iptInterface, | ||||
| 			*utilnet.ParsePortRangeOrDie(config.PortRange), | ||||
| 			config.IPTablesSyncPeriod.Duration, | ||||
| 			config.IPTablesMinSyncPeriod.Duration, | ||||
| 			config.UDPIdleTimeout.Duration, | ||||
| 		) | ||||
| 		var proxierUserspace proxy.ProxyProvider | ||||
|  | ||||
| 		if runtime.GOOS == "windows" { | ||||
| 			proxierUserspace, err = winuserspace.NewProxier( | ||||
| 				loadBalancer, | ||||
| 				net.ParseIP(config.BindAddress), | ||||
| 				netshInterface, | ||||
| 				*utilnet.ParsePortRangeOrDie(config.PortRange), | ||||
| 				// TODO @pires replace below with default values, if applicable | ||||
| 				config.IPTablesSyncPeriod.Duration, | ||||
| 				config.UDPIdleTimeout.Duration, | ||||
| 			) | ||||
| 		} else { | ||||
| 			proxierUserspace, err = userspace.NewProxier( | ||||
| 				loadBalancer, | ||||
| 				net.ParseIP(config.BindAddress), | ||||
| 				iptInterface, | ||||
| 				*utilnet.ParsePortRangeOrDie(config.PortRange), | ||||
| 				config.IPTablesSyncPeriod.Duration, | ||||
| 				config.IPTablesMinSyncPeriod.Duration, | ||||
| 				config.UDPIdleTimeout.Duration, | ||||
| 			) | ||||
| 		} | ||||
| 		if err != nil { | ||||
| 			glog.Fatalf("Unable to create proxier: %v", err) | ||||
| 		} | ||||
| 		proxier = proxierUserspace | ||||
| 		// Remove artifacts from the pure-iptables Proxier. | ||||
| 		glog.V(0).Info("Tearing down pure-iptables proxy rules.") | ||||
| 		iptables.CleanupLeftovers(iptInterface) | ||||
| 		// Remove artifacts from the pure-iptables Proxier, if not on Windows. | ||||
| 		if runtime.GOOS != "windows" { | ||||
| 			glog.V(0).Info("Tearing down pure-iptables proxy rules.") | ||||
| 			iptables.CleanupLeftovers(iptInterface) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// Add iptables reload function, if not on Windows. | ||||
| 	if runtime.GOOS != "windows" { | ||||
| 		iptInterface.AddReloadFunc(proxier.Sync) | ||||
| 	} | ||||
| 	iptInterface.AddReloadFunc(proxier.Sync) | ||||
|  | ||||
| 	// Create configs (i.e. Watches for Services and Endpoints) | ||||
| 	// Note: RegisterHandler() calls need to happen before creation of Sources because sources | ||||
| @@ -300,7 +331,7 @@ func (s *ProxyServer) Run() error { | ||||
| 	} | ||||
|  | ||||
| 	// Tune conntrack, if requested | ||||
| 	if s.Conntracker != nil { | ||||
| 	if s.Conntracker != nil && runtime.GOOS != "windows" { | ||||
| 		max, err := getConntrackMax(s.Config) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Paulo Pires
					Paulo Pires