Skip to content

chore: bump golangci lint to v2 #8203

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

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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
GO111MODULE: auto

- name: golangci-lint - vertical-pod-autoscaler
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
args: --timeout=30m
working-directory: ${{ env.GOPATH }}/src/k8s.io/autoscaler/vertical-pod-autoscaler
Expand Down
32 changes: 22 additions & 10 deletions vertical-pod-autoscaler/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
version: "2"
linters:
enable:
- forbidigo
settings:
forbidigo:
forbid:
# Forbid use of archived package "github.com/pkg/errors". Context: https://github.com/kubernetes/autoscaler/pull/7845
- pkg: github.com/pkg/errors
analyze-types: true
formatters:
enable:
- goimports

linters-settings:
forbidigo:
forbid:
# Forbid use of archived package "github.com/pkg/errors". Context: https://github.com/kubernetes/autoscaler/pull/7845
- pkg: github.com/pkg/errors
analyze-types: true

goimports:
local-prefixes: "k8s.io/autoscaler/vertical-pod-autoscaler"
- gci
settings:
goimports:
local-prefixes:
- k8s.io/autoscaler/vertical-pod-autoscaler
gci:
sections:
- standard
- default
- prefix(k8s.io/autoscaler/vertical-pod-autoscaler)
- dot
- blank
custom-order: true
5 changes: 2 additions & 3 deletions vertical-pod-autoscaler/pkg/admission-controller/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ import (
"os"
"sync"

"github.com/fsnotify/fsnotify"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/fsnotify/fsnotify"
admissionregistrationv1 "k8s.io/client-go/kubernetes/typed/admissionregistration/v1"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -73,7 +72,7 @@ func (cr *certReloader) start(stop <-chan struct{}) error {
}

go func() {
defer watcher.Close()
defer watcher.Close() // nolint:errcheck
for {
select {
case event := <-watcher.Events:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake"
k8stesting "k8s.io/client-go/testing"
Expand Down Expand Up @@ -260,10 +259,8 @@ func TestChangedCAReloader(t *testing.T) {
}

oldCAEncodedString := base64.StdEncoding.EncodeToString(oldWebhookCABundle)
for {
if patchCalled.Load() {
break
}
for !patchCalled.Load() {

time.Sleep(1 * time.Second)
}
newWebhookConfig, err := webhookConfigInterface.Get(context.TODO(), webhookConfigName, metav1.GetOptions{})
Expand Down
2 changes: 1 addition & 1 deletion vertical-pod-autoscaler/pkg/admission-controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func configTLS(cfg certsConfig, minTlsVersion, ciphers string, stop <-chan struc
case "tls1_3":
tlsVersion = tls.VersionTLS13
default:
klog.Fatal(fmt.Errorf("Unable to determine value for --min-tls-version (%s), must be either tls1_2 or tls1_3", minTlsVersion))
klog.Fatal(fmt.Errorf("unable to determine value for --min-tls-version (%s), must be either tls1_2 or tls1_3", minTlsVersion))
}

config := &tls.Config{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
core "k8s.io/api/core/v1"

resource_admission "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource"
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/annotations"
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"

"github.com/stretchr/testify/assert"
)

func addVpaObservedContainersPatch(containerNames []string) resource_admission.PatchRecord {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *resourcesUpdatesPatchCalculator) CalculatePatches(pod *core.Pod, vpa *v

containersResources, annotationsPerContainer, err := c.recommendationProvider.GetContainersResourcesForPod(pod, vpa)
if err != nil {
return []resource_admission.PatchRecord{}, fmt.Errorf("Failed to calculate resource patch for pod %s/%s: %v", pod.Namespace, pod.Name, err)
return []resource_admission.PatchRecord{}, fmt.Errorf("failed to calculate resource patch for pod %s/%s: %v", pod.Namespace, pod.Name, err)
}

if annotationsPerContainer == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

resource_admission "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource"
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"
vpa_api_util "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/vpa"

"github.com/stretchr/testify/assert"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"fmt"
"testing"

resource_admission "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource"

"github.com/stretchr/testify/assert"

resource_admission "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource"
)

// EqPatch returns true if patches are equal by comparing their
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import (
"math"
"testing"

"github.com/stretchr/testify/assert"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/limitrange"
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"
vpa_api_util "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/vpa"

"github.com/stretchr/testify/assert"
)

func mustParseResourcePointer(val string) *resource.Quantity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
v1 "k8s.io/api/admission/v1"
corev1 "k8s.io/api/core/v1"
apires "k8s.io/apimachinery/pkg/api/resource"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"

Expand Down Expand Up @@ -118,7 +117,7 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error {
if vpa.Spec.UpdatePolicy != nil {
mode := vpa.Spec.UpdatePolicy.UpdateMode
if mode == nil {
return fmt.Errorf("UpdateMode is required if UpdatePolicy is used")
return fmt.Errorf("updateMode is required if UpdatePolicy is used")
}
if _, found := possibleUpdateModes[*mode]; !found {
return fmt.Errorf("unexpected UpdateMode value %s", *mode)
Expand All @@ -128,14 +127,14 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error {
}

if minReplicas := vpa.Spec.UpdatePolicy.MinReplicas; minReplicas != nil && *minReplicas <= 0 {
return fmt.Errorf("MinReplicas has to be positive, got %v", *minReplicas)
return fmt.Errorf("minReplicas has to be positive, got %v", *minReplicas)
}
}

if vpa.Spec.ResourcePolicy != nil {
for _, policy := range vpa.Spec.ResourcePolicy.ContainerPolicies {
if policy.ContainerName == "" {
return fmt.Errorf("ContainerPolicies.ContainerName is required")
return fmt.Errorf("containerPolicies.ContainerName is required")
}
mode := policy.Mode
if mode != nil {
Expand All @@ -145,7 +144,7 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error {
}
for resource, min := range policy.MinAllowed {
if err := validateResourceResolution(resource, min); err != nil {
return fmt.Errorf("MinAllowed: %v", err)
return fmt.Errorf("minAllowed: %v", err)
}
max, found := policy.MaxAllowed[resource]
if found && max.Cmp(min) < 0 {
Expand All @@ -155,24 +154,24 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error {

for resource, max := range policy.MaxAllowed {
if err := validateResourceResolution(resource, max); err != nil {
return fmt.Errorf("MaxAllowed: %v", err)
return fmt.Errorf("maxAllowed: %v", err)
}
}
ControlledValues := policy.ControlledValues
if mode != nil && ControlledValues != nil {
if *mode == vpa_types.ContainerScalingModeOff && *ControlledValues == vpa_types.ContainerControlledValuesRequestsAndLimits {
return fmt.Errorf("ControlledValues shouldn't be specified if container scaling mode is off.")
return fmt.Errorf("controlledValues shouldn't be specified if container scaling mode is off")
}
}
}
}

if isCreate && vpa.Spec.TargetRef == nil {
return fmt.Errorf("TargetRef is required. If you're using v1beta1 version of the API, please migrate to v1")
return fmt.Errorf("targetRef is required. If you're using v1beta1 version of the API, please migrate to v1")
}

if len(vpa.Spec.Recommenders) > 1 {
return fmt.Errorf("The current version of VPA object shouldn't specify more than one recommenders.")
return fmt.Errorf("the current version of VPA object shouldn't specify more than one recommenders")
}

return nil
Expand All @@ -197,7 +196,7 @@ func validateCPUResolution(val apires.Quantity) error {

func validateMemoryResolution(val apires.Quantity) error {
if _, precissionPreserved := val.AsScale(0); !precissionPreserved {
return fmt.Errorf("Memory [%v] must be a whole number of bytes", val)
return fmt.Errorf("memory [%v] must be a whole number of bytes", val)
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/assert"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

featuregatetesting "k8s.io/component-base/featuregate/testing"

vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestValidateVPA(t *testing.T) {
name: "empty create",
vpa: vpa_types.VerticalPodAutoscaler{},
isCreate: true,
expectError: fmt.Errorf("TargetRef is required. If you're using v1beta1 version of the API, please migrate to v1"),
expectError: fmt.Errorf("targetRef is required. If you're using v1beta1 version of the API, please migrate to v1"),
},
{
name: "no update mode",
Expand All @@ -70,7 +69,7 @@ func TestValidateVPA(t *testing.T) {
UpdatePolicy: &vpa_types.PodUpdatePolicy{},
},
},
expectError: fmt.Errorf("UpdateMode is required if UpdatePolicy is used"),
expectError: fmt.Errorf("updateMode is required if UpdatePolicy is used"),
},
{
name: "bad update mode",
Expand Down Expand Up @@ -129,7 +128,7 @@ func TestValidateVPA(t *testing.T) {
},
},
},
expectError: fmt.Errorf("MinReplicas has to be positive, got 0"),
expectError: fmt.Errorf("minReplicas has to be positive, got 0"),
},
{
name: "no policy name",
Expand All @@ -140,7 +139,7 @@ func TestValidateVPA(t *testing.T) {
},
},
},
expectError: fmt.Errorf("ContainerPolicies.ContainerName is required"),
expectError: fmt.Errorf("containerPolicies.ContainerName is required"),
},
{
name: "invalid scaling mode",
Expand Down Expand Up @@ -171,7 +170,7 @@ func TestValidateVPA(t *testing.T) {
},
},
},
expectError: fmt.Errorf("The current version of VPA object shouldn't specify more than one recommenders."),
expectError: fmt.Errorf("the current version of VPA object shouldn't specify more than one recommenders"),
},
{
name: "bad limits",
Expand Down Expand Up @@ -213,7 +212,7 @@ func TestValidateVPA(t *testing.T) {
},
},
},
expectError: fmt.Errorf("MinAllowed: CPU [%v] must be a whole number of milli CPUs", badCPUResource.String()),
expectError: fmt.Errorf("minAllowed: CPU [%v] must be a whole number of milli CPUs", badCPUResource.String()),
},
{
name: "bad minAllowed memory value",
Expand All @@ -236,7 +235,7 @@ func TestValidateVPA(t *testing.T) {
},
},
},
expectError: fmt.Errorf("MinAllowed: Memory [%v] must be a whole number of bytes", resource.MustParse("100m")),
expectError: fmt.Errorf("minAllowed: memory [%v] must be a whole number of bytes", resource.MustParse("100m")),
},
{
name: "bad maxAllowed cpu value",
Expand All @@ -255,7 +254,7 @@ func TestValidateVPA(t *testing.T) {
},
},
},
expectError: fmt.Errorf("MaxAllowed: CPU [%s] must be a whole number of milli CPUs", badCPUResource.String()),
expectError: fmt.Errorf("maxAllowed: CPU [%s] must be a whole number of milli CPUs", badCPUResource.String()),
},
{
name: "bad maxAllowed memory value",
Expand All @@ -276,7 +275,7 @@ func TestValidateVPA(t *testing.T) {
},
},
},
expectError: fmt.Errorf("MaxAllowed: Memory [%v] must be a whole number of bytes", resource.MustParse("500m")),
expectError: fmt.Errorf("maxAllowed: memory [%v] must be a whole number of bytes", resource.MustParse("500m")),
},
{
name: "scaling off with controlled values requests and limits",
Expand All @@ -293,7 +292,7 @@ func TestValidateVPA(t *testing.T) {
},
},
},
expectError: fmt.Errorf("ControlledValues shouldn't be specified if container scaling mode is off."),
expectError: fmt.Errorf("controlledValues shouldn't be specified if container scaling mode is off"),
},
{
name: "all valid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"context"
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/autoscaling/v1"
core "k8s.io/api/core/v1"
Expand All @@ -30,9 +32,6 @@ import (
controllerfetcher "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target/controller_fetcher"
target_mock "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/target/mock"
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)

func parseLabelSelector(selector string) labels.Selector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func TestStoreCheckpointsMakesProgressEvenForCancelledContext(t *testing.T) {

patchedCheckpoints := []string{}
checkpointClient := &fakeautoscalingv1.FakeAutoscalingV1{Fake: &core.Fake{}}
checkpointClient.Fake.AddReactor("patch", "verticalpodautoscalercheckpoints", func(action core.Action) (handled bool, ret runtime.Object, err error) {
checkpointClient.AddReactor("patch", "verticalpodautoscalercheckpoints", func(action core.Action) (handled bool, ret runtime.Object, err error) {
patchAction := action.(core.PatchAction)
name := patchAction.GetName()
time.Sleep(2 * time.Millisecond) // Simulate some delay in patching, such that we can test the timeout
Expand Down
Loading
Loading