...

Source file src/k8s.io/kubernetes/cmd/kube-proxy/app/server_windows.go

Documentation: k8s.io/kubernetes/cmd/kube-proxy/app

     1  //go:build windows
     2  // +build windows
     3  
     4  /*
     5  Copyright 2014 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  // Package app does all of the work necessary to configure and run a
    21  // Kubernetes app process.
    22  package app
    23  
    24  import (
    25  	"errors"
    26  	"fmt"
    27  	"net"
    28  
    29  	// Enable pprof HTTP handlers.
    30  	_ "net/http/pprof"
    31  
    32  	v1 "k8s.io/api/core/v1"
    33  	"k8s.io/kubernetes/pkg/proxy"
    34  	proxyconfigapi "k8s.io/kubernetes/pkg/proxy/apis/config"
    35  	"k8s.io/kubernetes/pkg/proxy/winkernel"
    36  )
    37  
    38  // platformApplyDefaults is called after parsing command-line flags and/or reading the
    39  // config file, to apply platform-specific default values to config.
    40  func (o *Options) platformApplyDefaults(config *proxyconfigapi.KubeProxyConfiguration) {
    41  	if config.Mode == "" {
    42  		config.Mode = proxyconfigapi.ProxyModeKernelspace
    43  	}
    44  	if config.Winkernel.RootHnsEndpointName == "" {
    45  		config.Winkernel.RootHnsEndpointName = "cbr0"
    46  	}
    47  }
    48  
    49  // platformSetup is called after setting up the ProxyServer, but before creating the
    50  // Proxier. It should fill in any platform-specific fields and perform other
    51  // platform-specific setup.
    52  func (s *ProxyServer) platformSetup() error {
    53  	winkernel.RegisterMetrics()
    54  	// Preserve backward-compatibility with the old secondary IP behavior
    55  	if s.PrimaryIPFamily == v1.IPv4Protocol {
    56  		s.NodeIPs[v1.IPv6Protocol] = net.IPv6zero
    57  	} else {
    58  		s.NodeIPs[v1.IPv4Protocol] = net.IPv4zero
    59  	}
    60  	return nil
    61  }
    62  
    63  // platformCheckSupported is called immediately before creating the Proxier, to check
    64  // what IP families are supported (and whether the configuration is usable at all).
    65  func (s *ProxyServer) platformCheckSupported() (ipv4Supported, ipv6Supported, dualStackSupported bool, err error) {
    66  	// Check if Kernel proxier can be used at all
    67  	_, err = winkernel.CanUseWinKernelProxier(winkernel.WindowsKernelCompatTester{})
    68  	if err != nil {
    69  		return false, false, false, err
    70  	}
    71  
    72  	// winkernel always supports both single-stack IPv4 and single-stack IPv6, but may
    73  	// not support dual-stack.
    74  	ipv4Supported = true
    75  	ipv6Supported = true
    76  
    77  	compatTester := winkernel.DualStackCompatTester{}
    78  	dualStackSupported = compatTester.DualStackCompatible(s.Config.Winkernel.NetworkName)
    79  
    80  	return
    81  }
    82  
    83  // createProxier creates the proxy.Provider
    84  func (s *ProxyServer) createProxier(config *proxyconfigapi.KubeProxyConfiguration, dualStackMode, initOnly bool) (proxy.Provider, error) {
    85  	if initOnly {
    86  		return nil, fmt.Errorf("--init-only is not implemented on Windows")
    87  	}
    88  
    89  	var proxier proxy.Provider
    90  	var err error
    91  
    92  	if dualStackMode {
    93  		proxier, err = winkernel.NewDualStackProxier(
    94  			config.IPTables.SyncPeriod.Duration,
    95  			config.IPTables.MinSyncPeriod.Duration,
    96  			s.Hostname,
    97  			s.NodeIPs,
    98  			s.Recorder,
    99  			s.HealthzServer,
   100  			config.HealthzBindAddress,
   101  			config.Winkernel,
   102  		)
   103  	} else {
   104  		proxier, err = winkernel.NewProxier(
   105  			s.PrimaryIPFamily,
   106  			config.IPTables.SyncPeriod.Duration,
   107  			config.IPTables.MinSyncPeriod.Duration,
   108  			s.Hostname,
   109  			s.NodeIPs[s.PrimaryIPFamily],
   110  			s.Recorder,
   111  			s.HealthzServer,
   112  			config.HealthzBindAddress,
   113  			config.Winkernel,
   114  		)
   115  	}
   116  	if err != nil {
   117  		return nil, fmt.Errorf("unable to create proxier: %v", err)
   118  	}
   119  
   120  	return proxier, nil
   121  }
   122  
   123  // platformCleanup removes stale kube-proxy rules that can be safely removed.
   124  func platformCleanup(mode proxyconfigapi.ProxyMode, cleanupAndExit bool) error {
   125  	if cleanupAndExit {
   126  		return errors.New("--cleanup-and-exit is not implemented on Windows")
   127  	}
   128  	return nil
   129  }
   130  

View as plain text