Skip to content

Commit 37b8794

Browse files
committed
Added some logs and fixed the unit test
1 parent b0e3658 commit 37b8794

File tree

2 files changed

+16
-40
lines changed

2 files changed

+16
-40
lines changed

exp/controllers/awsmachinepool_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ func (r *AWSMachinePoolReconciler) updatePool(machinePoolScope *scope.MachinePoo
404404

405405
suspendedProcessesSlice := machinePoolScope.AWSMachinePool.Spec.SuspendProcesses.ConvertSetValuesToStringSlice()
406406
if !cmp.Equal(existingASG.CurrentlySuspendProcesses, suspendedProcessesSlice) {
407+
clusterScope.Info("reconciling processes", "suspend-processes", suspendedProcessesSlice)
407408
var (
408409
toBeSuspended []string
409410
toBeResumed []string
@@ -431,7 +432,7 @@ func (r *AWSMachinePoolReconciler) updatePool(machinePoolScope *scope.MachinePoo
431432
delete(currentlySuspended, k)
432433
}
433434

434-
// Convert them back into lists so
435+
// Convert them back into lists to pass them to resume/suspend.
435436
for k := range desiredSuspended {
436437
toBeSuspended = append(toBeSuspended, k)
437438
}
@@ -441,11 +442,13 @@ func (r *AWSMachinePoolReconciler) updatePool(machinePoolScope *scope.MachinePoo
441442
}
442443

443444
if len(toBeSuspended) > 0 {
445+
clusterScope.Info("suspending processes", "processes", toBeSuspended)
444446
if err := asgSvc.SuspendProcesses(existingASG.Name, toBeSuspended); err != nil {
445447
return errors.Wrapf(err, "failed to suspend processes while trying update pool")
446448
}
447449
}
448450
if len(toBeResumed) > 0 {
451+
clusterScope.Info("resuming processes", "processes", toBeResumed)
449452
if err := asgSvc.ResumeProcesses(existingASG.Name, toBeResumed); err != nil {
450453
return errors.Wrapf(err, "failed to resume processes while trying update pool")
451454
}

exp/controllers/awsmachinepool_controller_test.go

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
266266
},
267267
}
268268
}
269-
t.Run("it should suspend these processes", func(t *testing.T) {
269+
t.Run("it should not call suspend as we don't have an ASG yet", func(t *testing.T) {
270270
g := NewWithT(t)
271271
setup(t, g)
272272
defer teardown(t, g)
@@ -277,7 +277,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
277277
asgSvc.EXPECT().CreateASG(gomock.Any()).Return(&expinfrav1.AutoScalingGroup{
278278
Name: "name",
279279
}, nil)
280-
asgSvc.EXPECT().SuspendProcesses("name", []string{"Launch", "Terminate"}).Return(nil).AnyTimes()
280+
asgSvc.EXPECT().SuspendProcesses("name", []string{"Launch", "Terminate"}).Return(nil).AnyTimes().Times(0)
281281

282282
_, err := reconciler.reconcileNormal(context.Background(), ms, cs, cs)
283283
g.Expect(err).To(Succeed())
@@ -290,56 +290,29 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
290290
All: true,
291291
}
292292
}
293-
t.Run("it should result in all processes being included except the value all", func(t *testing.T) {
293+
t.Run("processes should be suspended during an update call", func(t *testing.T) {
294294
g := NewWithT(t)
295295
setup(t, g)
296296
defer teardown(t, g)
297297
setSuspendedProcesses(t, g)
298-
298+
ms.AWSMachinePool.Spec.SuspendProcesses.All = true
299299
ec2Svc.EXPECT().ReconcileLaunchTemplate(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
300-
asgSvc.EXPECT().GetASGByName(gomock.Any()).Return(nil, nil)
301-
asgSvc.EXPECT().CreateASG(gomock.Any()).Return(&expinfrav1.AutoScalingGroup{
300+
ec2Svc.EXPECT().ReconcileTags(gomock.Any(), gomock.Any()).Return(nil)
301+
asgSvc.EXPECT().GetASGByName(gomock.Any()).Return(&expinfrav1.AutoScalingGroup{
302302
Name: "name",
303303
}, nil)
304-
asgSvc.EXPECT().SuspendProcesses("name", []string{
304+
asgSvc.EXPECT().UpdateASG(gomock.Any()).Return(nil).AnyTimes()
305+
asgSvc.EXPECT().SuspendProcesses("name", gomock.InAnyOrder([]string{
306+
"ScheduledActions",
305307
"Launch",
306308
"Terminate",
307309
"AddToLoadBalancer",
308310
"AlarmNotification",
309311
"AZRebalance",
310-
"HealthCheck",
311312
"InstanceRefresh",
312-
"ReplaceUnhealthy",
313-
"ScheduledActions",
314-
}).Return(nil).AnyTimes()
315-
316-
_, err := reconciler.reconcileNormal(context.Background(), ms, cs, cs)
317-
g.Expect(err).To(Succeed())
318-
})
319-
t.Run("and one or more processes are disabled, it should not list those", func(t *testing.T) {
320-
g := NewWithT(t)
321-
setup(t, g)
322-
defer teardown(t, g)
323-
setSuspendedProcesses(t, g)
324-
ms.AWSMachinePool.Spec.SuspendProcesses.Processes = &expinfrav1.Processes{
325-
Launch: pointer.Bool(false),
326-
AZRebalance: pointer.Bool(true), // this should still be included but not twice...
327-
}
328-
ec2Svc.EXPECT().ReconcileLaunchTemplate(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
329-
asgSvc.EXPECT().GetASGByName(gomock.Any()).Return(nil, nil)
330-
asgSvc.EXPECT().CreateASG(gomock.Any()).Return(&expinfrav1.AutoScalingGroup{
331-
Name: "name",
332-
}, nil)
333-
asgSvc.EXPECT().SuspendProcesses("name", []string{
334-
"Terminate",
335-
"AddToLoadBalancer",
336-
"AlarmNotification",
337-
"AZRebalance",
338313
"HealthCheck",
339-
"InstanceRefresh",
340314
"ReplaceUnhealthy",
341-
"ScheduledActions",
342-
}).Return(nil).AnyTimes()
315+
})).Return(nil).AnyTimes().Times(1)
343316

344317
_, err := reconciler.reconcileNormal(context.Background(), ms, cs, cs)
345318
g.Expect(err).To(Succeed())
@@ -369,8 +342,8 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
369342
CurrentlySuspendProcesses: []string{"Launch", "process3"},
370343
}, nil)
371344
asgSvc.EXPECT().UpdateASG(gomock.Any()).Return(nil).AnyTimes()
372-
asgSvc.EXPECT().SuspendProcesses("name", []string{"Terminate"}).Return(nil).AnyTimes()
373-
asgSvc.EXPECT().ResumeProcesses("name", []string{"process3"}).Return(nil).AnyTimes()
345+
asgSvc.EXPECT().SuspendProcesses("name", []string{"Terminate"}).Return(nil).AnyTimes().Times(1)
346+
asgSvc.EXPECT().ResumeProcesses("name", []string{"process3"}).Return(nil).AnyTimes().Times(1)
374347

375348
_, err := reconciler.reconcileNormal(context.Background(), ms, cs, cs)
376349
g.Expect(err).To(Succeed())

0 commit comments

Comments
 (0)