Skip to content

Commit 8b2b5bf

Browse files
comtalystclaude
andcommitted
fix: resolve lint issues (cyclomatic complexity and variable shadow)
- Split popCreationResult() into popAKSMachineCreationResult() and popVMCreationResult() to reduce cyclomatic complexity from 13 to within limit - Rename local nodeClaim to testNodeClaim to avoid shadowing package-level var Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 791063e commit 8b2b5bf

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

pkg/cloudprovider/suite_features_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,13 +1614,13 @@ var _ = Describe("CloudProvider - Features", func() {
16141614
})
16151615
It("should not reattempt creation of a vm thats been created before, and also not CSE", func() {
16161616
// This test is more like a sanity check of the current intended behavior. The design of the behavior can be changed if intended.
1617-
nodeClaim := coretest.NodeClaim(karpv1.NodeClaim{
1617+
testNodeClaim := coretest.NodeClaim(karpv1.NodeClaim{
16181618
ObjectMeta: metav1.ObjectMeta{
16191619
Labels: map[string]string{"karpenter.sh/nodepool": nodePool.Name},
16201620
},
16211621
Spec: karpv1.NodeClaimSpec{NodeClassRef: &karpv1.NodeClassReference{Name: nodeClass.Name}},
16221622
})
1623-
vmName := instance.GenerateResourceName(nodeClaim.Name)
1623+
vmName := instance.GenerateResourceName(testNodeClaim.Name)
16241624
vm := &armcompute.VirtualMachine{
16251625
Name: lo.ToPtr(vmName),
16261626
ID: lo.ToPtr(fake.MkVMID(options.FromContext(ctx).NodeResourceGroup, vmName)),
@@ -1635,7 +1635,7 @@ var _ = Describe("CloudProvider - Features", func() {
16351635
}
16361636
azureEnv.VirtualMachinesAPI.Instances.Store(lo.FromPtr(vm.ID), *vm)
16371637
ExpectApplied(ctx, env.Client, nodePool, nodeClass)
1638-
_, err := cloudProvider.Create(ctx, nodeClaim) // Async routine can still be ran in the background after this point
1638+
_, err := cloudProvider.Create(ctx, testNodeClaim) // Async routine can still be ran in the background after this point
16391639
Expect(err).ToNot(HaveOccurred())
16401640

16411641
ExpectCSENotProvisioned(azureEnv)

pkg/cloudprovider/suite_shared_provision_test.go

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -289,41 +289,47 @@ func getCreateCallCount() int {
289289
func popCreationResult() creationResult {
290290
GinkgoHelper()
291291
if isAKSMachineMode() {
292-
input := azureEnv.AKSMachinesAPI.AKSMachineCreateOrUpdateBehavior.CalledWithInput.Pop()
293-
m := input.AKSMachine
294-
// Preserved nil guards from original AKS Machine tests
295-
Expect(m.Properties).ToNot(BeNil())
296-
Expect(m.Properties.Hardware).ToNot(BeNil())
297-
Expect(m.Properties.Hardware.VMSize).ToNot(BeNil())
298-
299-
zone, zoneErr := instance.GetAKSLabelZoneFromAKSMachine(&m, fake.Region)
300-
isEphemeral := false
301-
var osDiskType string
302-
if m.Properties.OperatingSystem != nil && m.Properties.OperatingSystem.OSDiskType != nil {
303-
osDiskType = string(*m.Properties.OperatingSystem.OSDiskType)
304-
isEphemeral = *m.Properties.OperatingSystem.OSDiskType == armcontainerservice.OSDiskTypeEphemeral
305-
}
306-
var diskSizeGB *int32
307-
if m.Properties.OperatingSystem != nil {
308-
diskSizeGB = m.Properties.OperatingSystem.OSDiskSizeGB
309-
}
310-
return creationResult{
311-
vmSize: lo.FromPtr(m.Properties.Hardware.VMSize),
312-
zone: zone,
313-
zoneErr: zoneErr,
314-
zones: m.Zones,
315-
tags: m.Properties.Tags,
316-
isEphemeral: isEphemeral,
317-
diskSizeGB: diskSizeGB,
318-
osDiskType: osDiskType,
319-
imageRef: lo.FromPtr(m.Properties.NodeImageVersion),
320-
}
292+
return popAKSMachineCreationResult()
321293
}
294+
return popVMCreationResult()
295+
}
322296

323-
// VM mode (AKSScriptless or BootstrappingClient)
297+
func popAKSMachineCreationResult() creationResult {
298+
GinkgoHelper()
299+
input := azureEnv.AKSMachinesAPI.AKSMachineCreateOrUpdateBehavior.CalledWithInput.Pop()
300+
m := input.AKSMachine
301+
Expect(m.Properties).ToNot(BeNil())
302+
Expect(m.Properties.Hardware).ToNot(BeNil())
303+
Expect(m.Properties.Hardware.VMSize).ToNot(BeNil())
304+
305+
zone, zoneErr := instance.GetAKSLabelZoneFromAKSMachine(&m, fake.Region)
306+
isEphemeral := false
307+
var osDiskType string
308+
if m.Properties.OperatingSystem != nil && m.Properties.OperatingSystem.OSDiskType != nil {
309+
osDiskType = string(*m.Properties.OperatingSystem.OSDiskType)
310+
isEphemeral = *m.Properties.OperatingSystem.OSDiskType == armcontainerservice.OSDiskTypeEphemeral
311+
}
312+
var diskSizeGB *int32
313+
if m.Properties.OperatingSystem != nil {
314+
diskSizeGB = m.Properties.OperatingSystem.OSDiskSizeGB
315+
}
316+
return creationResult{
317+
vmSize: lo.FromPtr(m.Properties.Hardware.VMSize),
318+
zone: zone,
319+
zoneErr: zoneErr,
320+
zones: m.Zones,
321+
tags: m.Properties.Tags,
322+
isEphemeral: isEphemeral,
323+
diskSizeGB: diskSizeGB,
324+
osDiskType: osDiskType,
325+
imageRef: lo.FromPtr(m.Properties.NodeImageVersion),
326+
}
327+
}
328+
329+
func popVMCreationResult() creationResult {
330+
GinkgoHelper()
324331
input := azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.CalledWithInput.Pop()
325332
vm := input.VM
326-
// Preserved nil guards from original VM tests
327333
Expect(vm.Properties).ToNot(BeNil())
328334
Expect(vm.Properties.HardwareProfile).ToNot(BeNil())
329335
Expect(vm.Properties.StorageProfile).ToNot(BeNil())

0 commit comments

Comments
 (0)