From 1677edc60cbde3ff34fc2412bf05bb48df7515ee Mon Sep 17 00:00:00 2001 From: Omer Aplatony Date: Wed, 4 Dec 2024 12:37:50 +0200 Subject: [PATCH] balancer: fixed lint issues and add linter to CI Signed-off-by: Omer Aplatony --- .github/workflows/ci.yaml | 9 +++++++++ balancer/main.go | 11 +++++++++-- balancer/pkg/controller/controller_test.go | 9 +++++---- balancer/pkg/controller/core.go | 6 +++--- balancer/pkg/pods/summary.go | 2 -- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 19e3aedca9cf..edfeb394b14a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,6 +9,8 @@ env: permissions: contents: read + checks: write + pull-requests: read jobs: test-and-verify: @@ -37,6 +39,13 @@ jobs: run: hack/verify-all.sh -v env: GO111MODULE: auto + + - name: golangci-lint - balancer + uses: golangci/golangci-lint-action@v6 + with: + args: --timeout=30m + working-directory: ${{ env.GOPATH }}/src/k8s.io/autoscaler/balancer + version: v1.60 - name: Test working-directory: ${{ env.GOPATH }}/src/k8s.io/autoscaler diff --git a/balancer/main.go b/balancer/main.go index 38530e528781..d77a7e7afc61 100644 --- a/balancer/main.go +++ b/balancer/main.go @@ -19,9 +19,10 @@ package main import ( "context" "flag" - "k8s.io/klog/v2" "time" + "k8s.io/klog/v2" + "k8s.io/apimachinery/pkg/util/wait" balancerclientset "k8s.io/autoscaler/balancer/pkg/client/clientset/versioned" balancerinformers "k8s.io/autoscaler/balancer/pkg/client/informers/externalversions" @@ -91,6 +92,9 @@ func main() { scaleKindResolver := scaleclient.NewDiscoveryScaleKindResolver(kubeClient.Discovery()) scaleClient, err := scaleclient.NewForConfig(cfg, restMapper, dynamic.LegacyAPIPathResolverFunc, scaleKindResolver) + if err != nil { + klog.Fatalf("Error creaing ScalesGetter: %s", err.Error()) + } podInformer := kubeInformerFactory.Core().V1().Pods() core := controller.NewCore(controller.NewScaleClient(context.TODO(), scaleClient, restMapper), podInformer) @@ -105,5 +109,8 @@ func main() { kubeInformerFactory.Start(stopCh) balancerInformerFactory.Start(stopCh) - controller.Run(concurrency, stopCh) + err = controller.Run(concurrency, stopCh) + if err != nil { + klog.Fatalf("Error: ", err.Error()) + } } diff --git a/balancer/pkg/controller/controller_test.go b/balancer/pkg/controller/controller_test.go index 5ee03247c90a..31885b5645af 100644 --- a/balancer/pkg/controller/controller_test.go +++ b/balancer/pkg/controller/controller_test.go @@ -37,10 +37,10 @@ import ( ) type testContext struct { - statusInfo *BalancerStatusInfo - balancerError *BalancerError - input []balancerapi.Balancer - core *fakeCore + statusInfo *BalancerStatusInfo + balancerError *BalancerError + input []balancerapi.Balancer + // core *fakeCore controller *Controller stop chan struct{} balancerUpdates chan balancerapi.Balancer @@ -211,6 +211,7 @@ func TestController(t *testing.T) { tc.err, !tc.updateFailed, ) + //nolint:errcheck go testContext.controller.Run(1, testContext.stop) if !tc.updateFailed { diff --git a/balancer/pkg/controller/core.go b/balancer/pkg/controller/core.go index 25f1e16c292a..a7003310f356 100644 --- a/balancer/pkg/controller/core.go +++ b/balancer/pkg/controller/core.go @@ -49,9 +49,9 @@ type BalancerStatusInfo struct { updated bool } -func newBalancerStatusInfo(replicas int32, updated bool) BalancerStatusInfo { - return BalancerStatusInfo{replicasObserved: replicas, updated: updated} -} +// func newBalancerStatusInfo(replicas int32, updated bool) BalancerStatusInfo { +// return BalancerStatusInfo{replicasObserved: replicas, updated: updated} +// } // core is CoreInferface implementation. type core struct { diff --git a/balancer/pkg/pods/summary.go b/balancer/pkg/pods/summary.go index 557a680a6d04..79fead2a7fdf 100644 --- a/balancer/pkg/pods/summary.go +++ b/balancer/pkg/pods/summary.go @@ -46,13 +46,11 @@ func CalculateSummary(podList []*v1.Pod, now time.Time, startupTimeout time.Dura case v1.PodRunning: result.Total++ result.Running++ - break case v1.PodPending: result.Total++ if p.CreationTimestamp.Add(startupTimeout).Before(now) { result.NotStartedWithinDeadline++ } - break } } return result