From 0bf0b3ef1aec72eada39cdff449624bf47cdc577 Mon Sep 17 00:00:00 2001 From: Dmitry Rozhkov Date: Thu, 27 Dec 2018 15:18:25 +0200 Subject: [PATCH] kubeadm: fix golint warnings for redundant ifs When golint is run against kubeadm it reports severel warnings like redundant if ...; err != nil check, just return error instead. Fix the warnings by just returning error. --- cmd/kubeadm/app/cmd/phases/controlplane.go | 5 +---- cmd/kubeadm/app/cmd/phases/markcontrolplane.go | 6 +----- cmd/kubeadm/app/cmd/reset.go | 5 +---- cmd/kubeadm/app/componentconfigs/registrations.go | 5 +---- cmd/kubeadm/app/phases/certs/certs.go | 6 +----- cmd/kubeadm/app/util/config/initconfiguration.go | 5 +---- cmd/kubeadm/app/util/config/joinconfiguration.go | 6 +----- 7 files changed, 7 insertions(+), 31 deletions(-) diff --git a/cmd/kubeadm/app/cmd/phases/controlplane.go b/cmd/kubeadm/app/cmd/phases/controlplane.go index 6a191b0604..e599537cb5 100644 --- a/cmd/kubeadm/app/cmd/phases/controlplane.go +++ b/cmd/kubeadm/app/cmd/phases/controlplane.go @@ -149,9 +149,6 @@ func runControlPlaneSubPhase(component string) func(c workflow.RunData) error { cfg := data.Cfg() fmt.Printf("[control-plane] Creating static Pod manifest for %q\n", component) - if err := controlplane.CreateStaticPodFiles(data.ManifestDir(), cfg, component); err != nil { - return err - } - return nil + return controlplane.CreateStaticPodFiles(data.ManifestDir(), cfg, component) } } diff --git a/cmd/kubeadm/app/cmd/phases/markcontrolplane.go b/cmd/kubeadm/app/cmd/phases/markcontrolplane.go index 37dd80564d..cf5f26778b 100644 --- a/cmd/kubeadm/app/cmd/phases/markcontrolplane.go +++ b/cmd/kubeadm/app/cmd/phases/markcontrolplane.go @@ -69,9 +69,5 @@ func runMarkControlPlane(c workflow.RunData) error { } nodeRegistration := data.Cfg().NodeRegistration - if err := markcontrolplanephase.MarkControlPlane(client, nodeRegistration.Name, nodeRegistration.Taints); err != nil { - return err - } - - return nil + return markcontrolplanephase.MarkControlPlane(client, nodeRegistration.Name, nodeRegistration.Taints) } diff --git a/cmd/kubeadm/app/cmd/reset.go b/cmd/kubeadm/app/cmd/reset.go index f181011ead..4cd9ad0e4e 100644 --- a/cmd/kubeadm/app/cmd/reset.go +++ b/cmd/kubeadm/app/cmd/reset.go @@ -239,10 +239,7 @@ func removeContainers(execer utilsexec.Interface, criSocketPath string) error { if err != nil { return err } - if err := containerRuntime.RemoveContainers(containers); err != nil { - return err - } - return nil + return containerRuntime.RemoveContainers(containers) } // cleanDir removes everything in a directory, but not the directory itself diff --git a/cmd/kubeadm/app/componentconfigs/registrations.go b/cmd/kubeadm/app/componentconfigs/registrations.go index ebe125d1a6..c814cd5db6 100644 --- a/cmd/kubeadm/app/componentconfigs/registrations.go +++ b/cmd/kubeadm/app/componentconfigs/registrations.go @@ -74,10 +74,7 @@ func (r Registration) Unmarshal(fileContent []byte) (runtime.Object, error) { func unmarshalObject(obj runtime.Object, fileContent []byte) error { // Decode the file content using the componentconfig Codecs that knows about all APIs - if err := runtime.DecodeInto(Codecs.UniversalDecoder(), fileContent, obj); err != nil { - return err - } - return nil + return runtime.DecodeInto(Codecs.UniversalDecoder(), fileContent, obj) } const ( diff --git a/cmd/kubeadm/app/phases/certs/certs.go b/cmd/kubeadm/app/phases/certs/certs.go index e89176686e..9881f3b8c0 100644 --- a/cmd/kubeadm/app/phases/certs/certs.go +++ b/cmd/kubeadm/app/phases/certs/certs.go @@ -59,11 +59,7 @@ func CreatePKIAssets(cfg *kubeadmapi.InitConfiguration) error { fmt.Printf("[certs] valid certificates and keys now exist in %q\n", cfg.CertificatesDir) // Service accounts are not x509 certs, so handled separately - if err := CreateServiceAccountKeyAndPublicKeyFiles(cfg); err != nil { - return err - } - - return nil + return CreateServiceAccountKeyAndPublicKeyFiles(cfg) } // CreateServiceAccountKeyAndPublicKeyFiles create a new public/private key files for signing service account users. diff --git a/cmd/kubeadm/app/util/config/initconfiguration.go b/cmd/kubeadm/app/util/config/initconfiguration.go index e425e0cdb6..eec7e28c6a 100644 --- a/cmd/kubeadm/app/util/config/initconfiguration.go +++ b/cmd/kubeadm/app/util/config/initconfiguration.go @@ -54,10 +54,7 @@ func SetInitDynamicDefaults(cfg *kubeadmapi.InitConfiguration) error { if err := SetAPIEndpointDynamicDefaults(&cfg.LocalAPIEndpoint); err != nil { return err } - if err := SetClusterDynamicDefaults(&cfg.ClusterConfiguration, cfg.LocalAPIEndpoint.AdvertiseAddress, cfg.LocalAPIEndpoint.BindPort); err != nil { - return err - } - return nil + return SetClusterDynamicDefaults(&cfg.ClusterConfiguration, cfg.LocalAPIEndpoint.AdvertiseAddress, cfg.LocalAPIEndpoint.BindPort) } // SetBootstrapTokensDynamicDefaults checks and sets configuration values for the BootstrapTokens object diff --git a/cmd/kubeadm/app/util/config/joinconfiguration.go b/cmd/kubeadm/app/util/config/joinconfiguration.go index 168de0b509..aa4d653075 100644 --- a/cmd/kubeadm/app/util/config/joinconfiguration.go +++ b/cmd/kubeadm/app/util/config/joinconfiguration.go @@ -41,11 +41,7 @@ func SetJoinDynamicDefaults(cfg *kubeadmapi.JoinConfiguration) error { return err } - if err := SetJoinControlPlaneDefaults(cfg.ControlPlane); err != nil { - return err - } - - return nil + return SetJoinControlPlaneDefaults(cfg.ControlPlane) } // SetJoinControlPlaneDefaults checks and sets configuration values for the JoinControlPlane object