@@ -431,11 +431,14 @@ func (s *Service) DeleteInstance(eventObject runtime.Object, instanceStatus *Ins
431431}
432432
433433// 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
435435// created. If the server was created the volume will have been added with
436436// DeleteOnTermination=true, and will be automatically cleaned up with the
437437// 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 {
439442 /*
440443 Attaching volumes to an instance is a two-step process:
441444
@@ -455,13 +458,13 @@ func (s *Service) DeleteVolumes(instanceSpec *InstanceSpec) error {
455458 DeleteOnTermination will ensure it is deleted in that case.
456459 */
457460
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 {
460463 return err
461464 }
462465 }
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 {
465468 return err
466469 }
467470 }
0 commit comments