From 5134a4581308904328774f40cc5a3174110a68a4 Mon Sep 17 00:00:00 2001 From: "yuxing.lyx" Date: Wed, 25 Oct 2023 16:12:07 +0800 Subject: [PATCH] chore: fix golang ci lint error Signed-off-by: yuxing.lyx --- .golangci.yml | 12 +++++++----- pkg/checker/node_checker.go | 4 ++-- pkg/checker/pod_checker.go | 4 ++-- pkg/infra/aliyun/ali_ecs.go | 5 +---- pkg/infra/container/container.go | 5 +---- pkg/infradriver/ssh_infradriver.go | 8 ++++---- test/testhelper/utils.go | 10 ++-------- utils/archive/compress.go | 2 +- utils/ssh/ssh.go | 16 ++++++++-------- utils/yaml/yaml.go | 6 +----- 10 files changed, 29 insertions(+), 43 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 45c60687bab..e22e81dddd5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,7 +25,7 @@ linters: enable: - gofmt - goimports - - golint + - revive - stylecheck - goconst - gosimple @@ -34,16 +34,12 @@ linters: - ineffassign - vet - typecheck - - deadcode - errcheck - govet - staticcheck - - structcheck - unused - - varcheck - nilerr - unparam - - ifshort - unconvert issues: @@ -51,6 +47,12 @@ issues: - linters: - golint text: "AccessKeyId" + - linters: + - typecheck + text: "has no field or method" + - linters: + - revive + text: "just return error instead" # golangci.com configuration # https://github.com/golangci/golangci/wiki/Configuration diff --git a/pkg/checker/node_checker.go b/pkg/checker/node_checker.go index 992e8571065..93e8963cb4f 100644 --- a/pkg/checker/node_checker.go +++ b/pkg/checker/node_checker.go @@ -58,9 +58,9 @@ func (n *NodeChecker) Check(cluster *v2.Cluster, phase string) error { return err } var notReadyNodeList []string - var readyCount uint32 = 0 + var readyCount uint32 var nodeCount uint32 - var notReadyCount uint32 = 0 + var notReadyCount uint32 for _, node := range nodes.Items { nodeIP, nodePhase := getNodeStatus(node) if nodePhase != ReadyNodeStatus { diff --git a/pkg/checker/pod_checker.go b/pkg/checker/pod_checker.go index c587ce67b11..d4d023a7865 100644 --- a/pkg/checker/pod_checker.go +++ b/pkg/checker/pod_checker.go @@ -55,8 +55,8 @@ func (n *PodChecker) Check(cluster *v2.Cluster, phase string) error { return err } for _, podNamespace := range namespacePodList { - var runningCount uint32 = 0 - var notRunningCount uint32 = 0 + var runningCount uint32 + var notRunningCount uint32 var podCount uint32 var notRunningPodList []*corev1.Pod for _, pod := range podNamespace.PodList.Items { diff --git a/pkg/infra/aliyun/ali_ecs.go b/pkg/infra/aliyun/ali_ecs.go index ef438e578e0..b39e7ebc195 100644 --- a/pkg/infra/aliyun/ali_ecs.go +++ b/pkg/infra/aliyun/ali_ecs.go @@ -52,10 +52,7 @@ func (a *AliProvider) RetryEcsRequest(request requests.AcsRequest, response resp func (a *AliProvider) RetryEcsAction(request requests.AcsRequest, response responses.AcsResponse, tryTimes int) error { return utils.Retry(tryTimes, TrySleepTime, func() error { - if err := a.EcsClient.DoAction(request, response); err != nil { - return err - } - return nil + return a.EcsClient.DoAction(request, response) }) } diff --git a/pkg/infra/container/container.go b/pkg/infra/container/container.go index 6d9571e1c94..d3854dc011d 100644 --- a/pkg/infra/container/container.go +++ b/pkg/infra/container/container.go @@ -146,10 +146,7 @@ func (a *ApplyProvider) ReconcileContainer() error { if err := a.applyResult(masterApplyResult); err != nil { return err } - if err := a.applyResult(nodeApplyResult); err != nil { - return err - } - return nil + return a.applyResult(nodeApplyResult) } func (a *ApplyProvider) applyResult(result *ApplyResult) error { diff --git a/pkg/infradriver/ssh_infradriver.go b/pkg/infradriver/ssh_infradriver.go index 91014d63529..7c349f7cccf 100644 --- a/pkg/infradriver/ssh_infradriver.go +++ b/pkg/infradriver/ssh_infradriver.go @@ -94,12 +94,12 @@ func NewInfraDriver(cluster *v2.Cluster) (InfraDriver, error) { } // initialize sshConfigs field - for _, host := range cluster.Spec.Hosts { - if err = mergo.Merge(&host.SSH, &cluster.Spec.SSH); err != nil { + for i := range cluster.Spec.Hosts { + if err = mergo.Merge(&cluster.Spec.Hosts[i].SSH, &cluster.Spec.SSH); err != nil { return nil, err } - for _, ip := range host.IPS { - ret.sshConfigs[ip.String()] = ssh.NewSSHClient(&host.SSH, true) + for _, ip := range cluster.Spec.Hosts[i].IPS { + ret.sshConfigs[ip.String()] = ssh.NewSSHClient(&cluster.Spec.Hosts[i].SSH, true) } } diff --git a/test/testhelper/utils.go b/test/testhelper/utils.go index 75a1dff9e8f..aa474d65428 100644 --- a/test/testhelper/utils.go +++ b/test/testhelper/utils.go @@ -73,10 +73,7 @@ func WriteFile(fileName string, content []byte) error { } } - if err := os.WriteFile(fileName, content, settings.FileMode0644); err != nil { - return err - } - return nil + return os.WriteFile(fileName, content, settings.FileMode0644) } type SSHClient struct { @@ -148,10 +145,7 @@ func MarshalYamlToFile(file string, obj interface{}) error { if err != nil { return err } - if err = WriteFile(file, data); err != nil { - return err - } - return nil + return WriteFile(file, data) } // GetLocalFileData get file data from local diff --git a/utils/archive/compress.go b/utils/archive/compress.go index 4c7d80a7e8c..4ca82db24cc 100644 --- a/utils/archive/compress.go +++ b/utils/archive/compress.go @@ -327,7 +327,7 @@ func Decompress(src io.Reader, dst string, options Options) (int64, error) { } var ( - size int64 = 0 + size int64 dirs []*tar.Header tr = tar.NewReader(reader) ) diff --git a/utils/ssh/ssh.go b/utils/ssh/ssh.go index 14db2a184a6..43b1bc51686 100644 --- a/utils/ssh/ssh.go +++ b/utils/ssh/ssh.go @@ -88,13 +88,13 @@ func NewSSHClient(ssh *v1.SSH, alsoToStdout bool) Interface { // GetHostSSHClient is used to executed bash command and no std out to be printed. func GetHostSSHClient(hostIP net.IP, cluster *v2.Cluster) (Interface, error) { - for _, host := range cluster.Spec.Hosts { - for _, ip := range host.IPS { + for i := range cluster.Spec.Hosts { + for _, ip := range cluster.Spec.Hosts[i].IPS { if hostIP.Equal(ip) { - if err := mergo.Merge(&host.SSH, &cluster.Spec.SSH); err != nil { + if err := mergo.Merge(&cluster.Spec.Hosts[i].SSH, &cluster.Spec.SSH); err != nil { return nil, err } - return NewSSHClient(&host.SSH, false), nil + return NewSSHClient(&cluster.Spec.Hosts[i].SSH, false), nil } } } @@ -103,13 +103,13 @@ func GetHostSSHClient(hostIP net.IP, cluster *v2.Cluster) (Interface, error) { // NewStdoutSSHClient is used to show std out when execute bash command. func NewStdoutSSHClient(hostIP net.IP, cluster *v2.Cluster) (Interface, error) { - for _, host := range cluster.Spec.Hosts { - for _, ip := range host.IPS { + for i := range cluster.Spec.Hosts { + for _, ip := range cluster.Spec.Hosts[i].IPS { if hostIP.Equal(ip) { - if err := mergo.Merge(&host.SSH, &cluster.Spec.SSH); err != nil { + if err := mergo.Merge(&cluster.Spec.Hosts[i].SSH, &cluster.Spec.SSH); err != nil { return nil, err } - return NewSSHClient(&host.SSH, true), nil + return NewSSHClient(&cluster.Spec.Hosts[i].SSH, true), nil } } } diff --git a/utils/yaml/yaml.go b/utils/yaml/yaml.go index be371e06ab0..8ee0da78249 100644 --- a/utils/yaml/yaml.go +++ b/utils/yaml/yaml.go @@ -46,11 +46,7 @@ func MarshalToFile(file string, obj interface{}) error { return err } - if err = osi.NewAtomicWriter(file).WriteFile(data); err != nil { - return err - } - - return nil + return osi.NewAtomicWriter(file).WriteFile(data) } func MarshalWithDelimiter(configs ...interface{}) ([]byte, error) {