From b33f86783fe466c3095a19cbe97c55875a667e27 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Wed, 1 May 2024 18:13:50 -0700 Subject: [PATCH] cloudapi: Add artifact cleanup to delete handler Related: RHEL-60120 --- internal/cloudapi/v2/errors.go | 2 ++ internal/cloudapi/v2/handler.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/internal/cloudapi/v2/errors.go b/internal/cloudapi/v2/errors.go index ea7ac0174..6d8796499 100644 --- a/internal/cloudapi/v2/errors.go +++ b/internal/cloudapi/v2/errors.go @@ -79,6 +79,7 @@ const ( ErrorGettingComposeList ServiceErrorCode = 1021 ErrorArtifactNotFound ServiceErrorCode = 1022 ErrorDeletingJob ServiceErrorCode = 1023 + ErrorDeletingArtifacts ServiceErrorCode = 1024 // Errors contained within this file ErrorUnspecified ServiceErrorCode = 10000 @@ -165,6 +166,7 @@ func getServiceErrors() serviceErrors { serviceError{ErrorTenantNotInContext, http.StatusInternalServerError, "Unable to retrieve tenant from request context"}, serviceError{ErrorGettingComposeList, http.StatusInternalServerError, "Unable to get list of composes"}, serviceError{ErrorDeletingJob, http.StatusInternalServerError, "Unable to delete job"}, + serviceError{ErrorDeletingArtifacts, http.StatusInternalServerError, "Unable to delete job artifacts"}, serviceError{ErrorUnspecified, http.StatusInternalServerError, "Unspecified internal error "}, serviceError{ErrorNotHTTPError, http.StatusInternalServerError, "Error is not an instance of HTTPError"}, diff --git a/internal/cloudapi/v2/handler.go b/internal/cloudapi/v2/handler.go index 76aa6dead..863f2e35c 100644 --- a/internal/cloudapi/v2/handler.go +++ b/internal/cloudapi/v2/handler.go @@ -345,6 +345,11 @@ func (h *apiHandlers) deleteComposeImpl(ctx echo.Context, jobId uuid.UUID) error return HTTPErrorWithInternal(ErrorDeletingJob, err) } + err = h.server.workers.CleanupArtifacts() + if err != nil { + return HTTPErrorWithInternal(ErrorDeletingArtifacts, err) + } + return ctx.JSON(http.StatusOK, ComposeDeleteStatus{ Href: fmt.Sprintf("/api/image-builder-composer/v2/composes/delete/%v", jobId), Id: jobId.String(),