mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 03:03:59 +00:00
Move proxy platformSetup call, and do LocalDetector setup from there
This commit is contained in:
parent
ebb0fdd4f6
commit
8abfa89e82
@ -567,6 +567,11 @@ func newProxyServer(config *kubeproxyconfig.KubeProxyConfiguration, master strin
|
||||
s.HealthzServer = healthcheck.NewProxierHealthServer(config.HealthzBindAddress, 2*config.IPTables.SyncPeriod.Duration, s.Recorder, s.NodeRef)
|
||||
}
|
||||
|
||||
err = s.platformSetup()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.Proxier, err = s.createProxier(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -706,12 +711,6 @@ func (s *ProxyServer) Run() error {
|
||||
// Start up a metrics server if requested
|
||||
serveMetrics(s.Config.MetricsBindAddress, s.Config.Mode, s.Config.EnableProfiling, errCh)
|
||||
|
||||
// Do platform-specific setup
|
||||
err := s.platformSetup()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
noProxyName, err := labels.NewRequirement(apis.LabelServiceProxyName, selection.DoesNotExist, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -63,6 +63,8 @@ import (
|
||||
// node after it is registered.
|
||||
var timeoutForNodePodCIDR = 5 * time.Minute
|
||||
|
||||
// platformApplyDefaults is called after parsing command-line flags and/or reading the
|
||||
// config file, to apply platform-specific default values to config.
|
||||
func (o *Options) platformApplyDefaults(config *proxyconfigapi.KubeProxyConfiguration) {
|
||||
if config.Mode == "" {
|
||||
klog.InfoS("Using iptables proxy")
|
||||
@ -76,21 +78,34 @@ func (o *Options) platformApplyDefaults(config *proxyconfigapi.KubeProxyConfigur
|
||||
klog.V(2).InfoS("DetectLocalMode", "localMode", string(config.DetectLocalMode))
|
||||
}
|
||||
|
||||
// createProxier creates the proxy.Provider
|
||||
func (s *ProxyServer) createProxier(config *proxyconfigapi.KubeProxyConfiguration) (proxy.Provider, error) {
|
||||
var proxier proxy.Provider
|
||||
var err error
|
||||
|
||||
if config.DetectLocalMode == proxyconfigapi.LocalModeNodeCIDR {
|
||||
// platformSetup is called after setting up the ProxyServer, but before creating the
|
||||
// Proxier. It should fill in any platform-specific fields and perform other
|
||||
// platform-specific setup.
|
||||
func (s *ProxyServer) platformSetup() error {
|
||||
if s.Config.DetectLocalMode == proxyconfigapi.LocalModeNodeCIDR {
|
||||
klog.InfoS("Watching for node, awaiting podCIDR allocation", "hostname", s.Hostname)
|
||||
node, err := waitForPodCIDR(s.Client, s.Hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
s.podCIDRs = node.Spec.PodCIDRs
|
||||
klog.InfoS("NodeInfo", "podCIDRs", node.Spec.PodCIDRs)
|
||||
}
|
||||
|
||||
err := s.setupConntrack()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
proxymetrics.RegisterMetrics()
|
||||
return nil
|
||||
}
|
||||
|
||||
// createProxier creates the proxy.Provider
|
||||
func (s *ProxyServer) createProxier(config *proxyconfigapi.KubeProxyConfiguration) (proxy.Provider, error) {
|
||||
var proxier proxy.Provider
|
||||
var err error
|
||||
|
||||
primaryProtocol := utiliptables.ProtocolIPv4
|
||||
if s.PrimaryIPFamily == v1.IPv6Protocol {
|
||||
primaryProtocol = utiliptables.ProtocolIPv6
|
||||
@ -271,7 +286,7 @@ func (s *ProxyServer) createProxier(config *proxyconfigapi.KubeProxyConfiguratio
|
||||
return proxier, nil
|
||||
}
|
||||
|
||||
func (s *ProxyServer) platformSetup() error {
|
||||
func (s *ProxyServer) setupConntrack() error {
|
||||
ct := &realConntracker{}
|
||||
|
||||
max, err := getConntrackMax(s.Config.Conntrack)
|
||||
@ -311,7 +326,6 @@ func (s *ProxyServer) platformSetup() error {
|
||||
}
|
||||
}
|
||||
|
||||
proxymetrics.RegisterMetrics()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -646,7 +646,7 @@ func TestGetConntrackMax(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyServer_createProxier(t *testing.T) {
|
||||
func TestProxyServer_platformSetup(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
node *v1.Node
|
||||
@ -683,9 +683,8 @@ func TestProxyServer_createProxier(t *testing.T) {
|
||||
v1.IPv6Protocol: net.IPv6zero,
|
||||
},
|
||||
}
|
||||
_, err := s.createProxier(tt.config)
|
||||
// TODO: mock the exec.Interface to not fail probing iptables
|
||||
if (err != nil) && !strings.Contains(err.Error(), "iptables is not supported for primary IP family") {
|
||||
err := s.platformSetup()
|
||||
if err != nil {
|
||||
t.Errorf("ProxyServer.createProxier() error = %v", err)
|
||||
return
|
||||
}
|
||||
|
@ -36,12 +36,22 @@ import (
|
||||
"k8s.io/kubernetes/pkg/proxy/winkernel"
|
||||
)
|
||||
|
||||
// platformApplyDefaults is called after parsing command-line flags and/or reading the
|
||||
// config file, to apply platform-specific default values to config.
|
||||
func (o *Options) platformApplyDefaults(config *proxyconfigapi.KubeProxyConfiguration) {
|
||||
if config.Mode == "" {
|
||||
config.Mode = proxyconfigapi.ProxyModeKernelspace
|
||||
}
|
||||
}
|
||||
|
||||
// platformSetup is called after setting up the ProxyServer, but before creating the
|
||||
// Proxier. It should fill in any platform-specific fields and perform other
|
||||
// platform-specific setup.
|
||||
func (s *ProxyServer) platformSetup() error {
|
||||
winkernel.RegisterMetrics()
|
||||
return nil
|
||||
}
|
||||
|
||||
// createProxier creates the proxy.Provider
|
||||
func (s *ProxyServer) createProxier(config *proxyconfigapi.KubeProxyConfiguration) (proxy.Provider, error) {
|
||||
var healthzPort int
|
||||
@ -93,11 +103,6 @@ func (s *ProxyServer) createProxier(config *proxyconfigapi.KubeProxyConfiguratio
|
||||
return proxier, nil
|
||||
}
|
||||
|
||||
func (s *ProxyServer) platformSetup() error {
|
||||
winkernel.RegisterMetrics()
|
||||
return nil
|
||||
}
|
||||
|
||||
func getDualStackMode(networkname string, compatTester winkernel.StackCompatTester) bool {
|
||||
return compatTester.DualStackCompatible(networkname)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user