@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"encoding/json"
22
22
"fmt"
23
+ "time"
23
24
24
25
"github.com/aws/aws-sdk-go/aws"
25
26
ignTypes "github.com/flatcar/ignition/config/v2_3/types"
@@ -340,8 +341,14 @@ func (r *AWSMachineReconciler) reconcileDelete(machineScope *scope.MachineScope,
340
341
// This decision is based on the ec2-instance-lifecycle graph at
341
342
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-lifecycle.html
342
343
switch instance .State {
343
- case infrav1 .InstanceStateShuttingDown , infrav1 . InstanceStateTerminated :
344
+ case infrav1 .InstanceStateShuttingDown :
344
345
machineScope .Info ("EC2 instance is shutting down or already terminated" , "instance-id" , instance .ID )
346
+ // requeue reconciliation until we observe termination (or the instance can no longer be looked up)
347
+ return ctrl.Result {RequeueAfter : time .Minute }, nil
348
+ case infrav1 .InstanceStateTerminated :
349
+ machineScope .Info ("EC2 instance terminated successfully" , "instance-id" , instance .ID )
350
+ controllerutil .RemoveFinalizer (machineScope .AWSMachine , infrav1 .MachineFinalizer )
351
+ return ctrl.Result {}, nil
345
352
default :
346
353
machineScope .Info ("Terminating EC2 instance" , "instance-id" , instance .ID )
347
354
@@ -391,12 +398,10 @@ func (r *AWSMachineReconciler) reconcileDelete(machineScope *scope.MachineScope,
391
398
392
399
machineScope .Info ("EC2 instance successfully terminated" , "instance-id" , instance .ID )
393
400
r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeNormal , "SuccessfulTerminate" , "Terminated instance %q" , instance .ID )
394
- }
395
401
396
- // Instance is deleted so remove the finalizer.
397
- controllerutil .RemoveFinalizer (machineScope .AWSMachine , infrav1 .MachineFinalizer )
398
-
399
- return ctrl.Result {}, nil
402
+ // requeue reconciliation until we observe termination (or the instance can no longer be looked up)
403
+ return ctrl.Result {RequeueAfter : time .Minute }, nil
404
+ }
400
405
}
401
406
402
407
// findInstance queries the EC2 apis and retrieves the instance if it exists.
0 commit comments