Skip to content

Commit

Permalink
Update delete image flow (#558)
Browse files Browse the repository at this point in the history
Signed-off-by: Prajyot-Parab <[email protected]>
  • Loading branch information
Prajyot-Parab authored Feb 16, 2022
1 parent 3e35b89 commit 1573880
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cloud/scope/powervs_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions controllers/ibmpowervsimage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/cloud/services/powervs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1573880

Please sign in to comment.