Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
haijianyang committed Feb 27, 2024
1 parent a8f8d38 commit 209a0c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions controllers/elfmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion controllers/tower_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
30 changes: 15 additions & 15 deletions controllers/tower_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,37 @@ 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())

resetMemoryCache()
_, 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)
Expand All @@ -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())
Expand Down Expand Up @@ -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"))
Expand All @@ -166,15 +166,15 @@ 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"))
Expect(err).ShouldNot(HaveOccurred())
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"))
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 209a0c8

Please sign in to comment.