Skip to content

Commit

Permalink
seedimage: clean-up service on image download deadline (#719)
Browse files Browse the repository at this point in the history
* seedimage: clean-up service on image download deadline

We used to just clean-up the Pod carrying the built image when hitting
the cleanupAfterMinutes deadline.
There is no need to leave the Service around, clean that up too.

Fixes #704

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>

* Update controllers/seedimage_controller.go

Co-authored-by: Fredrik Lönnegren <fredrik.lonnegren@gmail.com>
Signed-off-by: Francesco Giudici <francesco.giudici@gmail.com>

---------

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
Signed-off-by: Francesco Giudici <francesco.giudici@gmail.com>
Co-authored-by: Fredrik Lönnegren <fredrik.lonnegren@gmail.com>
(cherry picked from commit 5f2b96c)
  • Loading branch information
fgiudici authored and davidcassany committed Feb 18, 2025
1 parent ddb24ef commit c516b74
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion controllers/seedimage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,20 +868,36 @@ func (r *SeedImageReconciler) createBuildImageService(ctx context.Context, seedI
return err
}

seedImageDeadlinePassed := false
if seedImgCondition := meta.FindStatusCondition(seedImg.Status.Conditions, elementalv1.SeedImageConditionReady); seedImgCondition != nil &&
seedImgCondition.Status == metav1.ConditionTrue &&
seedImgCondition.Reason == elementalv1.SeedImageBuildDeadline {
seedImageDeadlinePassed = true
}

if err == nil {
logger.V(5).Info("Service already there")

// ensure the service was created by us
for _, owner := range foundSvc.GetOwnerReferences() {
if owner.UID == seedImg.UID {
// nothing to do
if seedImageDeadlinePassed {
logger.V(5).Info("Seed image deadline passed, delete associated service", "service", foundSvc.Name)
if err := r.Delete(ctx, foundSvc); err != nil {
return fmt.Errorf("failed to delete service %s: %w", foundSvc.Name, err)
}
}
return nil
}
}

return fmt.Errorf("service already exists and was not created by this controller")
}

if seedImageDeadlinePassed {
return nil
}

logger.V(5).Info("Creating service")

service := fillBuildImageService(seedImg.Name, seedImg.Namespace)
Expand Down

0 comments on commit c516b74

Please sign in to comment.