nodeup/pkg/ pkg/ staticcheck

This commit is contained in:
tanjunchen 2019-12-31 15:03:39 +08:00
parent 81d4cf62a1
commit 7e25f9831d
10 changed files with 16 additions and 16 deletions

View File

@ -567,11 +567,11 @@ func EvaluateHostnameOverride(hostnameOverride string) (string, error) {
} }
if len(result.Reservations) != 1 { if len(result.Reservations) != 1 {
return "", fmt.Errorf("Too many reservations returned for the single instance-id") return "", fmt.Errorf("too many reservations returned for the single instance-id")
} }
if len(result.Reservations[0].Instances) != 1 { if len(result.Reservations[0].Instances) != 1 {
return "", fmt.Errorf("Too many instances returned for the single instance-id") return "", fmt.Errorf("too many instances returned for the single instance-id")
} }
return *(result.Reservations[0].Instances[0].PrivateDnsName), nil return *(result.Reservations[0].Instances[0].PrivateDnsName), nil
} }

View File

@ -83,7 +83,7 @@ func (f *FileAssetsBuilder) buildFileAssets(c *fi.ModelBuilderContext, assets []
if asset.IsBase64 { if asset.IsBase64 {
decoded, err := base64.RawStdEncoding.DecodeString(content) decoded, err := base64.RawStdEncoding.DecodeString(content)
if err != nil { if err != nil {
return fmt.Errorf("Failed on file asset: %s is invalid, unable to decode base64, error: %q", asset.Name, err) return fmt.Errorf("failed on file asset: %s is invalid, unable to decode base64, error: %q", asset.Name, err)
} }
content = string(decoded) content = string(decoded)
} }

View File

@ -275,7 +275,7 @@ func (b *KubeAPIServerBuilder) writeAuthenticationConfig(c *fi.ModelBuilderConte
return nil return nil
} }
return fmt.Errorf("Unrecognized authentication config %v", b.Cluster.Spec.Authentication) return fmt.Errorf("unrecognized authentication config %v", b.Cluster.Spec.Authentication)
} }
// buildPod is responsible for generating the kube-apiserver pod and thus manifest file // buildPod is responsible for generating the kube-apiserver pod and thus manifest file

View File

@ -129,7 +129,7 @@ func (b *KubeProxyBuilder) buildPod() (*v1.Pod, error) {
cpuRequest, err := resource.ParseQuantity(c.CPURequest) cpuRequest, err := resource.ParseQuantity(c.CPURequest)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error parsing CPURequest=%q", c.CPURequest) return nil, fmt.Errorf("error parsing CPURequest=%q", c.CPURequest)
} }
resourceRequests["cpu"] = cpuRequest resourceRequests["cpu"] = cpuRequest
@ -137,7 +137,7 @@ func (b *KubeProxyBuilder) buildPod() (*v1.Pod, error) {
if c.CPULimit != "" { if c.CPULimit != "" {
cpuLimit, err := resource.ParseQuantity(c.CPULimit) cpuLimit, err := resource.ParseQuantity(c.CPULimit)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error parsing CPULimit=%q", c.CPULimit) return nil, fmt.Errorf("error parsing CPULimit=%q", c.CPULimit)
} }
resourceLimits["cpu"] = cpuLimit resourceLimits["cpu"] = cpuLimit
} }
@ -145,7 +145,7 @@ func (b *KubeProxyBuilder) buildPod() (*v1.Pod, error) {
if c.MemoryRequest != "" { if c.MemoryRequest != "" {
memoryRequest, err := resource.ParseQuantity(c.MemoryRequest) memoryRequest, err := resource.ParseQuantity(c.MemoryRequest)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error parsing MemoryRequest=%q", c.MemoryRequest) return nil, fmt.Errorf("error parsing MemoryRequest=%q", c.MemoryRequest)
} }
resourceRequests["memory"] = memoryRequest resourceRequests["memory"] = memoryRequest
} }
@ -153,7 +153,7 @@ func (b *KubeProxyBuilder) buildPod() (*v1.Pod, error) {
if c.MemoryLimit != "" { if c.MemoryLimit != "" {
memoryLimit, err := resource.ParseQuantity(c.MemoryLimit) memoryLimit, err := resource.ParseQuantity(c.MemoryLimit)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error parsing MemoryLimit=%q", c.MemoryLimit) return nil, fmt.Errorf("error parsing MemoryLimit=%q", c.MemoryLimit)
} }
resourceLimits["memory"] = memoryLimit resourceLimits["memory"] = memoryLimit
} }

View File

@ -45,7 +45,7 @@ func (b *VolumesBuilder) Build(c *fi.ModelBuilderContext) error {
for _, x := range b.InstanceGroup.Spec.VolumeMounts { for _, x := range b.InstanceGroup.Spec.VolumeMounts {
// @check the directory exists, else create it // @check the directory exists, else create it
if err := b.EnsureDirectory(x.Path); err != nil { if err := b.EnsureDirectory(x.Path); err != nil {
return fmt.Errorf("Failed to ensure the directory: %s, error: %s", x.Path, err) return fmt.Errorf("failed to ensure the directory: %s, error: %s", x.Path, err)
} }
m := &mount.SafeFormatAndMount{ m := &mount.SafeFormatAndMount{
@ -64,7 +64,7 @@ func (b *VolumesBuilder) Build(c *fi.ModelBuilderContext) error {
klog.Infof("Attempting to format and mount device: %s, path: %s", x.Device, x.Path) klog.Infof("Attempting to format and mount device: %s, path: %s", x.Device, x.Path)
if err := m.FormatAndMount(x.Device, x.Path, x.Filesystem, x.MountOptions); err != nil { if err := m.FormatAndMount(x.Device, x.Path, x.Filesystem, x.MountOptions); err != nil {
klog.Errorf("Failed to mount the device: %s on: %s, error: %s", x.Device, x.Path, err) klog.Errorf("failed to mount the device: %s on: %s, error: %s", x.Device, x.Path, err)
return err return err
} }

View File

@ -127,7 +127,7 @@ func WellKnownServiceIP(clusterSpec *kops.ClusterSpec, id int) (net.IP, error) {
return serviceIP, nil return serviceIP, nil
} }
return nil, fmt.Errorf("Unexpected IP address type for ServiceClusterIPRange: %s", clusterSpec.ServiceClusterIPRange) return nil, fmt.Errorf("unexpected IP address type for ServiceClusterIPRange: %s", clusterSpec.ServiceClusterIPRange)
} }
func IsBaseURL(kubernetesVersion string) bool { func IsBaseURL(kubernetesVersion string) bool {

View File

@ -169,5 +169,5 @@ func (i *nodeIdentifier) getInstanceGroup(instanceID int) (string, error) {
} }
} }
return "", errors.New("Could not find tag 'kops-instancegroup' from instance metadata") return "", errors.New("could not find tag 'kops-instancegroup' from instance metadata")
} }

View File

@ -267,7 +267,7 @@ func FindAutoscalingLaunchConfiguration(cloud awsup.AWSCloud, name string) (*aut
return nil, nil return nil, nil
} }
if len(results) != 1 { if len(results) != 1 {
return nil, fmt.Errorf("Found multiple LaunchConfigurations with name %q", name) return nil, fmt.Errorf("found multiple LaunchConfigurations with name %q", name)
} }
return results[0], nil return results[0], nil
} }
@ -362,7 +362,7 @@ func ListCloudFormationStacks(cloud fi.Cloud, clusterName string) ([]*resources.
c := cloud.(awsup.AWSCloud) c := cloud.(awsup.AWSCloud)
response, err := c.CloudFormation().ListStacks(request) response, err := c.CloudFormation().ListStacks(request)
if err != nil { if err != nil {
return nil, fmt.Errorf("Unable to list CloudFormation stacks: %v", err) return nil, fmt.Errorf("unable to list CloudFormation stacks: %v", err)
} }
for _, stack := range response.StackSummaries { for _, stack := range response.StackSummaries {
if *stack.StackName == clusterName { if *stack.StackName == clusterName {

View File

@ -71,7 +71,7 @@ func LoadModel(basedir string) (*Model, error) {
spec.InstanceGroups = append(spec.InstanceGroups, v) spec.InstanceGroups = append(spec.InstanceGroups, v)
default: default:
return nil, fmt.Errorf("Unhandled kind %q", gvk) return nil, fmt.Errorf("unhandled kind %q", gvk)
} }
} }

View File

@ -61,7 +61,7 @@ func SplitInto8(parent *net.IPNet) ([]*net.IPNet, error) {
Mask: net.CIDRMask(networkLength, 32), Mask: net.CIDRMask(networkLength, 32),
}) })
} else { } else {
return nil, fmt.Errorf("Unexpected IP address type: %s", parent) return nil, fmt.Errorf("unexpected IP address type: %s", parent)
} }
} }