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

🐛 Add for new linters to fix old syntax #10699

Merged
merged 10 commits into from
Jun 4, 2024
Merged
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/pr-golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # tag=v6.0.1
with:
version: v1.57.2
version: v1.59.0
args: --out-format=colored-line-number
working-directory: ${{matrix.working-directory}}
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ linters:
- bidichk
- bodyclose
- containedctx
- copyloopvar
- dogsled
- dupword
- durationcheck
- errcheck
- errchkjson
- exportloopref
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't want this linter anymore, because Go Team has resolved this issue by this

- gci
- ginkgolinter
- goconst
Expand All @@ -38,6 +38,7 @@ linters:
- govet
- importas
- ineffassign
- intrange
- loggercheck
- misspell
- nakedret
Expand Down
1 change: 0 additions & 1 deletion bootstrap/kubeadm/internal/cloudinit/controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func TestTemplateYAMLIndent(t *testing.T) {
}

for _, tc := range testcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestKubeadmConfigReconciler_MachineToBootstrapMapFuncReturn(t *testing.T) {
objs := []client.Object{cluster}
machineObjs := []client.Object{}
var expectedConfigName string
for i := 0; i < 3; i++ {
for i := range 3 {
configName := fmt.Sprintf("my-config-%d", i)
m := builder.Machine(metav1.NamespaceDefault, fmt.Sprintf("my-machine-%d", i)).
WithVersion("v1.19.1").
Expand All @@ -80,7 +80,7 @@ func TestKubeadmConfigReconciler_MachineToBootstrapMapFuncReturn(t *testing.T) {
Client: fakeClient,
SecretCachingClient: fakeClient,
}
for i := 0; i < 3; i++ {
for i := range 3 {
o := machineObjs[i]
configs := reconciler.MachineToBootstrapMapFunc(ctx, o)
if i == 1 {
Expand Down Expand Up @@ -675,7 +675,6 @@ func TestReconcileIfJoinCertificatesAvailableConditioninNodesAndControlPlaneIsRe
}

for _, rt := range useCases {
rt := rt // pin!
t.Run(rt.name, func(t *testing.T) {
g := NewWithT(t)

Expand Down Expand Up @@ -753,7 +752,6 @@ func TestReconcileIfJoinNodePoolsAndControlPlaneIsReady(t *testing.T) {
}

for _, rt := range useCases {
rt := rt // pin!
t.Run(rt.name, func(t *testing.T) {
g := NewWithT(t)

Expand Down Expand Up @@ -1819,7 +1817,7 @@ func TestKubeadmConfigReconciler_ClusterToKubeadmConfigs(t *testing.T) {
cluster := builder.Cluster(metav1.NamespaceDefault, "my-cluster").Build()
objs := []client.Object{cluster}
expectedNames := []string{}
for i := 0; i < 3; i++ {
for i := range 3 {
configName := fmt.Sprintf("my-config-%d", i)
m := builder.Machine(metav1.NamespaceDefault, fmt.Sprintf("my-machine-%d", i)).
WithVersion("v1.19.1").
Expand Down
2 changes: 0 additions & 2 deletions bootstrap/kubeadm/internal/ignition/clc/clc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,6 @@ func TestRender(t *testing.T) {
}

for _, tt := range tc {
tt := tt

t.Run(tt.desc, func(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 0 additions & 6 deletions bootstrap/kubeadm/internal/ignition/ignition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ func Test_NewNode(t *testing.T) {
}

for name, input := range cases {
input := input

t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -160,8 +158,6 @@ func Test_NewJoinControlPlane(t *testing.T) {
}

for name, input := range cases {
input := input

t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -278,8 +274,6 @@ func Test_NewInitControlPlane(t *testing.T) {
}

for name, input := range cases {
input := input

t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func TestControlPlaneInitMutex_Lock(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
gs := NewWithT(t)

Expand Down Expand Up @@ -259,7 +258,6 @@ func TestControlPlaneInitMutex_UnLock(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
gs := NewWithT(t)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ func TestKubeadmConfigTemplateValidation(t *testing.T) {
}

for name, tt := range cases {
tt := tt

webhook := &KubeadmConfigTemplate{}

t.Run(name, func(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion cmd/clusterctl/client/cluster/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ func (p *providerComponents) ValidateNoObjectsExist(ctx context.Context, provide
// Filter the resources according to the delete options
crsHavingObjects := []string{}
for _, crd := range customResources.Items {
crd := crd
storageVersion, err := storageVersionForCRD(&crd)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/clusterctl/client/cluster/mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (o *objectMover) move(ctx context.Context, graph *objectGraph, toProxy Prox

// Create all objects group by group, ensuring all the ownerReferences are re-created.
log.Info("Creating objects in the target cluster")
for groupIndex := 0; groupIndex < len(moveSequence.groups); groupIndex++ {
for groupIndex := range len(moveSequence.groups) {
if err := o.createGroup(ctx, moveSequence.getGroup(groupIndex), toProxy, mutators...); err != nil {
return err
}
Expand Down Expand Up @@ -419,7 +419,7 @@ func (o *objectMover) toDirectory(ctx context.Context, graph *objectGraph, direc

// Save all objects group by group
log.Info(fmt.Sprintf("Saving files to %s", directory))
for groupIndex := 0; groupIndex < len(moveSequence.groups); groupIndex++ {
for groupIndex := range len(moveSequence.groups) {
if err := o.backupGroup(ctx, moveSequence.getGroup(groupIndex), directory); err != nil {
return err
}
Expand Down Expand Up @@ -459,7 +459,7 @@ func (o *objectMover) fromDirectory(ctx context.Context, graph *objectGraph, toP

// Create all objects group by group, ensuring all the ownerReferences are re-created.
log.Info("Restoring objects into the target cluster")
for groupIndex := 0; groupIndex < len(moveSequence.groups); groupIndex++ {
for groupIndex := range len(moveSequence.groups) {
if err := o.restoreGroup(ctx, moveSequence.getGroup(groupIndex), toProxy); err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion cmd/clusterctl/client/cluster/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ func (u *providerUpgrader) scaleDownProvider(ctx context.Context, provider clust

// Scale down provider Deployments.
for _, deployment := range deploymentList.Items {
deployment := deployment
log.V(5).Info("Scaling down", "Deployment", klog.KObj(&deployment))
if err := scaleDownDeployment(ctx, cs, deployment); err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion cmd/clusterctl/client/repository/repository_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ func (g *gitHubRepository) getVersions(ctx context.Context) ([]string, error) {
}
versions := []string{}
for _, r := range allReleases {
r := r // pin
if r.TagName == nil {
continue
}
Expand Down
1 change: 0 additions & 1 deletion cmd/clusterctl/client/tree/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func GetOtherConditions(obj client.Object) []*clusterv1.Condition {
}
var conditions []*clusterv1.Condition
for _, c := range getter.GetConditions() {
c := c
if c.Type != clusterv1.ReadyCondition {
conditions = append(conditions, &c)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/cmd/version_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func writeStateFile(path string, vs *VersionState) error {
if err != nil {
return err
}
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
return err
}
return os.WriteFile(path, vsb, 0600)
Expand Down
2 changes: 1 addition & 1 deletion controllers/remote/keyedmutex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestKeyedMutex(t *testing.T) {

// Run this twice to ensure Clusters can be locked again
// after they have been unlocked.
for i := 0; i < 2; i++ {
for range 2 {
// Lock all Clusters (should work).
for _, key := range clusters {
g.Expect(km.TryLock(key)).To(BeTrue())
Expand Down
12 changes: 6 additions & 6 deletions controlplane/kubeadm/internal/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
Workload: fakeWorkloadCluster{},
}
objs := []client.Object{builder.GenericInfrastructureMachineTemplateCRD, cluster.DeepCopy(), kcp.DeepCopy(), tmpl.DeepCopy()}
for i := 0; i < 3; i++ {
for i := range 3 {
name := fmt.Sprintf("test-%d", i)
m := &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -564,7 +564,7 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
Workload: fakeWorkloadCluster{},
}
objs := []client.Object{builder.GenericInfrastructureMachineTemplateCRD, cluster.DeepCopy(), kcp.DeepCopy(), tmpl.DeepCopy()}
for i := 0; i < 3; i++ {
for i := range 3 {
name := fmt.Sprintf("test-%d", i)
m := &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -679,7 +679,7 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
Workload: fakeWorkloadCluster{},
}
objs := []client.Object{builder.GenericInfrastructureMachineTemplateCRD, cluster.DeepCopy(), kcp.DeepCopy(), tmpl.DeepCopy()}
for i := 0; i < 3; i++ {
for i := range 3 {
name := fmt.Sprintf("test-%d", i)
m := &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -2090,7 +2090,7 @@ func TestKubeadmControlPlaneReconciler_reconcileDelete(t *testing.T) {
initObjs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy()}

machines := collections.New()
for i := 0; i < 3; i++ {
for i := range 3 {
m, _ := createMachineNodePair(fmt.Sprintf("test-%d", i), cluster, kcp, true)
initObjs = append(initObjs, m)
machines.Insert(m)
Expand Down Expand Up @@ -2154,7 +2154,7 @@ func TestKubeadmControlPlaneReconciler_reconcileDelete(t *testing.T) {
initObjs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy(), workerMachine.DeepCopy()}

machines := collections.New()
for i := 0; i < 3; i++ {
for i := range 3 {
m, _ := createMachineNodePair(fmt.Sprintf("test-%d", i), cluster, kcp, true)
initObjs = append(initObjs, m)
machines.Insert(m)
Expand Down Expand Up @@ -2212,7 +2212,7 @@ func TestKubeadmControlPlaneReconciler_reconcileDelete(t *testing.T) {
initObjs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy(), workerMachinePool.DeepCopy()}

machines := collections.New()
for i := 0; i < 3; i++ {
for i := range 3 {
m, _ := createMachineNodePair(fmt.Sprintf("test-%d", i), cluster, kcp, true)
initObjs = append(initObjs, m)
machines.Insert(m)
Expand Down
4 changes: 2 additions & 2 deletions controlplane/kubeadm/internal/controllers/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestKubeadmControlPlaneReconciler_scaleUpControlPlane(t *testing.T) {
Workload: fakeWorkloadCluster{},
}

for i := 0; i < 2; i++ {
for i := range 2 {
m, _ := createMachineNodePair(fmt.Sprintf("test-%d", i), cluster, kcp, true)
setMachineHealthy(m)
fmc.Machines.Insert(m)
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestKubeadmControlPlaneReconciler_scaleUpControlPlane(t *testing.T) {
cluster.Status.InfrastructureReady = true

beforeMachines := collections.New()
for i := 0; i < 2; i++ {
for i := range 2 {
m, _ := createMachineNodePair(fmt.Sprintf("test-%d", i), cluster.DeepCopy(), kcp.DeepCopy(), true)
beforeMachines.Insert(m)
}
Expand Down
8 changes: 4 additions & 4 deletions controlplane/kubeadm/internal/controllers/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestKubeadmControlPlaneReconciler_updateStatusAllMachinesNotReady(t *testin

machines := map[string]*clusterv1.Machine{}
objs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy()}
for i := 0; i < 3; i++ {
for i := range 3 {
name := fmt.Sprintf("test-%d", i)
m, n := createMachineNodePair(name, cluster, kcp, false)
objs = append(objs, n, m)
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestKubeadmControlPlaneReconciler_updateStatusAllMachinesReady(t *testing.T

objs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy(), kubeadmConfigMap()}
machines := map[string]*clusterv1.Machine{}
for i := 0; i < 3; i++ {
for i := range 3 {
name := fmt.Sprintf("test-%d", i)
m, n := createMachineNodePair(name, cluster, kcp, true)
objs = append(objs, n, m)
Expand Down Expand Up @@ -287,7 +287,7 @@ func TestKubeadmControlPlaneReconciler_updateStatusMachinesReadyMixed(t *testing
g.Expect(err).ToNot(HaveOccurred())
machines := map[string]*clusterv1.Machine{}
objs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy()}
for i := 0; i < 4; i++ {
for i := range 4 {
name := fmt.Sprintf("test-%d", i)
m, n := createMachineNodePair(name, cluster, kcp, false)
machines[m.Name] = m
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestKubeadmControlPlaneReconciler_machinesCreatedIsIsTrueEvenWhenTheNodesAr
machines := map[string]*clusterv1.Machine{}
objs := []client.Object{cluster.DeepCopy(), kcp.DeepCopy()}
// Create the desired number of machines
for i := 0; i < 3; i++ {
for i := range 3 {
name := fmt.Sprintf("test-%d", i)
m, n := createMachineNodePair(name, cluster, kcp, false)
machines[m.Name] = m
Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/internal/controllers/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleDown(t *testing.T) {
},
}
objs := []client.Object{builder.GenericInfrastructureMachineTemplateCRD, cluster.DeepCopy(), kcp.DeepCopy(), tmpl.DeepCopy()}
for i := 0; i < 3; i++ {
for i := range 3 {
name := fmt.Sprintf("test-%d", i)
m := &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Expand Down
2 changes: 1 addition & 1 deletion exp/internal/controllers/machinepool_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (r *MachinePoolReconciler) waitForMachineCreation(ctx context.Context, mach
// The polling is against a local memory cache.
const waitForCacheUpdateInterval = 100 * time.Millisecond

for i := 0; i < len(machineList); i++ {
for i := range len(machineList) {
machine := machineList[i]
pollErr := wait.PollUntilContextTimeout(ctx, waitForCacheUpdateInterval, waitForCacheUpdateTimeout, true, func(ctx context.Context) (bool, error) {
key := client.ObjectKey{Namespace: machine.Namespace, Name: machine.Name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) {

func getInfraMachines(replicas int, mpName, clusterName, nsName string) []unstructured.Unstructured {
infraMachines := make([]unstructured.Unstructured, replicas)
for i := 0; i < replicas; i++ {
for i := range replicas {
infraMachines[i] = unstructured.Unstructured{
Object: map[string]interface{}{
"kind": builder.GenericInfrastructureMachineKind,
Expand All @@ -1923,7 +1923,7 @@ func getInfraMachines(replicas int, mpName, clusterName, nsName string) []unstru

func getMachines(replicas int, mpName, clusterName, nsName string) []clusterv1.Machine {
machines := make([]clusterv1.Machine, replicas)
for i := 0; i < replicas; i++ {
for i := range replicas {
machines[i] = clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-machine-%d", mpName, i),
Expand Down
2 changes: 0 additions & 2 deletions exp/topology/desiredstate/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ func (g *generator) computeMachineDeployment(ctx context.Context, s *scope.Scope

var machineDeploymentClass *clusterv1.MachineDeploymentClass
for _, mdClass := range s.Blueprint.ClusterClass.Spec.Workers.MachineDeployments {
mdClass := mdClass
if mdClass.Class == className {
machineDeploymentClass = &mdClass
break
Expand Down Expand Up @@ -958,7 +957,6 @@ func (g *generator) computeMachinePool(_ context.Context, s *scope.Scope, machin

var machinePoolClass *clusterv1.MachinePoolClass
for _, mpClass := range s.Blueprint.ClusterClass.Spec.Workers.MachinePools {
mpClass := mpClass
if mpClass.Class == className {
machinePoolClass = &mpClass
break
Expand Down
1 change: 0 additions & 1 deletion exp/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ func TestGetMachinePoolByLabels(t *testing.T) {
}

for _, tc := range testcases {
tc := tc
t.Run(tc.name, func(*testing.T) {
clientFake := fake.NewClientBuilder().
WithScheme(fakeScheme).
Expand Down
2 changes: 1 addition & 1 deletion hack/tools/prowjob-gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func mustHas(needle interface{}, haystack interface{}) (bool, error) {
l2 := reflect.ValueOf(haystack)
var item interface{}
l := l2.Len()
for i := 0; i < l; i++ {
for i := range l {
item = l2.Index(i).Interface()
if reflect.DeepEqual(needle, item) {
return true, nil
Expand Down
Loading
Loading