Skip to content

Commit 40a0647

Browse files
authored
Merge pull request kubernetes#73380 from vllry/kube-proxy-cleanup
Superficial kube-proxy cleanup
2 parents 7131617 + a23e442 commit 40a0647

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

cmd/kube-proxy/app/conntrack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func isSysFSWritable() (bool, error) {
129129
return false, errReadOnlySysFS
130130
}
131131

132-
return false, errors.New("No sysfs mounted")
132+
return false, errors.New("no sysfs mounted")
133133
}
134134

135135
func readIntStringFile(filename string) (int, error) {

cmd/kube-proxy/app/server.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"strings"
2929
"time"
3030

31-
v1 "k8s.io/api/core/v1"
31+
"k8s.io/api/core/v1"
3232
v1meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3333
"k8s.io/apimachinery/pkg/runtime"
3434
"k8s.io/apimachinery/pkg/runtime/serializer"
@@ -39,7 +39,7 @@ import (
3939
"k8s.io/apiserver/pkg/server/mux"
4040
"k8s.io/apiserver/pkg/server/routes"
4141
utilfeature "k8s.io/apiserver/pkg/util/feature"
42-
informers "k8s.io/client-go/informers"
42+
"k8s.io/client-go/informers"
4343
clientset "k8s.io/client-go/kubernetes"
4444
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
4545
"k8s.io/client-go/rest"
@@ -352,6 +352,7 @@ func (o *Options) writeConfigFile() error {
352352
if err != nil {
353353
return err
354354
}
355+
// TODO handle error
355356
defer configFile.Close()
356357

357358
if err := encoder.Encode(o.config, configFile); err != nil {
@@ -414,11 +415,11 @@ func (o *Options) loadConfig(data []byte) (*kubeproxyconfig.KubeProxyConfigurati
414415
if err != nil {
415416
return nil, err
416417
}
417-
config, ok := configObj.(*kubeproxyconfig.KubeProxyConfiguration)
418+
proxyConfig, ok := configObj.(*kubeproxyconfig.KubeProxyConfiguration)
418419
if !ok {
419420
return nil, fmt.Errorf("got unexpected config type: %v", gvk)
420421
}
421-
return config, nil
422+
return proxyConfig, nil
422423
}
423424

424425
func (o *Options) ApplyDefaults(in *kubeproxyconfig.KubeProxyConfiguration) (*kubeproxyconfig.KubeProxyConfiguration, error) {
@@ -478,6 +479,7 @@ with the apiserver API to configure the proxy.`,
478479

479480
opts.AddFlags(cmd.Flags())
480481

482+
// TODO handle error
481483
cmd.MarkFlagFilename("config", "yaml", "yml", "json")
482484

483485
return cmd
@@ -534,7 +536,6 @@ func createClients(config componentbaseconfig.ClientConnectionConfiguration, mas
534536
kubeConfig.AcceptContentTypes = config.AcceptContentTypes
535537
kubeConfig.ContentType = config.ContentType
536538
kubeConfig.QPS = config.QPS
537-
//TODO make config struct use int instead of int32?
538539
kubeConfig.Burst = int(config.Burst)
539540

540541
client, err := clientset.NewForConfig(kubeConfig)
@@ -560,7 +561,7 @@ func (s *ProxyServer) Run() error {
560561
encounteredError = iptables.CleanupLeftovers(s.IptInterface) || encounteredError
561562
encounteredError = ipvs.CleanupLeftovers(s.IpvsInterface, s.IptInterface, s.IpsetInterface, s.CleanupIPVS) || encounteredError
562563
if encounteredError {
563-
return errors.New("encountered an error while tearing down rules.")
564+
return errors.New("encountered an error while tearing down rules")
564565
}
565566
return nil
566567
}
@@ -594,18 +595,18 @@ func (s *ProxyServer) Run() error {
594595

595596
// Start up a metrics server if requested
596597
if len(s.MetricsBindAddress) > 0 {
597-
mux := mux.NewPathRecorderMux("kube-proxy")
598-
healthz.InstallHandler(mux)
599-
mux.HandleFunc("/proxyMode", func(w http.ResponseWriter, r *http.Request) {
598+
proxyMux := mux.NewPathRecorderMux("kube-proxy")
599+
healthz.InstallHandler(proxyMux)
600+
proxyMux.HandleFunc("/proxyMode", func(w http.ResponseWriter, r *http.Request) {
600601
fmt.Fprintf(w, "%s", s.ProxyMode)
601602
})
602-
mux.Handle("/metrics", prometheus.Handler())
603+
proxyMux.Handle("/metrics", prometheus.Handler())
603604
if s.EnableProfiling {
604-
routes.Profiling{}.Install(mux)
605+
routes.Profiling{}.Install(proxyMux)
605606
}
606-
configz.InstallHandler(mux)
607+
configz.InstallHandler(proxyMux)
607608
go wait.Until(func() {
608-
err := http.ListenAndServe(s.MetricsBindAddress, mux)
609+
err := http.ListenAndServe(s.MetricsBindAddress, proxyMux)
609610
if err != nil {
610611
utilruntime.HandleError(fmt.Errorf("starting metrics server failed: %v", err))
611612
}

cmd/kube-proxy/app/server_others_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func Test_getProxyMode(t *testing.T) {
4545
},
4646
{ // flag says iptables, error detecting version
4747
flag: "iptables",
48-
iptablesError: fmt.Errorf("oops!"),
48+
iptablesError: fmt.Errorf("flag says iptables, error detecting version"),
4949
expected: proxyModeUserspace,
5050
},
5151
{ // flag says iptables, version too low
@@ -67,7 +67,7 @@ func Test_getProxyMode(t *testing.T) {
6767
},
6868
{ // detect, error
6969
flag: "",
70-
iptablesError: fmt.Errorf("oops!"),
70+
iptablesError: fmt.Errorf("oops"),
7171
expected: proxyModeUserspace,
7272
},
7373
{ // detect, version too low

0 commit comments

Comments
 (0)