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