From 209a0c8fc82bcb606d6743faeab39ba803534ad2 Mon Sep 17 00:00:00 2001 From: haijianyang Date: Mon, 26 Feb 2024 21:34:06 -0500 Subject: [PATCH] Fix comments --- controllers/elfmachine_controller_test.go | 8 +++--- controllers/tower_cache.go | 2 +- controllers/tower_cache_test.go | 30 +++++++++++------------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/controllers/elfmachine_controller_test.go b/controllers/elfmachine_controller_test.go index b5051918..c27da389 100644 --- a/controllers/elfmachine_controller_test.go +++ b/controllers/elfmachine_controller_test.go @@ -258,7 +258,7 @@ var _ = Describe("ElfMachineReconciler", func() { expectConditions(elfMachine, []conditionAssertion{{infrav1.VMProvisionedCondition, corev1.ConditionFalse, clusterv1.ConditionSeverityWarning, infrav1.CloningFailedReason}}) }) - It("should create a new VM if none exists", func() { + It("should create a new VM if the VM does not exist", func() { resetMemoryCache() vm := fake.NewTowerVM() vm.Name = &elfMachine.Name @@ -271,7 +271,7 @@ var _ = Describe("ElfMachineReconciler", func() { machineContext := newMachineContext(ctrlContext, elfCluster, cluster, elfMachine, machine, mockVMService) machineContext.VMService = mockVMService - recordIsUnmet(machineContext, clusterInsufficientStorageKey, true) + recordOrClearError(machineContext, clusterInsufficientStorageKey, true) mockVMService.EXPECT().GetVMPlacementGroup(gomock.Any()).Return(placementGroup, nil) elfMachineKey := capiutil.ObjectKey(elfMachine) reconciler := &ElfMachineReconciler{ControllerContext: ctrlContext, NewVMService: mockNewVMService} @@ -286,7 +286,7 @@ var _ = Describe("ElfMachineReconciler", func() { ctrlContext = newCtrlContexts(elfCluster, cluster, elfMachine, machine, secret, md) fake.InitOwnerReferences(ctrlContext, elfCluster, cluster, elfMachine, machine) machineContext = newMachineContext(ctrlContext, elfCluster, cluster, elfMachine, machine, mockVMService) - recordIsUnmet(machineContext, clusterInsufficientMemoryKey, true) + recordOrClearError(machineContext, clusterInsufficientMemoryKey, true) reconciler = &ElfMachineReconciler{ControllerContext: ctrlContext, NewVMService: mockNewVMService} result, err = reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: elfMachineKey}) Expect(result.RequeueAfter).NotTo(BeZero()) @@ -845,7 +845,7 @@ var _ = Describe("ElfMachineReconciler", func() { fake.InitOwnerReferences(ctrlContext, elfCluster, cluster, elfMachine, machine) machineContext := newMachineContext(ctrlContext, elfCluster, cluster, elfMachine, machine, mockVMService) machineContext.VMService = mockVMService - recordIsUnmet(machineContext, clusterInsufficientMemoryKey, true) + recordOrClearError(machineContext, clusterInsufficientMemoryKey, true) reconciler := &ElfMachineReconciler{ControllerContext: ctrlContext, NewVMService: mockNewVMService} err := reconciler.powerOnVM(machineContext, vm) Expect(err).NotTo(HaveOccurred()) diff --git a/controllers/tower_cache.go b/controllers/tower_cache.go index 6349e3a8..9e3d9c86 100644 --- a/controllers/tower_cache.go +++ b/controllers/tower_cache.go @@ -51,7 +51,7 @@ type clusterResource struct { // Includes these scenarios: // 1. ELF cluster has insufficient memory. // 2. ELF cluster has insufficient storage. -// 3. Placement group not satisfy policy. +// 3. Cannot satisfy the PlacementGroup policy. func isELFScheduleVMErrorRecorded(ctx *context.MachineContext) (bool, string, error) { lock.Lock() defer lock.Unlock() diff --git a/controllers/tower_cache_test.go b/controllers/tower_cache_test.go index b04ab2be..d8c52b24 100644 --- a/controllers/tower_cache_test.go +++ b/controllers/tower_cache_test.go @@ -61,19 +61,19 @@ var _ = Describe("TowerCache", func() { _, found := inMemoryCache.Get(key) Expect(found).To(BeFalse()) - recordIsUnmet(machineContext, name, true) + recordOrClearError(machineContext, name, true) _, found = inMemoryCache.Get(key) Expect(found).To(BeTrue()) resource := getClusterResource(key) Expect(resource.LastDetected).To(Equal(resource.LastRetried)) - recordIsUnmet(machineContext, name, true) + recordOrClearError(machineContext, name, true) lastDetected := resource.LastDetected resource = getClusterResource(key) Expect(resource.LastDetected).To(Equal(resource.LastRetried)) Expect(resource.LastDetected.After(lastDetected)).To(BeTrue()) - recordIsUnmet(machineContext, name, false) + recordOrClearError(machineContext, name, false) resource = getClusterResource(key) Expect(resource).To(BeNil()) @@ -81,17 +81,17 @@ var _ = Describe("TowerCache", func() { _, found = inMemoryCache.Get(key) Expect(found).To(BeFalse()) - recordIsUnmet(machineContext, name, false) + recordOrClearError(machineContext, name, false) resource = getClusterResource(key) _, found = inMemoryCache.Get(key) Expect(found).To(BeFalse()) Expect(resource).To(BeNil()) - recordIsUnmet(machineContext, name, false) + recordOrClearError(machineContext, name, false) resource = getClusterResource(key) Expect(resource).To(BeNil()) - recordIsUnmet(machineContext, name, true) + recordOrClearError(machineContext, name, true) _, found = inMemoryCache.Get(key) Expect(found).To(BeTrue()) resource = getClusterResource(key) @@ -118,12 +118,12 @@ var _ = Describe("TowerCache", func() { Expect(ok).To(BeFalse()) Expect(err).ShouldNot(HaveOccurred()) - recordIsUnmet(machineContext, name, false) + recordOrClearError(machineContext, name, false) ok, err = canRetryVMOperation(machineContext) Expect(ok).To(BeFalse()) Expect(err).ShouldNot(HaveOccurred()) - recordIsUnmet(machineContext, name, true) + recordOrClearError(machineContext, name, true) ok, err = canRetryVMOperation(machineContext) Expect(ok).To(BeFalse()) Expect(err).ShouldNot(HaveOccurred()) @@ -157,7 +157,7 @@ var _ = Describe("TowerCache", func() { expectConditions(elfMachine, []conditionAssertion{}) elfCluster.Spec.Cluster = clusterInsufficientMemoryKey - recordIsUnmet(machineContext, clusterInsufficientMemoryKey, true) + recordOrClearError(machineContext, clusterInsufficientMemoryKey, true) ok, msg, err = isELFScheduleVMErrorRecorded(machineContext) Expect(ok).To(BeTrue()) Expect(msg).To(ContainSubstring("Insufficient memory detected for the ELF cluster")) @@ -166,7 +166,7 @@ var _ = Describe("TowerCache", func() { resetMemoryCache() elfCluster.Spec.Cluster = clusterInsufficientStorageKey - recordIsUnmet(machineContext, clusterInsufficientStorageKey, true) + recordOrClearError(machineContext, clusterInsufficientStorageKey, true) ok, msg, err = isELFScheduleVMErrorRecorded(machineContext) Expect(ok).To(BeTrue()) Expect(msg).To(ContainSubstring("Insufficient storage detected for the ELF cluster clusterInsufficientStorage")) @@ -174,7 +174,7 @@ var _ = Describe("TowerCache", func() { expectConditions(elfMachine, []conditionAssertion{{infrav1.VMProvisionedCondition, corev1.ConditionFalse, clusterv1.ConditionSeverityInfo, infrav1.WaitingForELFClusterWithSufficientStorageReason}}) resetMemoryCache() - recordIsUnmet(machineContext, placementGroupKey, true) + recordOrClearError(machineContext, placementGroupKey, true) ok, msg, err = isELFScheduleVMErrorRecorded(machineContext) Expect(ok).To(BeTrue()) Expect(msg).To(ContainSubstring("Not satisfy policy detected for the placement group")) @@ -244,16 +244,16 @@ func getKey(ctx *context.MachineContext, name string) string { return getKeyForDuplicatePlacementGroupError(placementGroupName) } -func recordIsUnmet(ctx *context.MachineContext, key string, isUnmet bool) { +func recordOrClearError(ctx *context.MachineContext, key string, record bool) { if strings.Contains(key, clusterInsufficientMemoryKey) { - recordElfClusterMemoryInsufficient(ctx, isUnmet) + recordElfClusterMemoryInsufficient(ctx, record) return } else if strings.Contains(key, clusterInsufficientStorageKey) { - recordElfClusterStorageInsufficient(ctx, isUnmet) + recordElfClusterStorageInsufficient(ctx, record) return } - Expect(recordPlacementGroupPolicyNotSatisfied(ctx, isUnmet)).ShouldNot(HaveOccurred()) + Expect(recordPlacementGroupPolicyNotSatisfied(ctx, record)).ShouldNot(HaveOccurred()) } func expireELFScheduleVMError(ctx *context.MachineContext, name string) {