Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused code #755

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# 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
3 changes: 1 addition & 2 deletions cmd/gcp-controller-manager/ca_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ type fakeCA struct {
intermediateCert *x509.Certificate
intermediateCertKey *rsa.PrivateKey
validCert *x509.Certificate
validCertKey *rsa.PrivateKey
invalidCerts map[string]*x509.Certificate
srvURL string
}
Expand Down Expand Up @@ -202,7 +201,7 @@ func (ca *fakeCA) regenerateValidCert(t *testing.T, id nodeidentity.Identity) {
if err != nil {
t.Fatal(err)
}
_, ca.validCert, ca.validCertKey = makeCert(t, &x509.Certificate{
_, ca.validCert, _ = makeCert(t, &x509.Certificate{
SerialNumber: big.NewInt(3),
NotBefore: time.Now(),
NotAfter: time.Now().Add(time.Hour),
Expand Down
14 changes: 6 additions & 8 deletions cmd/gcp-controller-manager/csr_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ var (
// gkeSigner uses external calls to GKE in order to sign certificate signing
// requests.
type gkeSigner struct {
webhook *webhook.GenericWebhook
ctx *controllerContext
retryBackoff *wait.Backoff
validators []csrValidator
webhook *webhook.GenericWebhook
ctx *controllerContext
validators []csrValidator
}

// newGKESigner will create a new instance of a gkeSigner.
Expand All @@ -66,10 +65,9 @@ func newGKESigner(ctx *controllerContext) (*gkeSigner, error) {
return nil, err
}
return &gkeSigner{
webhook: webhook,
ctx: ctx,
retryBackoff: ClusterSigningGKERetryBackoff,
validators: csrValidators(),
webhook: webhook,
ctx: ctx,
validators: csrValidators(),
}, nil
}

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
9 changes: 4 additions & 5 deletions cmd/gcp-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ var (
authSyncNodeURL = pflag.String("auth-sync-node-url", "", "URL for reaching the Auth Service SyncNode API.")
hmsAuthorizeSAMappingURL = pflag.String("hms-authorize-sa-mapping-url", "", "URL for reaching the Hosted Master Service AuthorizeSAMapping API.")
hmsSyncNodeURL = pflag.String("hms-sync-node-url", "", "URL for reaching the Hosted Master Service SyncNode API.")
autopilotEnabled = pflag.Bool("autopilot", false, "Is this a GKE Autopilot cluster.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you remove flags, independently they maybe a noop, the manifests using this binary need to be updated or will fail to execute

clearStalePodsOnNodeRegistration = pflag.Bool("clearStalePodsOnNodeRegistration", false, "If true, after node registration, delete pods bound to old node.")
kubeconfigQPS = pflag.Float32("kubeconfig-qps", 100, "QPS to use while talking with kube-apiserver.")
kubeconfigBurst = pflag.Int("kubeconfig-burst", 200, "Burst to use while talking with kube-apiserver.")
// Deprecated: do not use, does not have any effect.
autopilotEnabled = pflag.Bool("autopilot", false, "Is this a GKE Autopilot cluster.")
kubeconfigQPS = pflag.Float32("kubeconfig-qps", 100, "QPS to use while talking with kube-apiserver.")
kubeconfigBurst = pflag.Int("kubeconfig-burst", 200, "Burst to use while talking with kube-apiserver.")
)

func main() {
Expand Down Expand Up @@ -110,7 +111,6 @@ func main() {
hmsAuthorizeSAMappingURL: *hmsAuthorizeSAMappingURL,
hmsSyncNodeURL: *hmsSyncNodeURL,
healthz: healthz.NewHandler(),
autopilotEnabled: *autopilotEnabled,
clearStalePodsOnNodeRegistration: *clearStalePodsOnNodeRegistration,
}
var err error
Expand Down Expand Up @@ -167,7 +167,6 @@ type controllerManager struct {
authSyncNodeURL string
hmsAuthorizeSAMappingURL string
hmsSyncNodeURL string
autopilotEnabled bool
clearStalePodsOnNodeRegistration bool

// Fields initialized from other sources.
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ import (
)

type testGKENetworkParamSetController struct {
networkClient *networkfake.Clientset
informerFactory networkinformers.SharedInformerFactory
clusterValues gce.TestClusterValues
controller *Controller
metrics *controllers.ControllerManagerMetrics
cloud *gce.Cloud
nodeStore cache.Store
networkClient *networkfake.Clientset
clusterValues gce.TestClusterValues
controller *Controller
metrics *controllers.ControllerManagerMetrics
cloud *gce.Cloud
nodeStore cache.Store
}

const (
Expand Down Expand Up @@ -94,13 +93,12 @@ func setupGKENetworkParamSetController(ctx context.Context) *testGKENetworkParam
fakeGCE.Compute().Networks().Insert(ctx, nonDefaultNetworkKey, nonDefaultNetwork)

return &testGKENetworkParamSetController{
networkClient: fakeNetworking,
informerFactory: nwInfFactory,
clusterValues: testClusterValues,
controller: controller,
metrics: metrics,
cloud: fakeGCE,
nodeStore: fakeNodeInformer.Informer().GetStore(),
networkClient: fakeNetworking,
clusterValues: testClusterValues,
controller: controller,
metrics: metrics,
cloud: fakeGCE,
nodeStore: fakeNodeInformer.Informer().GetStore(),
}
}

Expand Down
1 change: 0 additions & 1 deletion pkg/controller/nodeipam/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ go_library(
"//vendor/k8s.io/client-go/informers/core/v1:core",
"//vendor/k8s.io/client-go/kubernetes",
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:core",
"//vendor/k8s.io/client-go/listers/core/v1:core",
"//vendor/k8s.io/client-go/tools/cache",
"//vendor/k8s.io/client-go/tools/record",
"//vendor/k8s.io/cloud-provider",
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
12 changes: 0 additions & 12 deletions pkg/controller/nodeipam/node_ipam_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
coreinformers "k8s.io/client-go/informers/core/v1"
clientset "k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
corelisters "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
cloudprovider "k8s.io/cloud-provider"
Expand All @@ -52,15 +51,9 @@ const (
type Controller struct {
allocatorType ipam.CIDRAllocatorType

cloud cloudprovider.Interface
clusterCIDRs []*net.IPNet
serviceCIDR *net.IPNet
secondaryServiceCIDR *net.IPNet
kubeClient clientset.Interface
// Method for easy mocking in unittest.
lookupIP func(host string) ([]net.IP, error)

nodeLister corelisters.NodeLister
nodeInformerSynced cache.InformerSynced

cidrAllocator ipam.CIDRAllocator
Expand Down Expand Up @@ -111,10 +104,6 @@ func NewNodeIpamController(
}

ic := &Controller{
cloud: cloud,
kubeClient: kubeClient,
lookupIP: net.LookupIP,
clusterCIDRs: clusterCIDRs,
serviceCIDR: serviceCIDR,
secondaryServiceCIDR: secondaryServiceCIDR,
allocatorType: allocatorType,
Expand All @@ -139,7 +128,6 @@ func NewNodeIpamController(
}
}

ic.nodeLister = nodeInformer.Lister()
ic.nodeInformerSynced = nodeInformer.Informer().HasSynced

return ic, nil
Expand Down
2 changes: 0 additions & 2 deletions providers/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ type Cloud struct {
containerService *container.Service
tpuService *tpuService
client clientset.Interface
clientBuilder cloudprovider.ControllerClientBuilder
eventBroadcaster record.EventBroadcaster
eventRecorder record.EventRecorder
projectID string
Expand Down Expand Up @@ -675,7 +674,6 @@ func tryConvertToProjectNames(configProject, configNetworkProject string, servic
// Initialize takes in a clientBuilder and spawns a goroutine for watching the clusterid configmap.
// This must be called before utilizing the funcs of gce.ClusterID
func (g *Cloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) {
g.clientBuilder = clientBuilder
g.client = clientBuilder.ClientOrDie("cloud-provider")

g.eventBroadcaster = record.NewBroadcaster()
Expand Down