Skip to content

Commit

Permalink
Remove unused code, add unused linter check
Browse files Browse the repository at this point in the history
  • Loading branch information
panslava committed Sep 18, 2024
1 parent 0a04c98 commit f9d8981
Show file tree
Hide file tree
Showing 40 changed files with 15 additions and 311 deletions.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ linters:
enable:
- errcheck
- forbidigo
- unused

issues:
exclude-rules:
Expand Down
1 change: 0 additions & 1 deletion cmd/404-server-with-metrics/server-with-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
var (
port = flag.Int("port", 8080, "Port number to serve default backend 404 page.")
metricsPort = flag.Int("metricsPort", 8081, "Port number to serve metrics for the default backend 404 page.")
serverTimeout = flag.Duration("timeout", 5*time.Second, "Time in seconds to wait before forcefully terminating the server.")
readTimeout = flag.Duration("read_timeout", 10*time.Second, "Time in seconds to read the entire request before timing out.")
readHeaderTimeout = flag.Duration("read_header_timeout", 10*time.Second, "Time in seconds to read the request header before timing out.")
writeTimeout = flag.Duration("write_timeout", 10*time.Second, "Time in seconds to write response before timing out.")
Expand Down
7 changes: 0 additions & 7 deletions cmd/check-gke-ingress/app/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"context"
"fmt"
"os"
"reflect"
"runtime"

networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -84,7 +82,6 @@ func RunChecks(ingresses []networkingv1.Ingress, client kubernetes.Interface, be
Checks: []*report.Check{},
}
ingressChecker := &IngressChecker{
client: client,
ingress: &ingress,
}

Expand Down Expand Up @@ -177,7 +174,3 @@ func addCheckResult(ingressRes *report.Resource, checkName, msg, res string) {
Result: res,
})
}

func getCheckName(check func()) string {
return runtime.FuncForPC(reflect.ValueOf(check).Pointer()).Name()
}
8 changes: 1 addition & 7 deletions cmd/check-gke-ingress/app/ingress/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/ingress-gce/cmd/check-gke-ingress/app/report"
"k8s.io/ingress-gce/pkg/annotations"
beconfigv1 "k8s.io/ingress-gce/pkg/apis/backendconfig/v1"
feconfigv1beta1 "k8s.io/ingress-gce/pkg/apis/frontendconfig/v1beta1"
beconfigclient "k8s.io/ingress-gce/pkg/backendconfig/client/clientset/versioned"
feconfigclient "k8s.io/ingress-gce/pkg/frontendconfig/client/clientset/versioned"
)
Expand All @@ -48,8 +47,6 @@ const (
)

type IngressChecker struct {
// Kubernetes client
client clientset.Interface
// Ingress object to be checked
ingress *networkingv1.Ingress
}
Expand Down Expand Up @@ -89,8 +86,6 @@ type FrontendConfigChecker struct {
namespace string
// Name of the frontendConfig
name string
// FrontendConfig object to be checked
feConfig *feconfigv1beta1.FrontendConfig
}

type ingressCheckFunc func(c *IngressChecker) (string, string, string)
Expand Down Expand Up @@ -250,14 +245,13 @@ func CheckHealthCheckTimeout(c *BackendConfigChecker) (string, string, string) {

// CheckFrontendConfigExistence checks whether a FrontendConfig exists.
func CheckFrontendConfigExistence(c *FrontendConfigChecker) (string, string, string) {
feConfig, err := c.client.NetworkingV1beta1().FrontendConfigs(c.namespace).Get(context.TODO(), c.name, metav1.GetOptions{})
_, err := c.client.NetworkingV1beta1().FrontendConfigs(c.namespace).Get(context.TODO(), c.name, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return FrontendConfigExistenceCheck, report.Failed, fmt.Sprintf("FrontendConfig %s/%s does not exist", c.namespace, c.name)
}
return FrontendConfigExistenceCheck, report.Failed, fmt.Sprintf("Failed to get frontendConfig %s/%s", c.namespace, c.name)
}
c.feConfig = feConfig
return FrontendConfigExistenceCheck, report.Passed, fmt.Sprintf("FrontendConfig %s/%s found", c.namespace, c.name)
}

Expand Down
1 change: 0 additions & 1 deletion cmd/e2e-test/upgrade/psc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type PSC struct {
t *testing.T
s *e2e.Sandbox
framework *e2e.Framework
gceSAURL string
}

func NewPSCUpgradeTest() e2e.UpgradeTest {
Expand Down
9 changes: 0 additions & 9 deletions cmd/fuzzer/app/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
backendconfig "k8s.io/ingress-gce/pkg/backendconfig/client/clientset/versioned"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/fuzz"
"k8s.io/ingress-gce/pkg/fuzz/features"
Expand Down Expand Up @@ -177,11 +176,3 @@ func k8sClientSet(config *rest.Config) *kubernetes.Clientset {
}
return clientset
}

func backendConfigClientset(config *rest.Config) *backendconfig.Clientset {
clientset, err := backendconfig.NewForConfig(config)
if err != nil {
panic(err.Error())
}
return clientset
}
2 changes: 0 additions & 2 deletions pkg/backends/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type Jig struct {
fakeInstancePool instancegroups.Manager
linker Linker
syncer Syncer
pool Pool
}

func newTestJig(fakeGCE *gce.Cloud) *Jig {
Expand Down Expand Up @@ -78,7 +77,6 @@ func newTestJig(fakeGCE *gce.Cloud) *Jig {
fakeInstancePool: fakeInstancePool,
linker: NewInstanceGroupLinker(fakeInstancePool, fakeBackendPool, klog.TODO()),
syncer: NewBackendSyncer(fakeBackendPool, fakeHealthChecks, fakeGCE),
pool: fakeBackendPool,
}
}

Expand Down
7 changes: 0 additions & 7 deletions pkg/composite/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

const (
// Version strings for recording metrics.
computeV1Version = "v1"
computeAlphaVersion = "alpha"
computeBetaVersion = "beta"
)

type apiCallMetrics struct {
latency *prometheus.HistogramVec
errors *prometheus.CounterVec
Expand Down
11 changes: 0 additions & 11 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ import (
type LoadBalancerController struct {
ctx *context.ControllerContext

nodeLister cache.Indexer

// TODO: Watch secrets
ingQueue utils.TaskQueue
Translator *legacytranslator.Translator
Expand Down Expand Up @@ -101,9 +99,6 @@ type LoadBalancerController struct {
// Ingress usage metrics.
metrics metrics.IngressMetricsCollector

ingClassLister cache.Indexer
ingParamsLister cache.Indexer

ZoneGetter *zonegetter.ZoneGetter

logger klog.Logger
Expand Down Expand Up @@ -132,7 +127,6 @@ func NewLoadBalancerController(

lbc := LoadBalancerController{
ctx: ctx,
nodeLister: ctx.NodeInformer.GetIndexer(),
Translator: ctx.Translator,
stopCh: stopCh,
hasSynced: ctx.HasSynced,
Expand All @@ -146,11 +140,6 @@ func NewLoadBalancerController(
logger: logger,
}

if ctx.IngClassInformer != nil {
lbc.ingClassLister = ctx.IngClassInformer.GetIndexer()
lbc.ingParamsLister = ctx.IngParamsInformer.GetIndexer()
}

lbc.ingSyncer = ingsync.NewIngressSyncer(&lbc, logger)
lbc.ingQueue = utils.NewPeriodicTaskQueueWithMultipleWorkers("ingress", "ingresses", flags.F.NumIngressWorkers, lbc.sync, logger)
lbc.backendSyncer.Init(lbc.Translator)
Expand Down
2 changes: 0 additions & 2 deletions pkg/controller/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func NewTranslator(serviceInformer cache.SharedIndexInformer,
EndpointSliceInformer: endpointSliceInformer,
KubeClient: kubeClient,
enableTHC: enableTHC,
recorderGetter: recorderGetter,
enableL7XLBRegional: enableL7XLBRegional,
logger: logger.WithName("Translator"),
}
Expand All @@ -100,7 +99,6 @@ type Translator struct {
PodInformer cache.SharedIndexInformer
EndpointSliceInformer cache.SharedIndexInformer
KubeClient kubernetes.Interface
recorderGetter healthchecks.RecorderGetter
enableTHC bool
enableL7XLBRegional bool

Expand Down
12 changes: 2 additions & 10 deletions pkg/controller/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ package translator
import (
"encoding/json"
"fmt"
"k8s.io/klog/v2"
"os"
"reflect"
"testing"
"time"

"k8s.io/klog/v2"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/kr/pretty"
Expand Down Expand Up @@ -1136,14 +1137,6 @@ func gceURLMapFromFile(t *testing.T, filename string) *utils.GCEURLMap {
return v
}

func int64ToMap(l []int64) map[int64]bool {
ret := map[int64]bool{}
for _, i := range l {
ret[i] = true
}
return ret
}

func TestSetTrafficScaling(t *testing.T) {
// No t.Parallel()

Expand Down Expand Up @@ -1383,7 +1376,6 @@ func TestSetThcOptInOnSvc(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
translator := fakeTranslator()
translator.recorderGetter = healthchecks.NewFakeRecorderGetter(0)
translator.enableTHC = tc.enableTHC
sp := *tc.sp

Expand Down
41 changes: 0 additions & 41 deletions pkg/controller/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ package controller
import (
"reflect"
"testing"
"time"

"google.golang.org/api/compute/v1"

api_v1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
Expand All @@ -35,10 +33,6 @@ import (
"k8s.io/ingress-gce/pkg/utils/zonegetter"
)

// Pods created in loops start from this time, for routines that
// sort on timestamp.
var firstPodCreationTime = time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC)

func TestZoneListing(t *testing.T) {
lbc := newLoadBalancerController()
zoneToNode := map[string][]string{
Expand All @@ -65,41 +59,6 @@ func TestZoneListing(t *testing.T) {
}
}

/*
* TODO(rramkumar): Move to pkg/instances in another PR
func TestInstancesAddedToZones(t *testing.T) {
lbc := newLoadBalancerController()
zoneToNode := map[string][]string{
"zone-1": {"n1", "n2"},
"zone-2": {"n3"},
}
addNodes(lbc, zoneToNode)
// Create 2 igs, one per zone.
testIG := "test-ig"
lbc.instancePool.EnsureInstanceGroupsAndPorts(testIG, []int64{int64(3001)})
// node pool syncs kube-nodes, this will add them to both igs.
lbc.instancePool.Sync([]string{"n1", "n2", "n3"})
gotZonesToNode := lbc.instancePool.GetInstancesByZone()
for z, nodeNames := range zoneToNode {
if ig, err := lbc.instancePool.GetInstanceGroup(testIG, z); err != nil {
t.Errorf("Failed to find ig %v in zone %v, found %+v: %v", testIG, z, ig, err)
}
expNodes := sets.NewString(nodeNames...)
gotNodes := sets.NewString(gotZonesToNode[z]...)
if !gotNodes.Equal(expNodes) {
t.Errorf("Nodes not added to zones, expected %+v got %+v", expNodes, gotNodes)
}
}
}
*/

func getProbePath(p *api_v1.Probe) string {
return p.ProbeHandler.HTTPGet.Path
}

func TestAddInstanceGroupsAnnotation(t *testing.T) {
testCases := []struct {
Igs []*compute.InstanceGroup
Expand Down
2 changes: 0 additions & 2 deletions pkg/crd/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ type CRDMeta struct {
singular string
plural string
shortNames []string
typeSource string
fn common.GetOpenAPIDefinitions
}

// NewCRDMeta creates a CRDMeta type which can be passed to a CRDHandler in
Expand Down
2 changes: 0 additions & 2 deletions pkg/experimental/workload/daemon/provider/gce/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type VM struct {
instanceName string
hostname string
internalIP string
externalIP string
projectID string
region string
zone string
Expand Down Expand Up @@ -256,7 +255,6 @@ func NewVM(logger klog.Logger) (vm *VM, err error) {
instanceName: getAttrOrPanic(metadata.InstanceName, "InstanceName", logger),
hostname: getAttrOrPanic(metadata.Hostname, "Hostname", logger),
internalIP: getAttrOrPanic(metadata.InternalIP, "InternalIP", logger),
externalIP: getAttrOrPanic(metadata.ExternalIP, "ExternalIP", logger),
projectID: getAttrOrPanic(metadata.ProjectID, "ProjectID", logger),
zone: getAttrOrPanic(metadata.Zone, "Zone", logger),
// Fetch the cluster name and zone
Expand Down
20 changes: 0 additions & 20 deletions pkg/experimental/workload/daemon/utils/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,3 @@ users:
expiry-key: '{.token_expiry}'
token-key: '{.access_token}'
name: {{.authProvider}}`

const kubeConfigKsaTemp = `
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: {{.clusterCa}}
server: https://{{.clusterIP}}
name: {{.clusterName}}
contexts:
- context:
cluster: {{.clusterName}}
user: {{.saName}}
name: {{.clusterName}}
current-context: {{.clusterName}}
kind: Config
preferences: {}
users:
- name: {{.saName}}
user:
token: {{.accessToken}}`
2 changes: 0 additions & 2 deletions pkg/firewalls/firewalls_l7_cr.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (

// FirewallRules manages firewall rules.
type FirewallCR struct {
cloud Firewall
namer *namer_util.Namer
srcRanges []string
// TODO(rramkumar): Eliminate this variable. We should just pass in
Expand All @@ -56,7 +55,6 @@ func NewFirewallCRPool(client firewallclient.Interface, cloud Firewall, namer *n
klog.Fatalf("Could not parse L7 src ranges %v for firewall rule: %v", l7SrcRanges, err)
}
return &FirewallCR{
cloud: cloud,
namer: namer,
srcRanges: l7SrcRanges,
nodePortRanges: nodePortRanges,
Expand Down
6 changes: 0 additions & 6 deletions pkg/fuzz/features/ilb.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ func (*ILBFeature) Name() string {
// ILBValidator is an example validator.
type ILBValidator struct {
fuzz.NullValidator

ing *v1.Ingress
env fuzz.ValidatorEnv
}

// Name implements fuzz.FeatureValidator.
Expand All @@ -54,9 +51,6 @@ func (*ILBValidator) Name() string {

// ConfigureAttributes implements fuzz.FeatureValidator.
func (v *ILBValidator) ConfigureAttributes(env fuzz.ValidatorEnv, ing *v1.Ingress, a *fuzz.IngressValidatorAttributes) error {
// Capture the env for use later in CheckResponse.
v.ing = ing
v.env = env
return nil
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/healthchecks/healthchecks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,11 +1203,7 @@ func hcFromBC(bchcc *backendconfigv1.HealthCheckConfig, neg bool, json bool) *co
func (f *syncSPFixture) hcs() *compute.HealthCheck { return f.toS(f.hc()) }
func (f *syncSPFixture) hc2() *compute.HealthCheck { return f.to2(f.hc()) }
func (f *syncSPFixture) negs() *compute.HealthCheck { return f.toS(f.neg()) }
func (f *syncSPFixture) neg2() *compute.HealthCheck { return f.to2(f.neg()) }
func (f *syncSPFixture) ilbs() *compute.HealthCheck { return f.toS(f.ilb()) }
func (f *syncSPFixture) ilb2() *compute.HealthCheck { return f.to2(f.ilb()) }
func (f *syncSPFixture) thcs() *compute.HealthCheck { panic("no such thing exists") }
func (f *syncSPFixture) thc2() *compute.HealthCheck { panic("no such thing exists") }

func (f *syncSPFixture) toS(h *compute.HealthCheck) *compute.HealthCheck {
h.Type = "HTTPS"
Expand Down
Loading

0 comments on commit f9d8981

Please sign in to comment.