From 5dffb9f59cccae963e0640f6b4d30a5336a731e9 Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Thu, 31 Mar 2022 17:34:43 +0100 Subject: [PATCH] cmd/worker: add empty manifest check Implement an error case for empty manifests in the osbuild jobs. This is already in place in the koji-osbuild job so this change introduces the same checks in case a job receives an empty manifest or a job has no manifest at all. --- cmd/osbuild-worker/jobimpl-osbuild.go | 31 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/cmd/osbuild-worker/jobimpl-osbuild.go b/cmd/osbuild-worker/jobimpl-osbuild.go index 6db4b4f18..18bc0fff5 100644 --- a/cmd/osbuild-worker/jobimpl-osbuild.go +++ b/cmd/osbuild-worker/jobimpl-osbuild.go @@ -112,20 +112,29 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { } // In case the manifest is empty, try to get it from dynamic args - if len(args.Manifest) == 0 && job.NDynamicArgs() > 0 { - var manifestJR worker.ManifestJobByIDResult - err = job.DynamicArgs(0, &manifestJR) - if err != nil { - osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args") - return err - } + if len(args.Manifest) == 0 { + if job.NDynamicArgs() > 0 { + var manifestJR worker.ManifestJobByIDResult + err = job.DynamicArgs(0, &manifestJR) + if err != nil { + osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args") + return err + } - // skip the job if the manifest generation failed - if manifestJR.JobError != nil { - osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorManifestDependency, "Manifest dependency failed") + // skip the job if the manifest generation failed + if manifestJR.JobError != nil { + osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorManifestDependency, "Manifest dependency failed") + return nil + } + args.Manifest = manifestJR.Manifest + if len(args.Manifest) == 0 { + osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorEmptyManifest, "Received empty manifest") + return nil + } + } else { + osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorEmptyManifest, "Job has no manifest") return nil } - args.Manifest = manifestJR.Manifest } // copy pipeline info to the result osbuildJobResult.PipelineNames = args.PipelineNames