From 0bf67dfad55b45af3444baf103b9b4cb69a57a8d Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Thu, 7 Apr 2022 17:01:36 +0200 Subject: [PATCH] Stop setting the `StreamOptimized` option in Weldr and Cloud APIs The VMDK image is already produced as stream-optimized. Therefore stop setting the `StreamOptimized` option in `OSBuildJob` structure by both, Weldr and Cloud APIs. Keep the handling of the option in worker for backward compatibility, in case an older instance of Composer server is used, which does not produce VMDK manifests as stream-optimized. In such case, the worker needs to convert the image. --- cmd/osbuild-worker/jobimpl-osbuild.go | 12 ++++++++++++ internal/cloudapi/v2/server.go | 5 ++--- internal/weldr/api.go | 9 ++++----- internal/worker/json.go | 15 +++++++++------ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/cmd/osbuild-worker/jobimpl-osbuild.go b/cmd/osbuild-worker/jobimpl-osbuild.go index f435de504..4de7f52dd 100644 --- a/cmd/osbuild-worker/jobimpl-osbuild.go +++ b/cmd/osbuild-worker/jobimpl-osbuild.go @@ -116,6 +116,7 @@ func validateResult(result *worker.OSBuildJobResult, jobID string) { func uploadToS3(a *awscloud.AWS, outputDirectory, exportPath, bucket, key, filename string, osbuildJobResult *worker.OSBuildJobResult, genericS3 bool, streamOptimized bool, streamOptimizedPath string) (err error) { imagePath := path.Join(outputDirectory, exportPath, filename) + // TODO: delete the stream-optimized handling after "some" time (kept for backward compatibility) // *** SPECIAL VMDK HANDLING START *** // Upload the VMDK image as stream-optimized. // The VMDK conversion is applied only when the job was submitted by Weldr API, @@ -294,6 +295,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { return nil } + // TODO: delete the stream-optimized handling after "some" time (kept for backward compatibility) streamOptimizedPath := "" // NOTE: Currently OSBuild supports multiple exports, but this isn't used @@ -303,6 +305,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { if osbuildJobResult.OSBuildOutput.Success && args.ImageName != "" { var f *os.File imagePath := path.Join(outputDirectory, exportPath, args.ImageName) + // TODO: delete the stream-optimized handling after "some" time (kept for backward compatibility) if args.StreamOptimized { f, err = vmware.OpenAsStreamOptimizedVmdk(imagePath) if err != nil { @@ -354,6 +357,15 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { // create a symlink so that uploaded image has the name specified by user imageName := args.Targets[0].ImageName + ".vmdk" imagePath := path.Join(tempDirectory, imageName) + + // New version of composer is already generating manifest with stream-optimized VMDK and is not setting + // the args.StreamOptimized option. In such case, the image itself is already stream optimized. + // Simulate the case as if it was converted by the worker. This makes it simpler to reuse the rest of + // the existing code below. + if !args.StreamOptimized { + streamOptimizedPath = path.Join(outputDirectory, exportPath, options.Filename) + } + err = os.Symlink(streamOptimizedPath, imagePath) if err != nil { osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error()) diff --git a/internal/cloudapi/v2/server.go b/internal/cloudapi/v2/server.go index d14cd0445..a948362c3 100644 --- a/internal/cloudapi/v2/server.go +++ b/internal/cloudapi/v2/server.go @@ -102,9 +102,8 @@ 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}, - Exports: ir.imageType.Exports(), - StreamOptimized: ir.imageType.Name() == "vmdk", // https://github.com/osbuild/osbuild/issues/528, + Targets: []*target.Target{ir.target}, + Exports: ir.imageType.Exports(), PipelineNames: &worker.PipelineNames{ Build: ir.imageType.BuildPipelines(), Payload: ir.imageType.PayloadPipelines(), diff --git a/internal/weldr/api.go b/internal/weldr/api.go index 6b8fae232..4ab0bdfa8 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -2347,11 +2347,10 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request var jobId uuid.UUID jobId, err = api.workers.EnqueueOSBuild(api.archName, &worker.OSBuildJob{ - Manifest: manifest, - Targets: targets, - ImageName: imageType.Filename(), - StreamOptimized: imageType.Name() == "vmdk", // https://github.com/osbuild/osbuild/issues/528 - Exports: imageType.Exports(), + Manifest: manifest, + Targets: targets, + ImageName: imageType.Filename(), + Exports: imageType.Exports(), PipelineNames: &worker.PipelineNames{ Build: imageType.BuildPipelines(), Payload: imageType.PayloadPipelines(), diff --git a/internal/worker/json.go b/internal/worker/json.go index 0adb29bd8..293d21c75 100644 --- a/internal/worker/json.go +++ b/internal/worker/json.go @@ -15,12 +15,15 @@ import ( // type OSBuildJob struct { - Manifest distro.Manifest `json:"manifest,omitempty"` - Targets []*target.Target `json:"targets,omitempty"` - ImageName string `json:"image_name,omitempty"` - StreamOptimized bool `json:"stream_optimized,omitempty"` - Exports []string `json:"export_stages,omitempty"` - PipelineNames *PipelineNames `json:"pipeline_names,omitempty"` + Manifest distro.Manifest `json:"manifest,omitempty"` + Targets []*target.Target `json:"targets,omitempty"` + ImageName string `json:"image_name,omitempty"` + + // TODO: Delete this after "some" time (kept for backward compatibility) + StreamOptimized bool `json:"stream_optimized,omitempty"` + + Exports []string `json:"export_stages,omitempty"` + PipelineNames *PipelineNames `json:"pipeline_names,omitempty"` } type JobResult struct {