diff --git a/cloud/scope/powervs_image.go b/cloud/scope/powervs_image.go index b86d977fb..c01cc9343 100644 --- a/cloud/scope/powervs_image.go +++ b/cloud/scope/powervs_image.go @@ -207,6 +207,10 @@ func (i *PowerVSImageScope) GetImportJob() (*models.Job, error) { return i.IBMPowerVSClient.GetCosImages(i.IBMPowerVSImage.Spec.ServiceInstanceID) } +func (i *PowerVSImageScope) DeleteImportJob() error { + return i.IBMPowerVSClient.DeleteJob(i.IBMPowerVSImage.Status.JobID) +} + func (i *PowerVSImageScope) SetReady() { i.IBMPowerVSImage.Status.Ready = true } diff --git a/controllers/ibmpowervsimage_controller.go b/controllers/ibmpowervsimage_controller.go index d44eecab2..25405127f 100644 --- a/controllers/ibmpowervsimage_controller.go +++ b/controllers/ibmpowervsimage_controller.go @@ -207,6 +207,14 @@ func (r *IBMPowerVSImageReconciler) reconcileDelete(scope *scope.PowerVSImageSco if scope.GetImageID() == "" { scope.Info("ImageID is not yet set, hence not invoking the powervs API to delete the image") + if scope.GetJobID() == "" { + scope.Info("JobID is not yet set, hence not invoking the powervs API to delete the image import job") + return ctrl.Result{}, nil + } + if err := scope.DeleteImportJob(); err != nil { + scope.Info("error deleting IBMPowerVSImage Import Job") + return ctrl.Result{}, errors.Wrapf(err, "error deleting IBMPowerVSImage Import Job") + } return ctrl.Result{}, nil } if err := scope.DeleteImage(); err != nil { diff --git a/pkg/cloud/services/powervs/service.go b/pkg/cloud/services/powervs/service.go index e25630de5..9535f5151 100644 --- a/pkg/cloud/services/powervs/service.go +++ b/pkg/cloud/services/powervs/service.go @@ -99,6 +99,11 @@ func (s *Service) GetJob(id string) (*models.Job, error) { return s.JobClient.Get(id) } +// DeleteJob deletes the image import job in the Power VS service instance. +func (s *Service) DeleteJob(id string) error { + return s.JobClient.Delete(id) +} + // GetAllNetwork returns all the networks in the Power VS service instance. func (s *Service) GetAllNetwork() (*models.Networks, error) { return s.NetworkClient.GetAll()