style: remove redundant judgment

Signed-off-by: cndoit18 <cndoit18@outlook.com>
This commit is contained in:
cndoit18 2022-07-29 18:25:05 +08:00
parent 26842bb0c8
commit ec43037d0f
26 changed files with 26 additions and 112 deletions

View File

@ -240,11 +240,7 @@ func runPreflightChecks(client clientset.Interface, ignorePreflightErrors sets.S
if err != nil { if err != nil {
return err return err
} }
err = upgrade.RunCoreDNSMigrationCheck(client, ignorePreflightErrors) return upgrade.RunCoreDNSMigrationCheck(client, ignorePreflightErrors)
if err != nil {
return err
}
return nil
} }
// getClient gets a real or fake client depending on whether the user is dry-running or not // getClient gets a real or fake client depending on whether the user is dry-running or not

View File

@ -471,11 +471,7 @@ func createKeyAndCSR(kubeadmConfig *kubeadmapi.InitConfiguration, cert *KubeadmC
if err != nil { if err != nil {
return err return err
} }
err = pkiutil.WriteCSR(certDir, name, csr) return pkiutil.WriteCSR(certDir, name, csr)
if err != nil {
return err
}
return nil
} }
// CreateDefaultKeysAndCSRFiles is used in ExternalCA mode to create key files // CreateDefaultKeysAndCSRFiles is used in ExternalCA mode to create key files

View File

@ -486,10 +486,7 @@ func validateSignedCertWithCA(l certKeyLocation, caCert *x509.Certificate) error
func validatePrivatePublicKey(l certKeyLocation) error { func validatePrivatePublicKey(l certKeyLocation) error {
// Try to load key // Try to load key
_, _, err := pkiutil.TryLoadPrivatePublicKeyFromDisk(l.pkiDir, l.baseName) _, _, err := pkiutil.TryLoadPrivatePublicKeyFromDisk(l.pkiDir, l.baseName)
if err != nil {
return errors.Wrapf(err, "failure loading key for %s", l.uxName) return errors.Wrapf(err, "failure loading key for %s", l.uxName)
}
return nil
} }
// validateCertificateWithConfig makes sure that a given certificate is valid at // validateCertificateWithConfig makes sure that a given certificate is valid at

View File

@ -281,11 +281,8 @@ func createKubeConfigFileIfNotExists(outDir, filename string, config *clientcmda
} }
fmt.Printf("[kubeconfig] Writing %q kubeconfig file\n", filename) fmt.Printf("[kubeconfig] Writing %q kubeconfig file\n", filename)
err = kubeconfigutil.WriteToDisk(kubeConfigFilePath, config) err = kubeconfigutil.WriteToDisk(kubeConfigFilePath, config)
if err != nil {
return errors.Wrapf(err, "failed to save kubeconfig file %q on disk", kubeConfigFilePath) return errors.Wrapf(err, "failed to save kubeconfig file %q on disk", kubeConfigFilePath)
} }
return nil
}
// kubeadm doesn't validate the existing kubeconfig file more than this (kubeadm trusts the client certs to be valid) // 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; // Basically, if we find a kubeconfig file with the same path; the same CA cert and the same server URL;
// kubeadm thinks those files are equal and doesn't bother writing a new file // kubeadm thinks those files are equal and doesn't bother writing a new file

View File

@ -110,8 +110,5 @@ func checkMigration(client clientset.Interface) error {
currentInstalledCoreDNSversion = strings.TrimLeft(currentInstalledCoreDNSversion, "v") currentInstalledCoreDNSversion = strings.TrimLeft(currentInstalledCoreDNSversion, "v")
_, err = migration.Migrate(currentInstalledCoreDNSversion, strings.TrimLeft(kubeadmconstants.CoreDNSVersion, "v"), corefile, false) _, err = migration.Migrate(currentInstalledCoreDNSversion, strings.TrimLeft(kubeadmconstants.CoreDNSVersion, "v"), corefile, false)
if err != nil {
return errors.Wrap(err, "CoreDNS will not be upgraded") return errors.Wrap(err, "CoreDNS will not be upgraded")
}
return nil
} }

View File

@ -249,10 +249,7 @@ func (w *KubeWaiter) WaitForStaticPodHashChange(nodeName, component, previousHas
if lastErr != nil { if lastErr != nil {
return lastErr 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 errors.Wrapf(err, "static Pod hash for component %s on Node %s did not change after %v", component, nodeName, w.timeout)
}
return nil
} }
// getStaticPodSingleHash computes hashes for a single Static Pod resource // getStaticPodSingleHash computes hashes for a single Static Pod resource

View File

@ -23,9 +23,5 @@ import (
// CopyDir copies the content of a folder // CopyDir copies the content of a folder
func CopyDir(src string, dst string) error { func CopyDir(src string, dst string) error {
cmd := exec.Command("cp", "-r", src, dst) cmd := exec.Command("cp", "-r", src, dst)
err := cmd.Run() return cmd.Run()
if err != nil {
return err
}
return nil
} }

View File

@ -87,11 +87,7 @@ func validateCSR(obj *certificates.CertificateSigningRequest) error {
return err return err
} }
// check that the signature is valid // check that the signature is valid
err = csr.CheckSignature() return csr.CheckSignature()
if err != nil {
return err
}
return nil
} }
func validateCertificate(pemData []byte) error { func validateCertificate(pemData []byte) error {

View File

@ -36,9 +36,5 @@ var SortingDeletionAgeRatio = metrics.NewHistogram(
// Register registers ReplicaSet controller metrics. // Register registers ReplicaSet controller metrics.
func Register(registrationFunc func(metrics.Registerable) error) error { func Register(registrationFunc func(metrics.Registerable) error) error {
err := registrationFunc(SortingDeletionAgeRatio) return registrationFunc(SortingDeletionAgeRatio)
if err != nil {
return err
}
return nil
} }

View File

@ -138,10 +138,7 @@ func (o *ConvertOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) (err er
// build the printer // build the printer
o.Printer, err = o.PrintFlags.ToPrinter() o.Printer, err = o.PrintFlags.ToPrinter()
if err != nil {
return err return err
}
return nil
} }
// RunConvert implements the generic Convert command // RunConvert implements the generic Convert command

View File

@ -214,10 +214,7 @@ func (m *Stub) Register(kubeletEndpoint, resourceName string, pluginSockDir stri
} }
_, err = client.Register(context.Background(), reqt) _, err = client.Register(context.Background(), reqt)
if err != nil {
return err return err
}
return nil
} }
// GetDevicePluginOptions returns DevicePluginOptions settings for the device plugin. // GetDevicePluginOptions returns DevicePluginOptions settings for the device plugin.

View File

@ -77,9 +77,5 @@ func (c *ObjectCache) Get(key string) (interface{}, error) {
// Add adds objectEntry by using a unique string as the key. // Add adds objectEntry by using a unique string as the key.
func (c *ObjectCache) Add(key string, obj interface{}) error { func (c *ObjectCache) Add(key string, obj interface{}) error {
err := c.cache.Add(objectEntry{key: key, obj: obj}) return c.cache.Add(objectEntry{key: key, obj: obj})
if err != nil {
return err
}
return nil
} }

View File

@ -524,11 +524,7 @@ func (ed *emptyDir) teardownDefault(dir string) error {
} }
// Renaming the directory is not required anymore because the operation executor // Renaming the directory is not required anymore because the operation executor
// now handles duplicate operations on the same volume // now handles duplicate operations on the same volume
err = os.RemoveAll(dir) return os.RemoveAll(dir)
if err != nil {
return err
}
return nil
} }
func (ed *emptyDir) teardownTmpfsOrHugetlbfs(dir string) error { func (ed *emptyDir) teardownTmpfsOrHugetlbfs(dir string) error {

View File

@ -63,10 +63,7 @@ func normalizeWebhookConfig(config *imagePolicyWebhookConfig) (err error) {
return err return err
} }
config.DenyTTL, err = normalizeConfigDuration("deny cache", time.Second, config.DenyTTL, minDenyTTL, maxDenyTTL, defaultDenyTTL) config.DenyTTL, err = normalizeConfigDuration("deny cache", time.Second, config.DenyTTL, minDenyTTL, maxDenyTTL, defaultDenyTTL)
if err != nil {
return err return err
}
return nil
} }
func normalizeConfigDuration(name string, scale, value, min, max, defaultValue time.Duration) (time.Duration, error) { func normalizeConfigDuration(name string, scale, value, min, max, defaultValue time.Duration) (time.Duration, error) {

View File

@ -105,9 +105,5 @@ func (s *DryRunnableStorage) copyInto(in, out runtime.Object) error {
return err return err
} }
_, _, err = s.Codec.Decode(data, nil, out) _, _, err = s.Codec.Decode(data, nil, out)
if err != nil {
return err return err
}
return nil
} }

View File

@ -571,10 +571,7 @@ func LoadTLSFiles(c *Config) error {
} }
c.KeyData, err = dataFromSliceOrFile(c.KeyData, c.KeyFile) c.KeyData, err = dataFromSliceOrFile(c.KeyData, c.KeyFile)
if err != nil {
return err return err
}
return nil
} }
// dataFromSliceOrFile returns data from the slice (if non-empty), or from the file, // dataFromSliceOrFile returns data from the slice (if non-empty), or from the file,

View File

@ -157,10 +157,7 @@ func loadTLSFiles(c *Config) error {
} }
c.TLS.KeyData, err = dataFromSliceOrFile(c.TLS.KeyData, c.TLS.KeyFile) c.TLS.KeyData, err = dataFromSliceOrFile(c.TLS.KeyData, c.TLS.KeyFile)
if err != nil {
return err return err
}
return nil
} }
// dataFromSliceOrFile returns data from the slice (if non-empty), or from the file, // dataFromSliceOrFile returns data from the slice (if non-empty), or from the file,

View File

@ -74,10 +74,7 @@ func (o *APIVersionsOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg
} }
var err error var err error
o.discoveryClient, err = f.ToDiscoveryClient() o.discoveryClient, err = f.ToDiscoveryClient()
if err != nil {
return err return err
}
return nil
} }
// RunAPIVersions does the work // RunAPIVersions does the work

View File

@ -211,10 +211,7 @@ func (o *CreateIngressOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, a
} }
o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd) o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd)
if err != nil {
return err return err
}
return nil
} }
// Validate validates the Ingress object to be created // Validate validates the Ingress object to be created

View File

@ -143,10 +143,7 @@ func (o *NamespaceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
} }
o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd) o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd)
if err != nil {
return err return err
}
return nil
} }
// Run calls the CreateSubcommandOptions.Run in NamespaceOpts instance // Run calls the CreateSubcommandOptions.Run in NamespaceOpts instance

View File

@ -152,10 +152,7 @@ func (o *RoleBindingOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg
} }
o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd) o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd)
if err != nil {
return err return err
}
return nil
} }
// Validate validates required fields are set // Validate validates required fields are set

View File

@ -381,10 +381,7 @@ func (o *ExposeServiceOptions) RunExpose(cmd *cobra.Command, args []string) erro
return o.PrintObj(actualObject, o.Out) return o.PrintObj(actualObject, o.Out)
}) })
if err != nil {
return err return err
}
return nil
} }
func (o *ExposeServiceOptions) createService() (*corev1.Service, error) { func (o *ExposeServiceOptions) createService() (*corev1.Service, error) {

View File

@ -199,10 +199,7 @@ func (o *SetResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, ar
} }
o.Infos, err = builder.Do().Infos() o.Infos, err = builder.Do().Infos()
if err != nil {
return err return err
}
return nil
} }
// Validate makes sure that provided values in ResourcesOptions are valid // Validate makes sure that provided values in ResourcesOptions are valid

View File

@ -174,10 +174,7 @@ func (o *SetServiceAccountOptions) Complete(f cmdutil.Factory, cmd *cobra.Comman
Latest() Latest()
} }
o.infos, err = builder.Do().Infos() o.infos, err = builder.Do().Infos()
if err != nil {
return err return err
}
return nil
} }
// Run creates and applies the patch either locally or calling apiserver. // Run creates and applies the patch either locally or calling apiserver.

View File

@ -589,10 +589,7 @@ func (o *EditOptions) annotationPatch(update *resource.Info) error {
WithFieldValidation(o.ValidationDirective). WithFieldValidation(o.ValidationDirective).
WithSubresource(o.Subresource) WithSubresource(o.Subresource)
_, err = helper.Patch(o.CmdNamespace, update.Name, patchType, patch, nil) _, err = helper.Patch(o.CmdNamespace, update.Name, patchType, patch, nil)
if err != nil {
return err return err
}
return nil
} }
// GetApplyPatch is used to get and apply patches // GetApplyPatch is used to get and apply patches

View File

@ -104,10 +104,7 @@ func (g *Cloud) DeleteTPU(ctx context.Context, name, zone string) error {
return err return err
} }
err = getErrorFromTPUOp(op) err = getErrorFromTPUOp(op)
if err != nil {
return err return err
}
return nil
} }
// GetTPU returns the Cloud TPU with the specified name in the specified zone. // GetTPU returns the Cloud TPU with the specified name in the specified zone.