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