Skip to content

Commit

Permalink
Fix linter findings
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Feb 14, 2024
1 parent dbe0d67 commit dca1937
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 14 deletions.
9 changes: 8 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ linters-settings:
#
- name: bool-literal-in-expr
- name: constant-logical-expr

goconst:
ignore-tests: true
issues:
max-same-issues: 0
max-issues-per-linter: 0
Expand Down Expand Up @@ -323,3 +324,9 @@ issues:
- gocritic
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"
path: _test\.go
# Note: We only found issues with memory aliasing after backporting Go 1.21 and a new golangci-lint version.
# Let's not waste time fixing memory aliasing in unit tests on this branch.
- linters:
- gosec
text: "G601: Implicit memory aliasing in for loop"
path: _test\.go
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func (c *clusterctlClient) Move(options MoveOptions) error {
return c.toDirectory(options)
} else if options.FromDirectory != "" {
return c.fromDirectory(options)
} else {
return c.move(options)
}

return c.move(options)
}

func (c *clusterctlClient) move(options MoveOptions) error {
Expand Down
2 changes: 1 addition & 1 deletion exp/runtime/hooks/api/v1alpha1/discovery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func init() {
"Runtime Extension implementers must use this hook to inform the Cluster API runtime about all the handlers " +
"that are defined in an external component implementing Runtime Extensions.\n" +
"\n" +
"Notes:\n" +
"Notes:\n" + //nolint:goconst
"- When using Runtime SDK utils, a handler for this hook is automatically generated",
Singleton: true,
})
Expand Down
2 changes: 1 addition & 1 deletion exp/runtime/hooks/api/v1alpha1/lifecyclehooks_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func init() {
"all the objects which are part of a Cluster's topology are going to be created.\n" +
"\n" +
"Notes:\n" +
"- This hook will be called only for Clusters with a managed topology\n" +
"- This hook will be called only for Clusters with a managed topology\n" + //nolint:goconst
"- The call's request contains the Cluster object\n" +
"- This is a blocking hook; Runtime Extension implementers can use this hook to execute\n" +
"tasks before the objects which are part of a Cluster's topology are created",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ func (r *Reconciler) getMachineDeploymentsForMachineSet(ctx context.Context, ms
}

deployments := make([]*clusterv1.MachineDeployment, 0, len(dList.Items))
for idx, d := range dList.Items {
selector, err := metav1.LabelSelectorAsSelector(&d.Spec.Selector)
for idx := range dList.Items {
selector, err := metav1.LabelSelectorAsSelector(&dList.Items[idx].Spec.Selector)
if err != nil {
continue
}
Expand Down
3 changes: 2 additions & 1 deletion internal/topology/check/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ func ClusterClassReferencesAreValid(clusterClass *clusterv1.ClusterClass) field.
allErrs = append(allErrs, LocalObjectTemplateIsValid(clusterClass.Spec.ControlPlane.MachineInfrastructure, clusterClass.Namespace, field.NewPath("spec", "controlPlane", "machineInfrastructure"))...)
}

for i, mdc := range clusterClass.Spec.Workers.MachineDeployments {
for i := range clusterClass.Spec.Workers.MachineDeployments {
mdc := clusterClass.Spec.Workers.MachineDeployments[i]
allErrs = append(allErrs, LocalObjectTemplateIsValid(&mdc.Template.Bootstrap, clusterClass.Namespace,
field.NewPath("spec", "workers", "machineDeployments").Index(i).Child("template", "bootstrap"))...)
allErrs = append(allErrs, LocalObjectTemplateIsValid(&mdc.Template.Infrastructure, clusterClass.Namespace,
Expand Down
3 changes: 2 additions & 1 deletion internal/webhooks/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ func validateMachineHealthChecks(cluster *clusterv1.Cluster, clusterClass *clust
}

if cluster.Spec.Topology.Workers != nil {
for i, md := range cluster.Spec.Topology.Workers.MachineDeployments {
for i := range cluster.Spec.Topology.Workers.MachineDeployments {
md := cluster.Spec.Topology.Workers.MachineDeployments[i]
if md.MachineHealthCheck != nil {
fldPath := field.NewPath("spec", "topology", "workers", "machineDeployments", "machineHealthCheck").Index(i)

Expand Down
3 changes: 2 additions & 1 deletion test/framework/machinedeployment_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ func AssertMachineDeploymentFailureDomains(ctx context.Context, input AssertMach
return input.Lister.List(ctx, ms, client.InNamespace(input.Cluster.Namespace), client.MatchingLabels(selectorMap))
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to list MachineSets for Cluster %s", klog.KObj(input.Cluster))

for _, machineSet := range ms.Items {
for i := range ms.Items {
machineSet := ms.Items[i]
machineSetFD := pointer.StringDeref(machineSet.Spec.Template.Spec.FailureDomain, "<None>")
Expect(machineSetFD).To(Equal(machineDeploymentFD), "MachineSet %s is in the %q failure domain, expecting %q", machineSet.Name, machineSetFD, machineDeploymentFD)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func TestReconcileNormalEtcd(t *testing.T) {

manager := cmanager.New(scheme)

host := "127.0.0.1" //nolint:goconst
host := "127.0.0.1"
wcmux, err := server.NewWorkloadClustersMux(manager, host, server.CustomPorts{
// NOTE: make sure to use ports different than other tests, so we can run tests in parallel
MinPort: server.DefaultMinPort + 1000,
Expand Down
2 changes: 1 addition & 1 deletion test/infrastructure/inmemory/internal/server/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestMux(t *testing.T) {
manager := cmanager.New(scheme)

wcl := "workload-cluster"
host := "127.0.0.1" //nolint:goconst
host := "127.0.0.1"
wcmux, err := NewWorkloadClustersMux(manager, host, CustomPorts{
// NOTE: make sure to use ports different than other tests, so we can run tests in parallel
MinPort: DefaultMinPort,
Expand Down
4 changes: 2 additions & 2 deletions util/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func (v buildIdentifiers) compare(o buildIdentifiers) int {
return 0
} else if i == len(v) && i < len(o) {
return -1
} else {
return 1
}

return 1
}

type buildIdentifier struct {
Expand Down

0 comments on commit dca1937

Please sign in to comment.