Skip to content

Commit

Permalink
bump golangci-lint to 1.60.1 and support go 1.23
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinForReal committed Aug 15, 2024
1 parent d3f83c6 commit 9eb8173
Show file tree
Hide file tree
Showing 39 changed files with 166 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ jobs:
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.55
version: v1.60
args: -v
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ delete-workload-cluster:
##@ Tools

LINTER = $(shell pwd)/bin/golangci-lint
LINTER_VERSION = v1.55.2
LINTER_VERSION = v1.60.1
.PHONY: golangci-lint
golangci-lint: ## Download golangci-lint locally if necessary.
@echo "Installing golangci-lint"
Expand Down
2 changes: 1 addition & 1 deletion cmd/acr-credential-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
Short: "Acr credential provider for Kubelet",
Long: `The acr credential provider is responsible for providing ACR credentials for kubelet`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 1 {
klog.Errorf("Config file is not specified")
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions cmd/cloud-controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewCloudControllerManagerCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "cloud-controller-manager",
Long: `The Cloud controller manager is a daemon that embeds the cloud specific control loops shipped with Kubernetes.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
verflag.PrintAndExitIfRequested("Cloud Provider Azure")
cliflag.PrintFlags(cmd.Flags())

Expand Down Expand Up @@ -164,7 +164,7 @@ func NewCloudControllerManagerCommand() *cobra.Command {
cliflag.PrintSections(cmd.OutOrStderr(), namedFlagSets, cols)
return nil
})
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
cmd.SetHelpFunc(func(cmd *cobra.Command, _ []string) {
fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n"+usageFmt, cmd.Long, cmd.UseLine())
cliflag.PrintSections(cmd.OutOrStdout(), namedFlagSets, cols)
})
Expand All @@ -174,7 +174,7 @@ func NewCloudControllerManagerCommand() *cobra.Command {

// RunWrapper adapts the ccm boot logic to the leader elector call back function
func RunWrapper(s *options.CloudControllerManagerOptions, c *cloudcontrollerconfig.Config, h *controllerhealthz.MutableHealthzHandler) func(ctx context.Context) {
return func(ctx context.Context) {
return func(_ context.Context) {
if !c.DynamicReloadingConfig.EnableDynamicReloading {
klog.V(1).Infof("using static initialization from config file %s", c.ComponentConfig.KubeCloudShared.CloudProvider.CloudConfigFile)
if err := Run(context.TODO(), c.Complete(), h); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloud-controller-manager/app/dynamic/secret_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewSecretWatcher(informerFactory informers.SharedInformerFactory, secretNam
_, _ = secretInformer.Informer().AddEventHandler(
// Your custom resource event handlers.
cache.ResourceEventHandlerFuncs{
UpdateFunc: func(oldObj, newObj interface{}) {
UpdateFunc: func(_, newObj interface{}) {
newSecret := newObj.(*v1.Secret)

if strings.EqualFold(newSecret.Name, secretName) &&
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloud-controller-manager/app/testing/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func StartTestServer(t Logger, customFlags []string) (result TestServer, err err
}

errCh := make(chan error)
go func(stopCh <-chan struct{}) {
go func(_ <-chan struct{}) {
if err := app.Run(context.TODO(), config.Complete(), nil); err != nil {
errCh <- err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/cloud-node-manager/app/nodemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewCloudNodeManagerCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "cloud-node-manager",
Long: `The Cloud node manager is a daemon that reconciles node information for its running node.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
verflag.PrintAndExitIfRequested("Cloud Node Manager")
cliflag.PrintFlags(cmd.Flags())

Expand Down Expand Up @@ -89,7 +89,7 @@ func NewCloudNodeManagerCommand() *cobra.Command {
cliflag.PrintSections(cmd.OutOrStderr(), namedFlagSets, cols)
return nil
})
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
cmd.SetHelpFunc(func(cmd *cobra.Command, _ []string) {
fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n"+usageFmt, cmd.Long, cmd.UseLine())
cliflag.PrintSections(cmd.OutOrStdout(), namedFlagSets, cols)
})
Expand Down
46 changes: 23 additions & 23 deletions pkg/azureclients/armclient/azure_armclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (

func TestSend(t *testing.T) {
count := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
if count <= 1 {
http.Error(w, "failed", http.StatusInternalServerError)
count++
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestDoHackRegionalRetryForGET(t *testing.T) {
assert.NoError(t, err)
}))

globalServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
globalServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
if tc.globalServerContentLength != nil {
w.Header().Set("Content-Length", *tc.globalServerContentLength)
}
Expand All @@ -136,7 +136,7 @@ func TestDoHackRegionalRetryForGET(t *testing.T) {

func TestSendFailure(t *testing.T) {
count := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
http.Error(w, "failed", http.StatusInternalServerError)
count++
}))
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestSendFailure(t *testing.T) {

func TestSendThrottled(t *testing.T) {
count := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set(consts.RetryAfterHeaderKey, "30")
http.Error(w, "failed", http.StatusTooManyRequests)
count++
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestSendThrottled(t *testing.T) {

func TestSendAsync(t *testing.T) {
count := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
count++
http.Error(w, "failed", http.StatusForbidden)
}))
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestSendAsync(t *testing.T) {
}

func TestSendAsyncSuccess(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
}))

Expand Down Expand Up @@ -307,7 +307,7 @@ func TestGetResource(t *testing.T) {
"param1": "value1",
"param2": "value2",
},
getResource: func(ctx context.Context, armClient *Client, apiVersion string, params map[string]interface{}) (*http.Response, *retry.Error) {
getResource: func(ctx context.Context, armClient *Client, _ string, params map[string]interface{}) (*http.Response, *retry.Error) {
decorators := []autorest.PrepareDecorator{
autorest.WithQueryParameters(params),
}
Expand All @@ -319,7 +319,7 @@ func TestGetResource(t *testing.T) {
expectedURIResource: "/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP?%24expand=data&api-version=2019-01-01",
apiVersion: "2019-01-01",
expectedAPIVersion: "2019-01-01",
getResource: func(ctx context.Context, armClient *Client, apiVersion string, params map[string]interface{}) (*http.Response, *retry.Error) {
getResource: func(ctx context.Context, armClient *Client, _ string, _ map[string]interface{}) (*http.Response, *retry.Error) {
return armClient.GetResourceWithExpandQuery(ctx, testResourceID, "data")
},
},
Expand All @@ -328,7 +328,7 @@ func TestGetResource(t *testing.T) {
expectedURIResource: "/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP?%24expand=data&api-version=2019-01-01",
apiVersion: "2018-01-01",
expectedAPIVersion: "2019-01-01",
getResource: func(ctx context.Context, armClient *Client, apiVersion string, params map[string]interface{}) (*http.Response, *retry.Error) {
getResource: func(ctx context.Context, armClient *Client, apiVersion string, _ map[string]interface{}) (*http.Response, *retry.Error) {
return armClient.GetResourceWithExpandAPIVersionQuery(ctx, testResourceID, "data", apiVersion)
},
},
Expand All @@ -337,7 +337,7 @@ func TestGetResource(t *testing.T) {
expectedURIResource: "/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP?api-version=2019-01-01",
apiVersion: "2018-01-01",
expectedAPIVersion: "2019-01-01",
getResource: func(ctx context.Context, armClient *Client, apiVersion string, params map[string]interface{}) (*http.Response, *retry.Error) {
getResource: func(ctx context.Context, armClient *Client, apiVersion string, _ map[string]interface{}) (*http.Response, *retry.Error) {
return armClient.GetResourceWithExpandAPIVersionQuery(ctx, testResourceID, "", apiVersion)
},
},
Expand All @@ -350,7 +350,7 @@ func TestGetResource(t *testing.T) {
"param1": "value1",
"param2": "value2",
},
getResource: func(ctx context.Context, armClient *Client, apiVersion string, params map[string]interface{}) (*http.Response, *retry.Error) {
getResource: func(ctx context.Context, armClient *Client, _ string, params map[string]interface{}) (*http.Response, *retry.Error) {
return armClient.GetResourceWithQueries(ctx, testResourceID, params)
},
},
Expand Down Expand Up @@ -537,11 +537,11 @@ func TestResourceAction(t *testing.T) {
}{
{
description: "put resource async",
action: func(armClient *Client, ctx context.Context, resourceID string, parameters interface{}) (*azure.Future, *http.Response, *retry.Error) {
action: func(armClient *Client, ctx context.Context, resourceID string, _ interface{}) (*azure.Future, *http.Response, *retry.Error) {
future, rerr := armClient.PutResourceAsync(ctx, resourceID, "")
return future, nil, rerr
},
assertion: func(count int, future *azure.Future, response *http.Response, rerr *retry.Error) {
assertion: func(count int, future *azure.Future, _ *http.Response, rerr *retry.Error) {
assert.Equal(t, 3, count, "count")
assert.Nil(t, future, "future")
assert.NotNil(t, rerr, "rerr")
Expand All @@ -550,11 +550,11 @@ func TestResourceAction(t *testing.T) {
},
{
description: "delete resource async",
action: func(armClient *Client, ctx context.Context, resourceID string, parameters interface{}) (*azure.Future, *http.Response, *retry.Error) {
action: func(armClient *Client, ctx context.Context, resourceID string, _ interface{}) (*azure.Future, *http.Response, *retry.Error) {
future, rerr := armClient.DeleteResourceAsync(ctx, resourceID)
return future, nil, rerr
},
assertion: func(count int, future *azure.Future, response *http.Response, rerr *retry.Error) {
assertion: func(count int, future *azure.Future, _ *http.Response, rerr *retry.Error) {
assert.Equal(t, 3, count, "count")
assert.Nil(t, future, "future")
assert.NotNil(t, rerr, "rerr")
Expand All @@ -563,11 +563,11 @@ func TestResourceAction(t *testing.T) {
},
{
description: "post resource",
action: func(armClient *Client, ctx context.Context, resourceID string, parameters interface{}) (*azure.Future, *http.Response, *retry.Error) {
action: func(armClient *Client, ctx context.Context, resourceID string, _ interface{}) (*azure.Future, *http.Response, *retry.Error) {
response, rerr := armClient.PostResource(ctx, resourceID, "post", "", map[string]interface{}{})
return nil, response, rerr
},
assertion: func(count int, future *azure.Future, response *http.Response, rerr *retry.Error) {
assertion: func(count int, _ *azure.Future, response *http.Response, rerr *retry.Error) {
assert.Equal(t, 3, count, "count")
assert.NotNil(t, response, "response")
assert.NotNil(t, rerr, "rerr")
Expand All @@ -576,33 +576,33 @@ func TestResourceAction(t *testing.T) {
},
{
description: "delete resource",
action: func(armClient *Client, ctx context.Context, resourceID string, parameters interface{}) (*azure.Future, *http.Response, *retry.Error) {
action: func(armClient *Client, ctx context.Context, resourceID string, _ interface{}) (*azure.Future, *http.Response, *retry.Error) {
rerr := armClient.DeleteResource(ctx, resourceID)
return nil, nil, rerr
},
assertion: func(count int, future *azure.Future, response *http.Response, rerr *retry.Error) {
assertion: func(count int, _ *azure.Future, _ *http.Response, rerr *retry.Error) {
assert.Equal(t, 3, count, "count")
assert.NotNil(t, rerr, "rerr")
assert.Equal(t, true, rerr.Retriable, "rerr.Retriable")
},
},
{
description: "head resource",
action: func(armClient *Client, ctx context.Context, resourceID string, parameters interface{}) (*azure.Future, *http.Response, *retry.Error) {
action: func(armClient *Client, ctx context.Context, resourceID string, _ interface{}) (*azure.Future, *http.Response, *retry.Error) {
response, rerr := armClient.HeadResource(ctx, resourceID)
return nil, response, rerr
},
assertion: func(count int, future *azure.Future, response *http.Response, rerr *retry.Error) {
assertion: func(count int, _ *azure.Future, response *http.Response, rerr *retry.Error) {
assert.Equal(t, 3, count, "count")
assert.NotNil(t, response, "response")
assert.NotNil(t, rerr, "rerr")
assert.Equal(t, true, rerr.Retriable, "rerr.Retriable")
},
},
} {
t.Run(tc.description, func(t *testing.T) {
t.Run(tc.description, func(_ *testing.T) {
count := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
count++
http.Error(w, "failed", http.StatusInternalServerError)
}))
Expand Down
5 changes: 3 additions & 2 deletions pkg/azureclients/armclient/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package armclient
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"html"
"io"
Expand Down Expand Up @@ -186,8 +187,8 @@ func DoHackRegionalRetryForGET(c *Client) autorest.SendDecorator {
emptyResp = (regionalResponse.ContentLength == 0 || trimmed == "" || trimmed == "{}") && regionalResponse.StatusCode >= 200 && regionalResponse.StatusCode < 300
if emptyResp {
contentLengthErrStr := fmt.Sprintf("empty response with trimmed body %q, ContentLength %d and StatusCode %d", trimmed, regionalResponse.ContentLength, regionalResponse.StatusCode)
klog.Errorf(contentLengthErrStr)
return response, fmt.Errorf(contentLengthErrStr)
klog.Error(contentLengthErrStr)
return response, errors.New(contentLengthErrStr)
}

return regionalResponse, regionalError
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/azure_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestCacheGet(t *testing.T) {

func TestCacheGetError(t *testing.T) {
getError := fmt.Errorf("getError")
getter := func(key string) (interface{}, error) {
getter := func(_ string) (interface{}, error) {
return nil, getError
}
cache, err := NewTimedCache(fakeCacheTTL, getter, false)
Expand Down
4 changes: 2 additions & 2 deletions pkg/consts/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func Test_extractInt32FromString(t *testing.T) {
nil,
}}, want: ptr.To(int32(-6)), wantErr: false},
{name: "validation failed", args: args{val: "-6", businessValidator: []Int32BusinessValidator{
func(i *int32) error {
func(_ *int32) error {
return fmt.Errorf("validator failed")
},
}}, wantErr: true},
Expand Down Expand Up @@ -226,7 +226,7 @@ func Test_getAttributeValueInSvcAnnotation(t *testing.T) {
{name: "annotation set is empty", args: args{key: "key"}, want: nil, wantErr: false},
{name: "key is not specified even though annotation set is not empty", args: args{annotations: map[string]string{"key": ""}}, want: nil, wantErr: false},
{name: "validation failed", args: args{annotations: map[string]string{"key": ""}, key: "key", validators: []BusinessValidator{
func(s *string) error {
func(_ *string) error {
return fmt.Errorf("validator failed")
},
}}, wantErr: true},
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func (az *Cloud) initCaches() (err error) {
return err
}

getter := func(key string) (interface{}, error) { return nil, nil }
getter := func(_ string) (interface{}, error) { return nil, nil }
if az.storageAccountCache, err = azcache.NewTimedCache(time.Minute, getter, az.Config.DisableAPICallCache); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azure_controller_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
maxLUN = 64 // max number of LUNs per VM
errStatusCode400 = "statuscode=400"
errInvalidParameter = `code="invalidparameter"`
errTargetInstanceIds = `target="instanceids"`
errTargetInstanceIDs = `target="instanceids"`
sourceSnapshot = "snapshot"
sourceVolume = "volume"
attachDiskMapKeySuffix = "attachdiskmap"
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azure_fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func GetTestCloud(ctrl *gomock.Controller) (az *Cloud) {
az.plsCache, _ = az.newPLSCache()
az.LoadBalancerBackendPool = NewMockBackendPool(ctrl)

getter := func(key string) (interface{}, error) { return nil, nil }
getter := func(_ string) (interface{}, error) { return nil, nil }
az.storageAccountCache, _ = azcache.NewTimedCache(time.Minute, getter, az.Config.DisableAPICallCache)
az.fileServicePropertiesCache, _ = azcache.NewTimedCache(5*time.Minute, getter, az.Config.DisableAPICallCache)

Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azure_instance_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestGetPlatformSubFaultDomain(t *testing.T) {
respString = "{}"
}
mux := http.NewServeMux()
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, respString)
}))
go func() {
Expand Down
12 changes: 6 additions & 6 deletions pkg/provider/azure_instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ func TestInstanceID(t *testing.T) {
}

mux := http.NewServeMux()
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
if test.metadataTemplate != "" {
fmt.Fprintf(w, test.metadataTemplate)
fmt.Fprint(w, test.metadataTemplate)
} else {
fmt.Fprintf(w, "{\"compute\":{\"name\":\"%s\",\"VMScaleSetName\":\"%s\",\"subscriptionId\":\"subscription\",\"resourceGroupName\":\"rg\", \"resourceId\":\"%s\"}}", test.metadataName, test.vmssName, test.resourceID)
}
Expand All @@ -247,7 +247,7 @@ func TestInstanceID(t *testing.T) {
t.Errorf("Test [%s] unexpected error: %v", test.name, err)
}
if test.useCustomImsCache {
cloud.Metadata.imsCache, err = azcache.NewTimedCache(consts.MetadataCacheTTL, func(key string) (interface{}, error) {
cloud.Metadata.imsCache, err = azcache.NewTimedCache(consts.MetadataCacheTTL, func(_ string) (interface{}, error) {
return nil, fmt.Errorf("getError")
}, false)
if err != nil {
Expand Down Expand Up @@ -622,7 +622,7 @@ func TestNodeAddresses(t *testing.T) {
}

if test.metadataTemplate != "" {
fmt.Fprintf(w, test.metadataTemplate)
fmt.Fprint(w, test.metadataTemplate)
} else {
if test.loadBalancerSku == "standard" {
fmt.Fprintf(w, metadataTemplate, test.metadataName, test.ipV4, "", test.ipV6, "")
Expand All @@ -642,7 +642,7 @@ func TestNodeAddresses(t *testing.T) {
}

if test.useCustomImsCache {
cloud.Metadata.imsCache, err = azcache.NewTimedCache(consts.MetadataCacheTTL, func(key string) (interface{}, error) {
cloud.Metadata.imsCache, err = azcache.NewTimedCache(consts.MetadataCacheTTL, func(_ string) (interface{}, error) {
return nil, fmt.Errorf("getError")
}, false)
if err != nil {
Expand Down Expand Up @@ -848,7 +848,7 @@ func TestNodeAddressesByProviderID(t *testing.T) {
}

mux := http.NewServeMux()
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintf(w, metadataTemplate, test.nodeName, test.ipV4, test.ipV4Public, test.ipV6, test.ipV6Public)
}))
go func() {
Expand Down
Loading

0 comments on commit 9eb8173

Please sign in to comment.