Skip to content

Commit

Permalink
balancer: fixed lint issues and add linter to CI
Browse files Browse the repository at this point in the history
Signed-off-by: Omer Aplatony <[email protected]>
  • Loading branch information
omerap12 committed Dec 4, 2024
1 parent 4ec3336 commit 1677edc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ env:

permissions:
contents: read
checks: write
pull-requests: read

jobs:
test-and-verify:
Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions balancer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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())
}
}
9 changes: 5 additions & 4 deletions balancer/pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions balancer/pkg/controller/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions balancer/pkg/pods/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1677edc

Please sign in to comment.