diff --git a/.golangci.yml b/.golangci.yml index 129a0dd..d0c5d61 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,8 +2,7 @@ linters: disable-all: true enable: - bodyclose - - deadcode - - depguard + # - depguard - dogsled - dupl - errcheck @@ -29,17 +28,33 @@ linters: - revive - rowserrcheck - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unparam - unused - - varcheck - whitespace issues: exclude: - Using the variable on range scope .* in function literal + # depguard: + # rules: + # Main: + # files: + # - "$all" + # # List of allowed packages. + # allow: + # - $gostd + # - github.com/OpenPeeDeeP + # - github.com/Masterminds/semver + # - github.com/aws + # - github.com/jedib0t + # - github.com/mateimicu + # - github.com/spf13 + # - github.com/stretchr - k8s.io + # # Packages that are not allowed where the value is a suggestion. + # deny: + linters-settings: errcheck: diff --git a/README.md b/README.md index e1cf321..9df7047 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # kdiscover -![CI](https://github.com/mateimicu/kdiscover/workflows/Lint%20&%20build%20Golang%20project/badge.svg?branch=master) +[![CI](https://github.com/mateimicu/kdiscover/actions/workflows/golang-ci.yaml/badge.svg?branch=master)](https://github.com/mateimicu/kdiscover/actions/workflows/golang-ci.yaml) ![CodeQL](https://github.com/mateimicu/kdiscover/workflows/CodeQL/badge.svg) [![codecov](https://codecov.io/gh/mateimicu/kdiscover/branch/master/graph/badge.svg)](https://codecov.io/gh/mateimicu/kdiscover) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/mateimicu/kdiscover?sort=semver) diff --git a/cmd/aws.go b/cmd/aws.go index 4066447..5cf3cf2 100644 --- a/cmd/aws.go +++ b/cmd/aws.go @@ -30,7 +30,7 @@ func newAWSCommand() *cobra.Command { // An issue about this https://github.com/spf13/cobra/issues/252 root := cmd for ; root.HasParent(); root = root.Parent() { - } + } //revive:disable-line:empty-block err := root.PersistentPreRunE(cmd, args) if err != nil { return err diff --git a/cmd/aws_list_test.go b/cmd/aws_list_test.go index 2805908..ee234cd 100644 --- a/cmd/aws_list_test.go +++ b/cmd/aws_list_test.go @@ -13,7 +13,7 @@ import ( type mockExportable struct{} -func (mockExportable) IsExported(cls kubeconfig.Endpointer) bool { +func (mockExportable) IsExported(_ kubeconfig.Endpointer) bool { return false } diff --git a/cmd/aws_update.go b/cmd/aws_update.go index a102b79..1ca29a9 100644 --- a/cmd/aws_update.go +++ b/cmd/aws_update.go @@ -26,7 +26,7 @@ func backupKubeConfig(kubeconfigPath string) (string, error) { "err": err.Error(), }).Info("Can't generate backup file name ") } - err = copy(kubeconfigPath, bName) + err = copyFs(kubeconfigPath, bName) if err != nil { return "", err } @@ -81,7 +81,7 @@ func newUpdateCommand() *cobra.Command { return updateCommand } -func copy(src, dst string) error { +func copyFs(src, dst string) error { sourceFileStat, err := os.Stat(src) if err != nil { return err diff --git a/internal/aws/eks_test.go b/internal/aws/eks_test.go index 0973945..0f36ed0 100644 --- a/internal/aws/eks_test.go +++ b/internal/aws/eks_test.go @@ -53,7 +53,8 @@ func (c *mockEKSClient) ListClustersPages(_ *eks.ListClustersInput, fn func(*eks // prepare clusters for _, cls := range c.Clusters[start:end] { - clusters = append(clusters, &cls.Name) + localCluster := *cls + clusters = append(clusters, &localCluster.Name) } o.Clusters = clusters lastPage := end == len(c.Clusters) @@ -80,12 +81,13 @@ func (c *mockEKSClient) DescribeCluster(input *eks.DescribeClusterInput) (*eks.D } for _, cls := range c.Clusters { + localCluster := *cls if *input.Name == cls.Name { cluster := eks.Cluster{} - cluster.Arn = &cls.ID - cluster.Endpoint = &cls.Endpoint - cluster.Name = &cls.Name - cluster.Status = &cls.Status + cluster.Arn = &localCluster.ID + cluster.Endpoint = &localCluster.Endpoint + cluster.Name = &localCluster.Name + cluster.Status = &localCluster.Status cert := eks.Certificate{} data := base64.StdEncoding.EncodeToString([]byte(cls.CertificateAuthorityData)) @@ -238,6 +240,7 @@ func TestGetClustersNoFailure(t *testing.T) { t.Parallel() log.SetOutput(ioutil.Discard) for _, tt := range cases { + client := tt.Client describeErrorCount := 0 for k := range tt.Client.ErrorOnDescribe { if k > len(tt.Client.Clusters) { @@ -258,7 +261,7 @@ func TestGetClustersNoFailure(t *testing.T) { t.Run(testname, func(t *testing.T) { ch := make(chan *cluster.Cluster) c := EKSClient{ - EKS: &tt.Client, + EKS: &client, Region: tt.Region, } go c.GetClusters(ch) @@ -311,6 +314,7 @@ func TestGetClustersListFailure(t *testing.T) { }, } for _, tt := range tts { + client := tt.Client describeErrorCount := 0 for k := range tt.Client.ErrorOnDescribe { if k > len(tt.Client.Clusters) { @@ -331,7 +335,7 @@ func TestGetClustersListFailure(t *testing.T) { t.Run(testname, func(t *testing.T) { ch := make(chan *cluster.Cluster) c := EKSClient{ - EKS: &tt.Client, + EKS: &client, Region: tt.Region, } go c.GetClusters(ch) diff --git a/internal/cluster/testing.go b/internal/cluster/testing.go index 65010f8..95bcbed 100644 --- a/internal/cluster/testing.go +++ b/internal/cluster/testing.go @@ -27,7 +27,7 @@ func randomString(length int) string { return stringWithCharset(length, charset) } -func dummyGenerateAuthInfo(cls *Cluster) *clientcmdapi.AuthInfo { +func dummyGenerateAuthInfo(_ *Cluster) *clientcmdapi.AuthInfo { return clientcmdapi.NewAuthInfo() }