Skip to content

Commit aec9433

Browse files
authored
Merge pull request #3864 from Skarlso/fix_suspend_process
Remove suspend process flow from create ASG
2 parents 5592d44 + 37b8794 commit aec9433

File tree

2 files changed

+22
-50
lines changed

2 files changed

+22
-50
lines changed

exp/controllers/awsmachinepool_controller.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (r *AWSMachinePoolReconciler) reconcileNormal(ctx context.Context, machineP
267267

268268
if asg == nil {
269269
// Create new ASG
270-
if _, err := r.createPool(machinePoolScope, clusterScope); err != nil {
270+
if err := r.createPool(machinePoolScope, clusterScope); err != nil {
271271
conditions.MarkFalse(machinePoolScope.AWSMachinePool, expinfrav1.ASGReadyCondition, expinfrav1.ASGProvisionFailedReason, clusterv1.ConditionSeverityError, err.Error())
272272
return ctrl.Result{}, err
273273
}
@@ -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
}
@@ -454,21 +457,17 @@ func (r *AWSMachinePoolReconciler) updatePool(machinePoolScope *scope.MachinePoo
454457
return nil
455458
}
456459

457-
func (r *AWSMachinePoolReconciler) createPool(machinePoolScope *scope.MachinePoolScope, clusterScope cloud.ClusterScoper) (*expinfrav1.AutoScalingGroup, error) {
460+
func (r *AWSMachinePoolReconciler) createPool(machinePoolScope *scope.MachinePoolScope, clusterScope cloud.ClusterScoper) error {
458461
clusterScope.Info("Initializing ASG client")
459462

460463
asgsvc := r.getASGService(clusterScope)
461464

462465
machinePoolScope.Info("Creating Autoscaling Group")
463-
asg, err := asgsvc.CreateASG(machinePoolScope)
464-
if err != nil {
465-
return nil, errors.Wrapf(err, "failed to create AWSMachinePool")
466-
}
467-
suspendedProcessesSlice := machinePoolScope.AWSMachinePool.Spec.SuspendProcesses.ConvertSetValuesToStringSlice()
468-
if err := asgsvc.SuspendProcesses(asg.Name, suspendedProcessesSlice); err != nil {
469-
return nil, errors.Wrapf(err, "failed to suspend processes while trying to create Pool")
466+
if _, err := asgsvc.CreateASG(machinePoolScope); err != nil {
467+
return errors.Wrapf(err, "failed to create AWSMachinePool")
470468
}
471-
return asg, nil
469+
470+
return nil
472471
}
473472

474473
func (r *AWSMachinePoolReconciler) findASG(machinePoolScope *scope.MachinePoolScope, asgsvc services.ASGInterface) (*expinfrav1.AutoScalingGroup, error) {

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)