@@ -286,44 +286,30 @@ func (d *AWSDriver) Delete(machineID string) error {
286
286
metrics .APIRequestCount .With (prometheus.Labels {"provider" : "aws" , "service" : "ecs" }).Inc ()
287
287
288
288
if len (describeImageOutput .Images ) < 1 {
289
- klog .Errorf ("Image %s not found" , * imageID )
290
- return fmt .Errorf ("Image %s not found" , * imageID )
291
- }
292
-
293
- // returns instanceBlockDevices whose DeleteOnTermination field is nil on machineAPIs
294
- instanceBlkDeviceMappings , err := d .checkBlockDevices (instanceID , describeImageOutput .Images [0 ].RootDeviceName )
295
- if err != nil {
296
- klog .Errorf ("Could not Default deletionOnTermination while terminating machine: %s" , err .Error ())
297
- return err
298
- }
299
-
300
- // Default deletionOnTermination to true when unset on API field
301
- if len (instanceBlkDeviceMappings ) > 0 {
302
- input := & ec2.ModifyInstanceAttributeInput {
303
- InstanceId : aws .String (instanceID ),
304
- BlockDeviceMappings : instanceBlkDeviceMappings ,
305
- }
306
- _ , err = svc .ModifyInstanceAttribute (input )
289
+ // Disk image not found at provider
290
+ klog .Warningf ("Disk image %s not found at provider for machineID %q" , * imageID , machineID )
291
+ } else {
292
+ // returns instanceBlockDevices whose DeleteOnTermination field is nil on machineAPIs
293
+ instanceBlkDeviceMappings , err := d .checkBlockDevices (instanceID , describeImageOutput .Images [0 ].RootDeviceName )
307
294
if err != nil {
308
- if aerr , ok := err .(awserr.Error ); ok {
309
- switch aerr .Code () {
310
- case "InvalidInstanceAttributeValue" :
311
- // Case when disk is not yet attached to the VM
312
- klog .Warning (aerr .Error ())
313
- break
314
- default :
315
- klog .Error (aerr .Error ())
316
- metrics .APIFailedRequestCount .With (prometheus.Labels {"provider" : "aws" , "service" : "ecs" }).Inc ()
317
- return err
318
- }
319
- } else {
320
- klog .Error (err .Error ())
295
+ klog .Errorf ("Could not Default deletionOnTermination while terminating machine: %s" , err .Error ())
296
+ }
297
+
298
+ // Default deletionOnTermination to true when unset on API field
299
+ if err == nil && len (instanceBlkDeviceMappings ) > 0 {
300
+ input := & ec2.ModifyInstanceAttributeInput {
301
+ InstanceId : aws .String (instanceID ),
302
+ BlockDeviceMappings : instanceBlkDeviceMappings ,
303
+ }
304
+ _ , err = svc .ModifyInstanceAttribute (input )
305
+ if err != nil {
321
306
metrics .APIFailedRequestCount .With (prometheus.Labels {"provider" : "aws" , "service" : "ecs" }).Inc ()
322
- return err
307
+ klog .Warningf ("Couldn't complete modify instance with machineID %q. Error: %s. Continuing machine deletion" , machineID , err .Error ())
308
+ } else {
309
+ metrics .APIRequestCount .With (prometheus.Labels {"provider" : "aws" , "service" : "ecs" }).Inc ()
310
+ klog .V (2 ).Infof ("Successfully defaulted deletionOnTermination to true for disks (with nil pointer) for machineID: %q" , machineID )
323
311
}
324
312
}
325
- metrics .APIRequestCount .With (prometheus.Labels {"provider" : "aws" , "service" : "ecs" }).Inc ()
326
- klog .V (2 ).Infof ("Successfully defaulted deletionOnTermination to true for disks (with nil pointer) for instanceID: %q" , instanceID )
327
313
}
328
314
329
315
// Terminate instance call
0 commit comments