worker/osbuild: handle manifest dynamic argument index

Previously, the `OSBuild` job assumed that it can have only a single
job dependency, which could be only the `ManifestJobByID`. This won't
work well for the Koji use case, because the Koji OSBuild job has also
dependency on the Koji-init job.

Extend the `worker.OSBuildJob` structure with a new field, which holds
the `ManifestJobByIDResult` index in the job's dynamic arguments slice.
This value is considered in case when there is more than one dependency
of the `OSBuild` job.
This commit is contained in:
Tomas Hozza 2022-05-12 17:41:47 +02:00 committed by Tom Gundersen
parent a4e6531565
commit 97da1e7ad6
2 changed files with 19 additions and 9 deletions

View file

@ -281,7 +281,17 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
if len(args.Manifest) == 0 {
if job.NDynamicArgs() > 0 {
var manifestJR worker.ManifestJobByIDResult
err = job.DynamicArgs(0, &manifestJR)
if job.NDynamicArgs() == 1 {
// Classic case of a compose request with the ManifestJobByID job as the single dependency
err = job.DynamicArgs(0, &manifestJR)
} else if job.NDynamicArgs() > 1 && args.ManifestDynArgsIdx != nil {
// Case when the job has multiple dependencies, but the manifest is not part of the static job arguments,
// but rather in the dynamic arguments (e.g. from ManifestJobByID job).
if *args.ManifestDynArgsIdx > job.NDynamicArgs()-1 {
panic("ManifestDynArgsIdx is out of range of the number of dynamic job arguments")
}
err = job.DynamicArgs(*args.ManifestDynArgsIdx, &manifestJR)
}
if err != nil {
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorParsingDynamicArgs, "Error parsing dynamic args")
return err
@ -293,11 +303,9 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
return nil
}
args.Manifest = manifestJR.Manifest
if len(args.Manifest) == 0 {
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorEmptyManifest, "Received empty manifest")
return nil
}
} else {
}
if len(args.Manifest) == 0 {
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorEmptyManifest, "Job has no manifest")
return nil
}

View file

@ -16,9 +16,11 @@ import (
//
type OSBuildJob struct {
Manifest distro.Manifest `json:"manifest,omitempty"`
Targets []*target.Target `json:"targets,omitempty"`
ImageName string `json:"image_name,omitempty"`
Manifest distro.Manifest `json:"manifest,omitempty"`
// Index of the ManifestJobByIDResult instance in the job's dynamic arguments slice
ManifestDynArgsIdx *int `json:"manifest_dyn_args_idx,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"`