Skip to content

Commit d9fc4b9

Browse files
chore(golangci-lint): add gocritic linter
1 parent 71f1710 commit d9fc4b9

File tree

27 files changed

+63
-79
lines changed

27 files changed

+63
-79
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters:
1818
- exportloopref
1919
- gci
2020
- goconst
21+
- gocritic
2122
- gocyclo
2223
- godot
2324
- gofmt

api/v1alpha3/azuremachine_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type AzureMachineSpec struct {
4242
// as defined in Cluster API. This relates to an Azure Availability Zone
4343
FailureDomain *string `json:"failureDomain,omitempty"`
4444

45-
// DEPRECATED: use FailureDomain instead
45+
// Deprecated: use FailureDomain instead
4646
AvailabilityZone AvailabilityZone `json:"availabilityZone,omitempty"`
4747

4848
// Image is used to provide details of an image to use during VM creation.
@@ -79,7 +79,7 @@ type AzureMachineSpec struct {
7979
// DataDisk specifies the parameters that are used to add one or more data disks to the machine
8080
DataDisks []DataDisk `json:"dataDisks,omitempty"`
8181

82-
// DEPRECATED: to support old clients, will be removed in v1alpha4/v1beta1
82+
// Deprecated: to support old clients, will be removed in v1alpha4/v1beta1
8383
Location string `json:"location"`
8484

8585
SSHPublicKey string `json:"sshPublicKey"`

api/v1alpha3/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type VnetSpec struct {
7272
Name string `json:"name"`
7373

7474
// CidrBlock is the CIDR block to be used when the provider creates a managed virtual network.
75-
// DEPRECATED: Use CIDRBlocks instead
75+
// Deprecated: Use CIDRBlocks instead
7676
// +optional
7777
CidrBlock string `json:"cidrBlock,omitempty"`
7878

@@ -311,7 +311,7 @@ type AzureSharedGalleryImage struct {
311311

312312
// AvailabilityZone specifies an Azure Availability Zone.
313313
//
314-
// DEPRECATED: Use FailureDomain instead.
314+
// Deprecated: Use FailureDomain instead.
315315
type AvailabilityZone struct {
316316
ID *string `json:"id,omitempty"`
317317
Enabled *bool `json:"enabled,omitempty"`
@@ -432,7 +432,7 @@ type SubnetSpec struct {
432432
Name string `json:"name"`
433433

434434
// CidrBlock is the CIDR block to be used when the provider creates a managed Vnet.
435-
// DEPRECATED: Use CIDRBlocks instead
435+
// Deprecated: Use CIDRBlocks instead
436436
// +optional
437437
CidrBlock string `json:"cidrBlock,omitempty"`
438438

api/v1alpha4/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ type PublicIPSpec struct {
242242
}
243243

244244
// VMState describes the state of an Azure virtual machine.
245-
// DEPRECATED: use ProvisioningState.
245+
// Deprecated: use ProvisioningState.
246246
type VMState string
247247

248248
// ProvisioningState describes the provisioning state of an Azure resource.

api/v1beta1/azurecluster_webhook_test.go

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ func TestAzureCluster_ValidateCreate(t *testing.T) {
3333
}{
3434
{
3535
name: "azurecluster with pre-existing vnet - valid spec",
36-
cluster: func() *AzureCluster {
37-
return createValidCluster()
38-
}(),
36+
cluster: createValidCluster(),
3937
wantErr: false,
4038
},
4139
{
@@ -140,9 +138,7 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
140138
},
141139
{
142140
name: "azurecluster with no control plane endpoint - valid spec",
143-
oldCluster: func() *AzureCluster {
144-
return createValidCluster()
145-
}(),
141+
oldCluster: createValidCluster(),
146142
cluster: func() *AzureCluster {
147143
cluster := createValidCluster()
148144
cluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{
@@ -155,12 +151,8 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
155151
},
156152
{
157153
name: "azurecluster with pre-existing vnet - valid spec",
158-
oldCluster: func() *AzureCluster {
159-
return createValidCluster()
160-
}(),
161-
cluster: func() *AzureCluster {
162-
return createValidCluster()
163-
}(),
154+
oldCluster: createValidCluster(),
155+
cluster: createValidCluster(),
164156
wantErr: false,
165157
},
166158
{
@@ -179,9 +171,7 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
179171
},
180172
{
181173
name: "azurecluster with pre-existing vnet - lack control plane subnet",
182-
oldCluster: func() *AzureCluster {
183-
return createValidCluster()
184-
}(),
174+
oldCluster: createValidCluster(),
185175
cluster: func() *AzureCluster {
186176
cluster := createValidCluster()
187177
cluster.Spec.NetworkSpec.Subnets = cluster.Spec.NetworkSpec.Subnets[1:]
@@ -191,9 +181,7 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
191181
},
192182
{
193183
name: "azurecluster with pre-existing vnet - lack node subnet",
194-
oldCluster: func() *AzureCluster {
195-
return createValidCluster()
196-
}(),
184+
oldCluster: createValidCluster(),
197185
cluster: func() *AzureCluster {
198186
cluster := createValidCluster()
199187
cluster.Spec.NetworkSpec.Subnets = cluster.Spec.NetworkSpec.Subnets[:1]
@@ -203,9 +191,7 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
203191
},
204192
{
205193
name: "azurecluster with pre-existing vnet - invalid resourcegroup name",
206-
oldCluster: func() *AzureCluster {
207-
return createValidCluster()
208-
}(),
194+
oldCluster: createValidCluster(),
209195
cluster: func() *AzureCluster {
210196
cluster := createValidCluster()
211197
cluster.Spec.NetworkSpec.Vnet.ResourceGroup = "invalid-name###"
@@ -215,9 +201,7 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
215201
},
216202
{
217203
name: "azurecluster with pre-existing vnet - invalid subnet name",
218-
oldCluster: func() *AzureCluster {
219-
return createValidCluster()
220-
}(),
204+
oldCluster: createValidCluster(),
221205
cluster: func() *AzureCluster {
222206
cluster := createValidCluster()
223207
cluster.Spec.NetworkSpec.Subnets = append(cluster.Spec.NetworkSpec.Subnets,

api/v1beta1/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ type PublicIPSpec struct {
269269
}
270270

271271
// VMState describes the state of an Azure virtual machine.
272-
// DEPRECATED: use ProvisioningState.
272+
// Deprecated: use ProvisioningState.
273273
type VMState string
274274

275275
// ProvisioningState describes the provisioning state of an Azure resource.

azure/converters/loadbalancers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323

2424
// SKUtoSDK converts infrav1.SKU into a network.LoadBalancerSkuName.
2525
func SKUtoSDK(src infrav1.SKU) network.LoadBalancerSkuName {
26-
switch src {
27-
case infrav1.SKUStandard:
26+
if src == infrav1.SKUStandard {
2827
return network.LoadBalancerSkuNameStandard
2928
}
3029
return ""

azure/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func GetDefaultWindowsImage(k8sVersion, runtime string) (*infrav1.Image, error)
317317

318318
// Starting with 1.22 we default to containerd for Windows unless the runtime flag is set.
319319
if v.GTE(v122) && runtime != "dockershim" {
320-
skuID = skuID + "-containerd"
320+
skuID += "-containerd"
321321
}
322322

323323
defaultImage := &infrav1.Image{

azure/scope/cluster.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ func (s *ClusterScope) GenerateFQDN(ipName string) string {
656656
}
657657

658658
// GenerateLegacyFQDN generates an IP name and a fully qualified domain name, based on a hash, cluster name and cluster location.
659-
// DEPRECATED: use GenerateFQDN instead.
659+
// Deprecated: use GenerateFQDN instead.
660660
func (s *ClusterScope) GenerateLegacyFQDN() (string, string) {
661661
h := fnv.New32a()
662662
if _, err := h.Write([]byte(fmt.Sprintf("%s/%s/%s", s.SubscriptionID(), s.ResourceGroup(), s.ClusterName()))); err != nil {
@@ -831,20 +831,20 @@ func (s *ClusterScope) SetDNSName() {
831831
func (s *ClusterScope) getOutboundLBPublicIPSpecs(outboundLB *infrav1.LoadBalancerSpec, generateOutboundIPName func(string) string) []azure.PublicIPSpec {
832832
var outboundIPSpecs []azure.PublicIPSpec
833833
loadBalancerNodeOutboundIPs := outboundLB.FrontendIPsCount
834-
if loadBalancerNodeOutboundIPs == nil || *loadBalancerNodeOutboundIPs == 0 {
834+
switch {
835+
case loadBalancerNodeOutboundIPs == nil || *loadBalancerNodeOutboundIPs == 0:
835836
// do nothing
836-
} else if *loadBalancerNodeOutboundIPs == 1 {
837+
case *loadBalancerNodeOutboundIPs == 1:
837838
outboundIPSpecs = append(outboundIPSpecs, azure.PublicIPSpec{
838839
Name: generateOutboundIPName(s.ClusterName()),
839840
})
840-
} else {
841+
default:
841842
for i := 0; i < int(*loadBalancerNodeOutboundIPs); i++ {
842843
outboundIPSpecs = append(outboundIPSpecs, azure.PublicIPSpec{
843844
Name: azure.WithIndex(generateOutboundIPName(s.ClusterName()), i+1),
844845
})
845846
}
846847
}
847-
848848
return outboundIPSpecs
849849
}
850850

azure/scope/identity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func createAzureIdentityWithBindings(ctx context.Context, azureIdentity *infrav1
270270
},
271271
Spec: aadpodv1.AzureIdentityBindingSpec{
272272
AzureIdentity: copiedIdentity.Name,
273-
Selector: infrav1.AzureIdentityBindingSelector, //should be same as selector added on controller
273+
Selector: infrav1.AzureIdentityBindingSelector, // should be same as selector added on controller
274274
},
275275
}
276276
err = kubeClient.Create(ctx, azureIdentityBinding)

0 commit comments

Comments
 (0)