@@ -431,11 +431,14 @@ func (s *Service) DeleteInstance(eventObject runtime.Object, instanceStatus *Ins
431
431
}
432
432
433
433
// DeleteVolumes deletes any cinder volumes which were created for the instance.
434
- // Note that this must only be called when the server was not successfully
434
+ // Note that this need only be called when the server was not successfully
435
435
// created. If the server was created the volume will have been added with
436
436
// DeleteOnTermination=true, and will be automatically cleaned up with the
437
437
// server.
438
- func (s * Service ) DeleteVolumes (instanceSpec * InstanceSpec ) error {
438
+ // We don't pass InstanceSpec here because we only require instance name,
439
+ // rootVolume, and additionalBlockDevices, and resolving the whole InstanceSpec
440
+ // introduces unnecessary failure modes.
441
+ func (s * Service ) DeleteVolumes (instanceName string , rootVolume * infrav1.RootVolume , additionalBlockDevices []infrav1.AdditionalBlockDevice ) error {
439
442
/*
440
443
Attaching volumes to an instance is a two-step process:
441
444
@@ -455,13 +458,13 @@ func (s *Service) DeleteVolumes(instanceSpec *InstanceSpec) error {
455
458
DeleteOnTermination will ensure it is deleted in that case.
456
459
*/
457
460
458
- if hasRootVolume ( instanceSpec ) {
459
- if err := s .deleteVolume (instanceSpec . Name , "root" ); err != nil {
461
+ if rootVolume != nil && rootVolume . SizeGiB > 0 {
462
+ if err := s .deleteVolume (instanceName , "root" ); err != nil {
460
463
return err
461
464
}
462
465
}
463
- for _ , volumeSpec := range instanceSpec . AdditionalBlockDevices {
464
- if err := s .deleteVolume (instanceSpec . Name , volumeSpec .Name ); err != nil {
466
+ for _ , volumeSpec := range additionalBlockDevices {
467
+ if err := s .deleteVolume (instanceName , volumeSpec .Name ); err != nil {
465
468
return err
466
469
}
467
470
}
0 commit comments