Skip to content

Commit

Permalink
chore: fix golang ci lint error (#2311)
Browse files Browse the repository at this point in the history
Signed-off-by: yuxing.lyx <yuxing.lyx@alibaba-inc.com>
  • Loading branch information
starnop authored Oct 25, 2023
1 parent f9bf927 commit ec4a2c7
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 43 deletions.
12 changes: 7 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ linters:
enable:
- gofmt
- goimports
- golint
- revive
- stylecheck
- goconst
- gosimple
Expand All @@ -34,23 +34,25 @@ linters:
- ineffassign
- vet
- typecheck
- deadcode
- errcheck
- govet
- staticcheck
- structcheck
- unused
- varcheck
- nilerr
- unparam
- ifshort
- unconvert

issues:
exclude-rules:
- 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
Expand Down
4 changes: 2 additions & 2 deletions pkg/checker/node_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/checker/pod_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions pkg/infra/aliyun/ali_ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/infra/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/infradriver/ssh_infradriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
10 changes: 2 additions & 8 deletions test/testhelper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/archive/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
16 changes: 8 additions & 8 deletions utils/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions utils/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ec4a2c7

Please sign in to comment.