mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #73380 from vllry/kube-proxy-cleanup
Superficial kube-proxy cleanup
This commit is contained in:
		@@ -129,7 +129,7 @@ func isSysFSWritable() (bool, error) {
 | 
				
			|||||||
		return false, errReadOnlySysFS
 | 
							return false, errReadOnlySysFS
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return false, errors.New("No sysfs mounted")
 | 
						return false, errors.New("no sysfs mounted")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func readIntStringFile(filename string) (int, error) {
 | 
					func readIntStringFile(filename string) (int, error) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,7 +28,7 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/core/v1"
 | 
						"k8s.io/api/core/v1"
 | 
				
			||||||
	v1meta "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						v1meta "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/runtime"
 | 
						"k8s.io/apimachinery/pkg/runtime"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/runtime/serializer"
 | 
						"k8s.io/apimachinery/pkg/runtime/serializer"
 | 
				
			||||||
@@ -39,7 +39,7 @@ import (
 | 
				
			|||||||
	"k8s.io/apiserver/pkg/server/mux"
 | 
						"k8s.io/apiserver/pkg/server/mux"
 | 
				
			||||||
	"k8s.io/apiserver/pkg/server/routes"
 | 
						"k8s.io/apiserver/pkg/server/routes"
 | 
				
			||||||
	utilfeature "k8s.io/apiserver/pkg/util/feature"
 | 
						utilfeature "k8s.io/apiserver/pkg/util/feature"
 | 
				
			||||||
	informers "k8s.io/client-go/informers"
 | 
						"k8s.io/client-go/informers"
 | 
				
			||||||
	clientset "k8s.io/client-go/kubernetes"
 | 
						clientset "k8s.io/client-go/kubernetes"
 | 
				
			||||||
	v1core "k8s.io/client-go/kubernetes/typed/core/v1"
 | 
						v1core "k8s.io/client-go/kubernetes/typed/core/v1"
 | 
				
			||||||
	"k8s.io/client-go/rest"
 | 
						"k8s.io/client-go/rest"
 | 
				
			||||||
@@ -352,6 +352,7 @@ func (o *Options) writeConfigFile() error {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// TODO handle error
 | 
				
			||||||
	defer configFile.Close()
 | 
						defer configFile.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := encoder.Encode(o.config, configFile); err != nil {
 | 
						if err := encoder.Encode(o.config, configFile); err != nil {
 | 
				
			||||||
@@ -414,11 +415,11 @@ func (o *Options) loadConfig(data []byte) (*kubeproxyconfig.KubeProxyConfigurati
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	config, ok := configObj.(*kubeproxyconfig.KubeProxyConfiguration)
 | 
						proxyConfig, ok := configObj.(*kubeproxyconfig.KubeProxyConfiguration)
 | 
				
			||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		return nil, fmt.Errorf("got unexpected config type: %v", gvk)
 | 
							return nil, fmt.Errorf("got unexpected config type: %v", gvk)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return config, nil
 | 
						return proxyConfig, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (o *Options) ApplyDefaults(in *kubeproxyconfig.KubeProxyConfiguration) (*kubeproxyconfig.KubeProxyConfiguration, error) {
 | 
					func (o *Options) ApplyDefaults(in *kubeproxyconfig.KubeProxyConfiguration) (*kubeproxyconfig.KubeProxyConfiguration, error) {
 | 
				
			||||||
@@ -478,6 +479,7 @@ with the apiserver API to configure the proxy.`,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	opts.AddFlags(cmd.Flags())
 | 
						opts.AddFlags(cmd.Flags())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// TODO handle error
 | 
				
			||||||
	cmd.MarkFlagFilename("config", "yaml", "yml", "json")
 | 
						cmd.MarkFlagFilename("config", "yaml", "yml", "json")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return cmd
 | 
						return cmd
 | 
				
			||||||
@@ -534,7 +536,6 @@ func createClients(config componentbaseconfig.ClientConnectionConfiguration, mas
 | 
				
			|||||||
	kubeConfig.AcceptContentTypes = config.AcceptContentTypes
 | 
						kubeConfig.AcceptContentTypes = config.AcceptContentTypes
 | 
				
			||||||
	kubeConfig.ContentType = config.ContentType
 | 
						kubeConfig.ContentType = config.ContentType
 | 
				
			||||||
	kubeConfig.QPS = config.QPS
 | 
						kubeConfig.QPS = config.QPS
 | 
				
			||||||
	//TODO make config struct use int instead of int32?
 | 
					 | 
				
			||||||
	kubeConfig.Burst = int(config.Burst)
 | 
						kubeConfig.Burst = int(config.Burst)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	client, err := clientset.NewForConfig(kubeConfig)
 | 
						client, err := clientset.NewForConfig(kubeConfig)
 | 
				
			||||||
@@ -560,7 +561,7 @@ func (s *ProxyServer) Run() error {
 | 
				
			|||||||
		encounteredError = iptables.CleanupLeftovers(s.IptInterface) || encounteredError
 | 
							encounteredError = iptables.CleanupLeftovers(s.IptInterface) || encounteredError
 | 
				
			||||||
		encounteredError = ipvs.CleanupLeftovers(s.IpvsInterface, s.IptInterface, s.IpsetInterface, s.CleanupIPVS) || encounteredError
 | 
							encounteredError = ipvs.CleanupLeftovers(s.IpvsInterface, s.IptInterface, s.IpsetInterface, s.CleanupIPVS) || encounteredError
 | 
				
			||||||
		if encounteredError {
 | 
							if encounteredError {
 | 
				
			||||||
			return errors.New("encountered an error while tearing down rules.")
 | 
								return errors.New("encountered an error while tearing down rules")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -594,18 +595,18 @@ func (s *ProxyServer) Run() error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Start up a metrics server if requested
 | 
						// Start up a metrics server if requested
 | 
				
			||||||
	if len(s.MetricsBindAddress) > 0 {
 | 
						if len(s.MetricsBindAddress) > 0 {
 | 
				
			||||||
		mux := mux.NewPathRecorderMux("kube-proxy")
 | 
							proxyMux := mux.NewPathRecorderMux("kube-proxy")
 | 
				
			||||||
		healthz.InstallHandler(mux)
 | 
							healthz.InstallHandler(proxyMux)
 | 
				
			||||||
		mux.HandleFunc("/proxyMode", func(w http.ResponseWriter, r *http.Request) {
 | 
							proxyMux.HandleFunc("/proxyMode", func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
			fmt.Fprintf(w, "%s", s.ProxyMode)
 | 
								fmt.Fprintf(w, "%s", s.ProxyMode)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		mux.Handle("/metrics", prometheus.Handler())
 | 
							proxyMux.Handle("/metrics", prometheus.Handler())
 | 
				
			||||||
		if s.EnableProfiling {
 | 
							if s.EnableProfiling {
 | 
				
			||||||
			routes.Profiling{}.Install(mux)
 | 
								routes.Profiling{}.Install(proxyMux)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		configz.InstallHandler(mux)
 | 
							configz.InstallHandler(proxyMux)
 | 
				
			||||||
		go wait.Until(func() {
 | 
							go wait.Until(func() {
 | 
				
			||||||
			err := http.ListenAndServe(s.MetricsBindAddress, mux)
 | 
								err := http.ListenAndServe(s.MetricsBindAddress, proxyMux)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				utilruntime.HandleError(fmt.Errorf("starting metrics server failed: %v", err))
 | 
									utilruntime.HandleError(fmt.Errorf("starting metrics server failed: %v", err))
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -45,7 +45,7 @@ func Test_getProxyMode(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{ // flag says iptables, error detecting version
 | 
							{ // flag says iptables, error detecting version
 | 
				
			||||||
			flag:          "iptables",
 | 
								flag:          "iptables",
 | 
				
			||||||
			iptablesError: fmt.Errorf("oops!"),
 | 
								iptablesError: fmt.Errorf("flag says iptables, error detecting version"),
 | 
				
			||||||
			expected:      proxyModeUserspace,
 | 
								expected:      proxyModeUserspace,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{ // flag says iptables, version too low
 | 
							{ // flag says iptables, version too low
 | 
				
			||||||
@@ -67,7 +67,7 @@ func Test_getProxyMode(t *testing.T) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		{ // detect, error
 | 
							{ // detect, error
 | 
				
			||||||
			flag:          "",
 | 
								flag:          "",
 | 
				
			||||||
			iptablesError: fmt.Errorf("oops!"),
 | 
								iptablesError: fmt.Errorf("oops"),
 | 
				
			||||||
			expected:      proxyModeUserspace,
 | 
								expected:      proxyModeUserspace,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{ // detect, version too low
 | 
							{ // detect, version too low
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user