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

balancer: fixed lint issues and add linter to CI #7559

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
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())
}
}
2 changes: 1 addition & 1 deletion balancer/pkg/controller/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func setConditionsBasedOnError(balancer *v1alpha1.Balancer, err *BalancerError,
} else {
balancer.Status.Conditions = setConditionInList(balancer.Status.Conditions,
now, v1alpha1.BalancerConditionRunning, metav1.ConditionFalse,
string(err.phase), err.Error())
string(err.phase), "%s", err.Error())
}
}

Expand Down
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}
// }
Comment on lines +52 to +54
Copy link
Member Author

Choose a reason for hiding this comment

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

function is unused. should I remove it instead?


// 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
Loading