Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
- Add .golangci.yaml config with only unused linter enabled
  • Loading branch information
panslava committed Aug 27, 2024
1 parent 1de8477 commit f63dfe7
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 68 deletions.
11 changes: 11 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
linters:
# Disable all linters.
# Default: false
disable-all: true
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default-linters
enable:
- unused

run:
timeout: 3m
1 change: 0 additions & 1 deletion cmd/gcp-controller-manager/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ go_test(
"//vendor/github.com/google/go-cmp/cmp/cmpopts",
"//vendor/google.golang.org/api/compute/v0.beta:v0_beta",
"//vendor/google.golang.org/api/compute/v1:compute",
"//vendor/google.golang.org/api/container/v1:container",
"//vendor/k8s.io/api/authorization/v1:authorization",
"//vendor/k8s.io/api/certificates/v1:certificates",
"//vendor/k8s.io/api/certificates/v1beta1",
Expand Down
1 change: 0 additions & 1 deletion cmd/gcp-controller-manager/dpwi/nodesyncer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ go_library(
"//vendor/k8s.io/client-go/informers/core/v1:core",
"//vendor/k8s.io/client-go/tools/cache",
"//vendor/k8s.io/client-go/tools/clientcmd/api",
"//vendor/k8s.io/client-go/util/workqueue",
],
)

Expand Down
2 changes: 0 additions & 2 deletions cmd/gcp-controller-manager/dpwi/nodesyncer/nodesyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
coreinformers "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/tools/cache"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/util/workqueue"
"k8s.io/cloud-provider-gcp/cmd/gcp-controller-manager/dpwi/auth"
"k8s.io/cloud-provider-gcp/cmd/gcp-controller-manager/dpwi/ctxlog"
"k8s.io/cloud-provider-gcp/cmd/gcp-controller-manager/dpwi/eventhandler"
Expand All @@ -48,7 +47,6 @@ type NodeHandler struct {
eventhandler.EventHandler
podIndexer cache.Indexer
nodeIndexer cache.Indexer
queue workqueue.RateLimitingInterface
verifier verifier
auth *auth.Client
nodeMap *nodeMap
Expand Down
16 changes: 0 additions & 16 deletions cmd/gcp-controller-manager/dpwi/serviceaccounts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"sync"

"k8s.io/client-go/tools/cache"
"k8s.io/cloud-provider-gcp/cmd/gcp-controller-manager/dpwi/ctxlog"
)

Expand Down Expand Up @@ -60,14 +59,6 @@ func (sa ServiceAccount) Key() string {
return fmt.Sprintf("%s/%s", sa.Namespace, sa.Name)
}

func saFromKey(key string) (ServiceAccount, error) {
namespace, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
return ServiceAccount{}, err
}
return ServiceAccount{namespace, name}, nil
}

// Serialize returns m in its JSON encoded format or error if serialization had failed.
func (m *SAMap) Serialize() ([]byte, error) {
m.RLock()
Expand Down Expand Up @@ -115,13 +106,6 @@ func (m *saMap) get(sa ServiceAccount) (GSAEmail, bool) {
return gsa, ok
}

// Serialize returns m in its JSON encoded format or error if serialization had failed.
func (m *saMap) serialize() ([]byte, error) {
m.RLock()
defer m.RUnlock()
return json.Marshal(m.ma)
}

type verifyResult struct {
preVerifiedGSA GSAEmail
curGSA GSAEmail
Expand Down
41 changes: 0 additions & 41 deletions cmd/gcp-controller-manager/node_csr_approver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
betacompute "google.golang.org/api/compute/v0.beta"
compute "google.golang.org/api/compute/v1"
container "google.golang.org/api/container/v1"
authorization "k8s.io/api/authorization/v1"
capi "k8s.io/api/certificates/v1"
certsv1 "k8s.io/api/certificates/v1"
Expand Down Expand Up @@ -296,11 +295,6 @@ func TestNodeApproverHandle(t *testing.T) {
}
}

// stringPointer copies a constant string and returns a pointer to the copy.
func stringPointer(str string) *string {
return &str
}

func TestValidators(t *testing.T) {
t.Run("isLegacyNodeClientCert", func(t *testing.T) {
goodCase := func(b *csrBuilder, _ *controllerContext) {
Expand Down Expand Up @@ -725,41 +719,6 @@ func fakeGCPAPI(t *testing.T, ekPub *rsa.PublicKey) (*http.Client, *httptest.Ser
return cl, srv
}

func fakeGKEAPI(t *testing.T) (*http.Client, *httptest.Server) {
srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
t.Logf("fakeGKEAPI request %q", req.URL.Path)
switch req.URL.Path {
case "/v1/projects/p0/locations/z0/clusters/c0":
json.NewEncoder(rw).Encode(container.Cluster{
Name: "c0",
NodePools: []*container.NodePool{
{InstanceGroupUrls: []string{"https://www.googleapis.com/compute/v1/projects/2/zones/r0/instanceGroupManagers/ig0"}},
{InstanceGroupUrls: []string{"https://www.googleapis.com/compute/v1/projects/2/zones/z0/instanceGroupManagers/ig0"}},
},
})
case "/v1/projects/p0/locations/z0/clusters/c1":
json.NewEncoder(rw).Encode(container.Cluster{
Name: "c1",
NodePools: []*container.NodePool{
{InstanceGroupUrls: []string{"https://www.googleapis.com/compute/v1/projects/2/zones/z0/instanceGroupManagers/ig1"}},
},
})
case "/v1/projects/p0/locations/z0/clusters/c2":
json.NewEncoder(rw).Encode(container.Cluster{
Name: "c2",
NodePools: []*container.NodePool{
{InstanceGroupUrls: []string{"https://www.googleapis.com/compute/v1/projects/2/zones/z0/instanceGroupManagers/unknown"}},
},
})
default:
http.Error(rw, "not found", http.StatusNotFound)
}
}))
cl := srv.Client()
cl.Transport = fakeTransport{srv.URL}
return cl, srv
}

type fakeTransport struct{ addr string }

func (t fakeTransport) RoundTrip(r *http.Request) (*http.Response, error) {
Expand Down
1 change: 0 additions & 1 deletion cmd/gke-gcloud-auth-plugin/cred_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var (
"extra_args": "%s"
}
`
invalidCacheFile = "invalid_cache_file"
fakeCurrentContext = "gke_user-gke-dev_us-east1-b_cluster-1"
cachedAccessToken = "ya29.cached_token"

Expand Down
6 changes: 0 additions & 6 deletions pkg/controller/nodeipam/ipam/cidr_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ const (
// cidrUpdateRetries is the no. of times a NodeSpec update will be retried before dropping it.
cidrUpdateRetries = 3

// updateRetryTimeout is the time to wait before requeing a failed node for retry
updateRetryTimeout = 250 * time.Millisecond

// maxUpdateRetryTimeout is the maximum amount of time between timeouts.
maxUpdateRetryTimeout = 5 * time.Second

// updateMaxRetries is the max retries for a failed node
updateMaxRetries = 10
)
Expand Down

0 comments on commit f63dfe7

Please sign in to comment.