From ec43037d0f57fdfc2fdc4960fdb8a7e31ac79fae Mon Sep 17 00:00:00 2001 From: cndoit18 Date: Fri, 29 Jul 2022 18:25:05 +0800 Subject: [PATCH] style: remove redundant judgment Signed-off-by: cndoit18 --- cmd/kubeadm/app/cmd/upgrade/common.go | 6 +----- cmd/kubeadm/app/phases/certs/certlist.go | 6 +----- cmd/kubeadm/app/phases/certs/certs.go | 5 +---- cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go | 5 +---- cmd/kubeadm/app/phases/upgrade/preflight.go | 5 +---- cmd/kubeadm/app/util/apiclient/wait.go | 5 +---- cmd/kubeadm/app/util/copy.go | 6 +----- pkg/apis/certificates/validation/validation.go | 6 +----- pkg/controller/replicaset/metrics/metrics.go | 6 +----- pkg/kubectl/cmd/convert/convert.go | 5 +---- pkg/kubelet/cm/devicemanager/plugin/v1beta1/stub.go | 5 +---- pkg/kubelet/util/cache/object_cache.go | 6 +----- pkg/volume/emptydir/empty_dir.go | 6 +----- plugin/pkg/admission/imagepolicy/config.go | 5 +---- .../apiserver/pkg/registry/generic/registry/dryrun.go | 6 +----- staging/src/k8s.io/client-go/rest/config.go | 5 +---- staging/src/k8s.io/client-go/transport/transport.go | 5 +---- .../src/k8s.io/kubectl/pkg/cmd/apiresources/apiversions.go | 5 +---- staging/src/k8s.io/kubectl/pkg/cmd/create/create_ingress.go | 5 +---- .../src/k8s.io/kubectl/pkg/cmd/create/create_namespace.go | 5 +---- .../src/k8s.io/kubectl/pkg/cmd/create/create_rolebinding.go | 5 +---- staging/src/k8s.io/kubectl/pkg/cmd/expose/expose.go | 5 +---- staging/src/k8s.io/kubectl/pkg/cmd/set/set_resources.go | 5 +---- .../src/k8s.io/kubectl/pkg/cmd/set/set_serviceaccount.go | 5 +---- .../src/k8s.io/kubectl/pkg/cmd/util/editor/editoptions.go | 5 +---- staging/src/k8s.io/legacy-cloud-providers/gce/gce_tpu.go | 5 +---- 26 files changed, 26 insertions(+), 112 deletions(-) diff --git a/cmd/kubeadm/app/cmd/upgrade/common.go b/cmd/kubeadm/app/cmd/upgrade/common.go index 2efc77a49f9..c71ec2c2d3c 100644 --- a/cmd/kubeadm/app/cmd/upgrade/common.go +++ b/cmd/kubeadm/app/cmd/upgrade/common.go @@ -240,11 +240,7 @@ func runPreflightChecks(client clientset.Interface, ignorePreflightErrors sets.S if err != nil { return err } - err = upgrade.RunCoreDNSMigrationCheck(client, ignorePreflightErrors) - if err != nil { - return err - } - return nil + return upgrade.RunCoreDNSMigrationCheck(client, ignorePreflightErrors) } // getClient gets a real or fake client depending on whether the user is dry-running or not diff --git a/cmd/kubeadm/app/phases/certs/certlist.go b/cmd/kubeadm/app/phases/certs/certlist.go index 8cd82bab168..f8edee04ce0 100644 --- a/cmd/kubeadm/app/phases/certs/certlist.go +++ b/cmd/kubeadm/app/phases/certs/certlist.go @@ -471,11 +471,7 @@ func createKeyAndCSR(kubeadmConfig *kubeadmapi.InitConfiguration, cert *KubeadmC if err != nil { return err } - err = pkiutil.WriteCSR(certDir, name, csr) - if err != nil { - return err - } - return nil + return pkiutil.WriteCSR(certDir, name, csr) } // CreateDefaultKeysAndCSRFiles is used in ExternalCA mode to create key files diff --git a/cmd/kubeadm/app/phases/certs/certs.go b/cmd/kubeadm/app/phases/certs/certs.go index 738fccf1743..22a736088d3 100644 --- a/cmd/kubeadm/app/phases/certs/certs.go +++ b/cmd/kubeadm/app/phases/certs/certs.go @@ -486,10 +486,7 @@ func validateSignedCertWithCA(l certKeyLocation, caCert *x509.Certificate) error func validatePrivatePublicKey(l certKeyLocation) error { // Try to load key _, _, err := pkiutil.TryLoadPrivatePublicKeyFromDisk(l.pkiDir, l.baseName) - if err != nil { - return errors.Wrapf(err, "failure loading key for %s", l.uxName) - } - return nil + return errors.Wrapf(err, "failure loading key for %s", l.uxName) } // validateCertificateWithConfig makes sure that a given certificate is valid at diff --git a/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go b/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go index c1058849868..b300146c3e9 100644 --- a/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go +++ b/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go @@ -281,10 +281,7 @@ func createKubeConfigFileIfNotExists(outDir, filename string, config *clientcmda } fmt.Printf("[kubeconfig] Writing %q kubeconfig file\n", filename) err = kubeconfigutil.WriteToDisk(kubeConfigFilePath, config) - if err != nil { - return errors.Wrapf(err, "failed to save kubeconfig file %q on disk", kubeConfigFilePath) - } - return nil + return errors.Wrapf(err, "failed to save kubeconfig file %q on disk", kubeConfigFilePath) } // kubeadm doesn't validate the existing kubeconfig file more than this (kubeadm trusts the client certs to be valid) // Basically, if we find a kubeconfig file with the same path; the same CA cert and the same server URL; diff --git a/cmd/kubeadm/app/phases/upgrade/preflight.go b/cmd/kubeadm/app/phases/upgrade/preflight.go index 382e2427ee9..03e844d702d 100644 --- a/cmd/kubeadm/app/phases/upgrade/preflight.go +++ b/cmd/kubeadm/app/phases/upgrade/preflight.go @@ -110,8 +110,5 @@ func checkMigration(client clientset.Interface) error { currentInstalledCoreDNSversion = strings.TrimLeft(currentInstalledCoreDNSversion, "v") _, err = migration.Migrate(currentInstalledCoreDNSversion, strings.TrimLeft(kubeadmconstants.CoreDNSVersion, "v"), corefile, false) - if err != nil { - return errors.Wrap(err, "CoreDNS will not be upgraded") - } - return nil + return errors.Wrap(err, "CoreDNS will not be upgraded") } diff --git a/cmd/kubeadm/app/util/apiclient/wait.go b/cmd/kubeadm/app/util/apiclient/wait.go index ebac2c95d3c..b319d511051 100644 --- a/cmd/kubeadm/app/util/apiclient/wait.go +++ b/cmd/kubeadm/app/util/apiclient/wait.go @@ -249,10 +249,7 @@ func (w *KubeWaiter) WaitForStaticPodHashChange(nodeName, component, previousHas if lastErr != nil { return lastErr } - if err != nil { - return errors.Wrapf(err, "static Pod hash for component %s on Node %s did not change after %v", component, nodeName, w.timeout) - } - return nil + return errors.Wrapf(err, "static Pod hash for component %s on Node %s did not change after %v", component, nodeName, w.timeout) } // getStaticPodSingleHash computes hashes for a single Static Pod resource diff --git a/cmd/kubeadm/app/util/copy.go b/cmd/kubeadm/app/util/copy.go index 6465547d2c2..5e9c9ef0bdb 100644 --- a/cmd/kubeadm/app/util/copy.go +++ b/cmd/kubeadm/app/util/copy.go @@ -23,9 +23,5 @@ import ( // CopyDir copies the content of a folder func CopyDir(src string, dst string) error { cmd := exec.Command("cp", "-r", src, dst) - err := cmd.Run() - if err != nil { - return err - } - return nil + return cmd.Run() } diff --git a/pkg/apis/certificates/validation/validation.go b/pkg/apis/certificates/validation/validation.go index a4e21860361..0d1e4333cad 100644 --- a/pkg/apis/certificates/validation/validation.go +++ b/pkg/apis/certificates/validation/validation.go @@ -87,11 +87,7 @@ func validateCSR(obj *certificates.CertificateSigningRequest) error { return err } // check that the signature is valid - err = csr.CheckSignature() - if err != nil { - return err - } - return nil + return csr.CheckSignature() } func validateCertificate(pemData []byte) error { diff --git a/pkg/controller/replicaset/metrics/metrics.go b/pkg/controller/replicaset/metrics/metrics.go index 73278b05130..64b3a6dcd3f 100644 --- a/pkg/controller/replicaset/metrics/metrics.go +++ b/pkg/controller/replicaset/metrics/metrics.go @@ -36,9 +36,5 @@ var SortingDeletionAgeRatio = metrics.NewHistogram( // Register registers ReplicaSet controller metrics. func Register(registrationFunc func(metrics.Registerable) error) error { - err := registrationFunc(SortingDeletionAgeRatio) - if err != nil { - return err - } - return nil + return registrationFunc(SortingDeletionAgeRatio) } diff --git a/pkg/kubectl/cmd/convert/convert.go b/pkg/kubectl/cmd/convert/convert.go index 211c43f059b..7a9d5e7a916 100644 --- a/pkg/kubectl/cmd/convert/convert.go +++ b/pkg/kubectl/cmd/convert/convert.go @@ -138,10 +138,7 @@ func (o *ConvertOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) (err er // build the printer o.Printer, err = o.PrintFlags.ToPrinter() - if err != nil { - return err - } - return nil + return err } // RunConvert implements the generic Convert command diff --git a/pkg/kubelet/cm/devicemanager/plugin/v1beta1/stub.go b/pkg/kubelet/cm/devicemanager/plugin/v1beta1/stub.go index d354222590b..95ff4c7c0aa 100644 --- a/pkg/kubelet/cm/devicemanager/plugin/v1beta1/stub.go +++ b/pkg/kubelet/cm/devicemanager/plugin/v1beta1/stub.go @@ -214,10 +214,7 @@ func (m *Stub) Register(kubeletEndpoint, resourceName string, pluginSockDir stri } _, err = client.Register(context.Background(), reqt) - if err != nil { - return err - } - return nil + return err } // GetDevicePluginOptions returns DevicePluginOptions settings for the device plugin. diff --git a/pkg/kubelet/util/cache/object_cache.go b/pkg/kubelet/util/cache/object_cache.go index 98dbe40534a..e5645ec3f2b 100644 --- a/pkg/kubelet/util/cache/object_cache.go +++ b/pkg/kubelet/util/cache/object_cache.go @@ -77,9 +77,5 @@ func (c *ObjectCache) Get(key string) (interface{}, error) { // Add adds objectEntry by using a unique string as the key. func (c *ObjectCache) Add(key string, obj interface{}) error { - err := c.cache.Add(objectEntry{key: key, obj: obj}) - if err != nil { - return err - } - return nil + return c.cache.Add(objectEntry{key: key, obj: obj}) } diff --git a/pkg/volume/emptydir/empty_dir.go b/pkg/volume/emptydir/empty_dir.go index 6370902d0ea..620d23cd633 100644 --- a/pkg/volume/emptydir/empty_dir.go +++ b/pkg/volume/emptydir/empty_dir.go @@ -524,11 +524,7 @@ func (ed *emptyDir) teardownDefault(dir string) error { } // Renaming the directory is not required anymore because the operation executor // now handles duplicate operations on the same volume - err = os.RemoveAll(dir) - if err != nil { - return err - } - return nil + return os.RemoveAll(dir) } func (ed *emptyDir) teardownTmpfsOrHugetlbfs(dir string) error { diff --git a/plugin/pkg/admission/imagepolicy/config.go b/plugin/pkg/admission/imagepolicy/config.go index 84e19349359..c3b3e537c29 100644 --- a/plugin/pkg/admission/imagepolicy/config.go +++ b/plugin/pkg/admission/imagepolicy/config.go @@ -63,10 +63,7 @@ func normalizeWebhookConfig(config *imagePolicyWebhookConfig) (err error) { return err } config.DenyTTL, err = normalizeConfigDuration("deny cache", time.Second, config.DenyTTL, minDenyTTL, maxDenyTTL, defaultDenyTTL) - if err != nil { - return err - } - return nil + return err } func normalizeConfigDuration(name string, scale, value, min, max, defaultValue time.Duration) (time.Duration, error) { diff --git a/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/dryrun.go b/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/dryrun.go index 1d912533891..018e4b4c52d 100644 --- a/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/dryrun.go +++ b/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/dryrun.go @@ -105,9 +105,5 @@ func (s *DryRunnableStorage) copyInto(in, out runtime.Object) error { return err } _, _, err = s.Codec.Decode(data, nil, out) - if err != nil { - return err - } - return nil - + return err } diff --git a/staging/src/k8s.io/client-go/rest/config.go b/staging/src/k8s.io/client-go/rest/config.go index d61ca203894..81e3cbd6897 100644 --- a/staging/src/k8s.io/client-go/rest/config.go +++ b/staging/src/k8s.io/client-go/rest/config.go @@ -571,10 +571,7 @@ func LoadTLSFiles(c *Config) error { } c.KeyData, err = dataFromSliceOrFile(c.KeyData, c.KeyFile) - if err != nil { - return err - } - return nil + return err } // dataFromSliceOrFile returns data from the slice (if non-empty), or from the file, diff --git a/staging/src/k8s.io/client-go/transport/transport.go b/staging/src/k8s.io/client-go/transport/transport.go index 8ba7056d0e3..ff0efc33d34 100644 --- a/staging/src/k8s.io/client-go/transport/transport.go +++ b/staging/src/k8s.io/client-go/transport/transport.go @@ -157,10 +157,7 @@ func loadTLSFiles(c *Config) error { } c.TLS.KeyData, err = dataFromSliceOrFile(c.TLS.KeyData, c.TLS.KeyFile) - if err != nil { - return err - } - return nil + return err } // dataFromSliceOrFile returns data from the slice (if non-empty), or from the file, diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/apiresources/apiversions.go b/staging/src/k8s.io/kubectl/pkg/cmd/apiresources/apiversions.go index 71585d4e8eb..a0970f8350e 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/apiresources/apiversions.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/apiresources/apiversions.go @@ -74,10 +74,7 @@ func (o *APIVersionsOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg } var err error o.discoveryClient, err = f.ToDiscoveryClient() - if err != nil { - return err - } - return nil + return err } // RunAPIVersions does the work diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_ingress.go b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_ingress.go index 5515e3009ec..b3e2e3408b9 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_ingress.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_ingress.go @@ -211,10 +211,7 @@ func (o *CreateIngressOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, a } o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd) - if err != nil { - return err - } - return nil + return err } // Validate validates the Ingress object to be created diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_namespace.go b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_namespace.go index 2e8f1001376..fc77e5a2f3d 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_namespace.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_namespace.go @@ -143,10 +143,7 @@ func (o *NamespaceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args } o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd) - if err != nil { - return err - } - return nil + return err } // Run calls the CreateSubcommandOptions.Run in NamespaceOpts instance diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_rolebinding.go b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_rolebinding.go index 33c96cea760..06b9ad5bccc 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_rolebinding.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_rolebinding.go @@ -152,10 +152,7 @@ func (o *RoleBindingOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg } o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd) - if err != nil { - return err - } - return nil + return err } // Validate validates required fields are set diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/expose/expose.go b/staging/src/k8s.io/kubectl/pkg/cmd/expose/expose.go index 8862086ae7c..9ce97d32341 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/expose/expose.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/expose/expose.go @@ -381,10 +381,7 @@ func (o *ExposeServiceOptions) RunExpose(cmd *cobra.Command, args []string) erro return o.PrintObj(actualObject, o.Out) }) - if err != nil { - return err - } - return nil + return err } func (o *ExposeServiceOptions) createService() (*corev1.Service, error) { diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/set/set_resources.go b/staging/src/k8s.io/kubectl/pkg/cmd/set/set_resources.go index a3caf4a80f4..cb70c0fddbb 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/set/set_resources.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/set/set_resources.go @@ -199,10 +199,7 @@ func (o *SetResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, ar } o.Infos, err = builder.Do().Infos() - if err != nil { - return err - } - return nil + return err } // Validate makes sure that provided values in ResourcesOptions are valid diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/set/set_serviceaccount.go b/staging/src/k8s.io/kubectl/pkg/cmd/set/set_serviceaccount.go index d037f5bed85..8f534002a6e 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/set/set_serviceaccount.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/set/set_serviceaccount.go @@ -174,10 +174,7 @@ func (o *SetServiceAccountOptions) Complete(f cmdutil.Factory, cmd *cobra.Comman Latest() } o.infos, err = builder.Do().Infos() - if err != nil { - return err - } - return nil + return err } // Run creates and applies the patch either locally or calling apiserver. diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/util/editor/editoptions.go b/staging/src/k8s.io/kubectl/pkg/cmd/util/editor/editoptions.go index c9a47fc674a..05b28cfa047 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/util/editor/editoptions.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/util/editor/editoptions.go @@ -589,10 +589,7 @@ func (o *EditOptions) annotationPatch(update *resource.Info) error { WithFieldValidation(o.ValidationDirective). WithSubresource(o.Subresource) _, err = helper.Patch(o.CmdNamespace, update.Name, patchType, patch, nil) - if err != nil { - return err - } - return nil + return err } // GetApplyPatch is used to get and apply patches diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_tpu.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_tpu.go index 63acb344b54..5b3e627415b 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_tpu.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_tpu.go @@ -104,10 +104,7 @@ func (g *Cloud) DeleteTPU(ctx context.Context, name, zone string) error { return err } err = getErrorFromTPUOp(op) - if err != nil { - return err - } - return nil + return err } // GetTPU returns the Cloud TPU with the specified name in the specified zone.