k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cmd/kube-proxy/app/server_windows.go (about) 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 "context" 26 "errors" 27 "fmt" 28 "net" 29 30 // Enable pprof HTTP handlers. 31 _ "net/http/pprof" 32 33 v1 "k8s.io/api/core/v1" 34 "k8s.io/kubernetes/pkg/proxy" 35 proxyconfigapi "k8s.io/kubernetes/pkg/proxy/apis/config" 36 "k8s.io/kubernetes/pkg/proxy/winkernel" 37 ) 38 39 // platformApplyDefaults is called after parsing command-line flags and/or reading the 40 // config file, to apply platform-specific default values to config. 41 func (o *Options) platformApplyDefaults(config *proxyconfigapi.KubeProxyConfiguration) { 42 if config.Mode == "" { 43 config.Mode = proxyconfigapi.ProxyModeKernelspace 44 } 45 if config.Winkernel.RootHnsEndpointName == "" { 46 config.Winkernel.RootHnsEndpointName = "cbr0" 47 } 48 } 49 50 // platformSetup is called after setting up the ProxyServer, but before creating the 51 // Proxier. It should fill in any platform-specific fields and perform other 52 // platform-specific setup. 53 func (s *ProxyServer) platformSetup(ctx context.Context) error { 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(ctx context.Context) (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(ctx context.Context, 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(ctx context.Context, 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 }