From 28ef0bc8554d4ca4639ffe09b5b44d6a46c6f521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Fri, 16 Feb 2024 14:28:27 +0100 Subject: [PATCH] cloudapi: move manifest seed into an image request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The goal of this commit is primarily to simplify the API of the enqueue methods. This way, basically everything needed to generate manifests is in the imageRequest structure, which simplifies the amount of structures that we need to think about. Signed-off-by: Ondřej Budai --- internal/cloudapi/v2/handler.go | 6 ++++-- internal/cloudapi/v2/server.go | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/cloudapi/v2/handler.go b/internal/cloudapi/v2/handler.go index 05d61f6ea..b25b8eb16 100644 --- a/internal/cloudapi/v2/handler.go +++ b/internal/cloudapi/v2/handler.go @@ -141,6 +141,7 @@ type imageRequest struct { imageOptions distro.ImageOptions targets []*target.Target blueprint blueprint.Blueprint + manifestSeed int64 } func (h *apiHandlers) PostCompose(ctx echo.Context) error { @@ -271,17 +272,18 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error { imageOptions: imageOptions, targets: irTargets, blueprint: bp, + manifestSeed: manifestSeed, }) } var id uuid.UUID if request.Koji != nil { - id, err = h.server.enqueueKojiCompose(uint64(request.Koji.TaskId), request.Koji.Server, request.Koji.Name, request.Koji.Version, request.Koji.Release, manifestSeed, irs, channel) + id, err = h.server.enqueueKojiCompose(uint64(request.Koji.TaskId), request.Koji.Server, request.Koji.Name, request.Koji.Version, request.Koji.Release, irs, channel) if err != nil { return err } } else { - id, err = h.server.enqueueCompose(manifestSeed, irs, channel) + id, err = h.server.enqueueCompose(irs, channel) if err != nil { return err } diff --git a/internal/cloudapi/v2/server.go b/internal/cloudapi/v2/server.go index 9c07ecce8..2d5197345 100644 --- a/internal/cloudapi/v2/server.go +++ b/internal/cloudapi/v2/server.go @@ -117,7 +117,7 @@ func (s *Server) Shutdown() { s.goroutinesGroup.Wait() } -func (s *Server) enqueueCompose(manifestSeed int64, irs []imageRequest, channel string) (uuid.UUID, error) { +func (s *Server) enqueueCompose(irs []imageRequest, channel string) (uuid.UUID, error) { var id uuid.UUID if len(irs) != 1 { return id, HTTPError(ErrorInvalidNumberOfImageBuilds) @@ -129,7 +129,7 @@ func (s *Server) enqueueCompose(manifestSeed int64, irs []imageRequest, channel arch := ir.imageType.Arch() distribution := arch.Distro() - manifestSource, _, err := ir.imageType.Manifest(&ibp, ir.imageOptions, ir.repositories, manifestSeed) + manifestSource, _, err := ir.imageType.Manifest(&ibp, ir.imageOptions, ir.repositories, ir.manifestSeed) if err != nil { logrus.Warningf("ErrorEnqueueingJob, failed generating manifest: %v", err) return id, HTTPErrorWithInternal(ErrorEnqueueingJob, err) @@ -226,14 +226,14 @@ func (s *Server) enqueueCompose(manifestSeed int64, irs []imageRequest, channel s.goroutinesGroup.Add(1) go func() { - serializeManifest(s.goroutinesCtx, manifestSource, s.workers, depsolveJobID, containerResolveJobID, ostreeResolveJobID, manifestJobID, manifestSeed) + serializeManifest(s.goroutinesCtx, manifestSource, s.workers, depsolveJobID, containerResolveJobID, ostreeResolveJobID, manifestJobID, ir.manifestSeed) defer s.goroutinesGroup.Done() }() return id, nil } -func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, release string, manifestSeed int64, irs []imageRequest, channel string) (uuid.UUID, error) { +func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, release string, irs []imageRequest, channel string) (uuid.UUID, error) { var id uuid.UUID kojiDirectory := "osbuild-cg/osbuild-composer-koji-" + uuid.New().String() @@ -256,7 +256,7 @@ func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, releas arch := ir.imageType.Arch() distribution := arch.Distro() - manifestSource, _, err := ir.imageType.Manifest(&ibp, ir.imageOptions, ir.repositories, manifestSeed) + manifestSource, _, err := ir.imageType.Manifest(&ibp, ir.imageOptions, ir.repositories, ir.manifestSeed) if err != nil { logrus.Errorf("ErrorEnqueueingJob, failed generating manifest: %v", err) return id, HTTPErrorWithInternal(ErrorEnqueueingJob, err) @@ -380,7 +380,7 @@ func (s *Server) enqueueKojiCompose(taskID uint64, server, name, version, releas // copy the image request while passing it into the goroutine to prevent data races s.goroutinesGroup.Add(1) go func(ir imageRequest) { - serializeManifest(s.goroutinesCtx, manifestSource, s.workers, depsolveJobID, containerResolveJobID, ostreeResolveJobID, manifestJobID, manifestSeed) + serializeManifest(s.goroutinesCtx, manifestSource, s.workers, depsolveJobID, containerResolveJobID, ostreeResolveJobID, manifestJobID, ir.manifestSeed) defer s.goroutinesGroup.Done() }(ir) }