From d7ab1f21126f418d961f64a3484e7eca843584fb Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Mon, 23 Oct 2023 18:51:43 +0200 Subject: [PATCH] cloudapi: multiple upload targets in request Add an array of targets in the imageRequest and return an array from ImageRequest.GetTargets() (renamed from GetTarget()). Currently, the function still only returns one target, the default for the image type with the top level upload options. --- internal/cloudapi/v2/handler.go | 17 +++++++++-------- internal/cloudapi/v2/imagerequest.go | 7 ++++--- internal/cloudapi/v2/server.go | 8 ++++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/internal/cloudapi/v2/handler.go b/internal/cloudapi/v2/handler.go index eb368f07e..3865a78c7 100644 --- a/internal/cloudapi/v2/handler.go +++ b/internal/cloudapi/v2/handler.go @@ -139,7 +139,7 @@ type imageRequest struct { arch distro.Arch repositories []rpmmd.RepoConfig imageOptions distro.ImageOptions - target *target.Target + targets []*target.Target } func (h *apiHandlers) PostCompose(ctx echo.Context) error { @@ -236,7 +236,7 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error { return err } - var irTarget *target.Target + var irTargets []*target.Target if ir.UploadOptions == nil { // nowhere to put the image, this is a user error if request.Koji == nil { @@ -245,13 +245,14 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error { } else if localSave { // Override the image type upload selection and save it locally // Final image is in /var/lib/osbuild-composer/artifacts/UUID/ - irTarget = target.NewWorkerServerTarget() - irTarget.ImageName = imageType.Filename() - irTarget.OsbuildArtifact.ExportFilename = imageType.Filename() - irTarget.OsbuildArtifact.ExportName = imageType.Exports()[0] + srvTarget := target.NewWorkerServerTarget() + srvTarget.ImageName = imageType.Filename() + srvTarget.OsbuildArtifact.ExportFilename = imageType.Filename() + srvTarget.OsbuildArtifact.ExportName = imageType.Exports()[0] + irTargets = []*target.Target{srvTarget} } else { // Get the target for the selected image type - irTarget, err = ir.GetTarget(&request, imageType) + irTargets, err = ir.GetTargets(&request, imageType) if err != nil { return err } @@ -262,7 +263,7 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error { arch: arch, repositories: repos, imageOptions: imageOptions, - target: irTarget, + targets: irTargets, }) } diff --git a/internal/cloudapi/v2/imagerequest.go b/internal/cloudapi/v2/imagerequest.go index e5a695940..024d409c6 100644 --- a/internal/cloudapi/v2/imagerequest.go +++ b/internal/cloudapi/v2/imagerequest.go @@ -283,8 +283,9 @@ func getDefaultTarget(imageType ImageTypes) (UploadTypes, error) { } } -// GetTarget returns the target for the selected image type. -func (ir *ImageRequest) GetTarget(request *ComposeRequest, imageType distro.ImageType) (irTarget *target.Target, err error) { +// GetTargets returns all the targets for image request. +func (ir *ImageRequest) GetTargets(request *ComposeRequest, imageType distro.ImageType) ([]*target.Target, error) { + var irTarget *target.Target uploadTarget, err := getDefaultTarget(ir.ImageType) if err != nil { return nil, err @@ -316,7 +317,7 @@ func (ir *ImageRequest) GetTarget(request *ComposeRequest, imageType distro.Imag } irTarget.OsbuildArtifact.ExportName = imageType.Exports()[0] - return irTarget, nil + return []*target.Target{irTarget}, nil } // GetOSTreeOptions returns the image ostree options when included in the request diff --git a/internal/cloudapi/v2/server.go b/internal/cloudapi/v2/server.go index 942fd4667..22644412c 100644 --- a/internal/cloudapi/v2/server.go +++ b/internal/cloudapi/v2/server.go @@ -203,7 +203,7 @@ func (s *Server) enqueueCompose(distribution distro.Distro, bp blueprint.Bluepri } id, err = s.workers.EnqueueOSBuildAsDependency(ir.arch.Name(), &worker.OSBuildJob{ - Targets: []*target.Target{ir.target}, + Targets: ir.targets, PipelineNames: &worker.PipelineNames{ Build: ir.imageType.BuildPipelines(), Payload: ir.imageType.PayloadPipelines(), @@ -341,9 +341,9 @@ func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, releas kojiTarget.ImageName = kojiFilename targets := []*target.Target{kojiTarget} - // add any cloud upload target if defined - if ir.target != nil { - targets = append(targets, ir.target) + // add any cloud upload targets if defined + if ir.targets != nil { + targets = append(targets, ir.targets...) } buildID, err := s.workers.EnqueueOSBuildAsDependency(ir.arch.Name(), &worker.OSBuildJob{