From 576511a91b47290d8f217d746e35932c0212c439 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 16 Jan 2025 10:00:06 +0100 Subject: [PATCH] manifest: add `SerializeOptions` to `manifest.Serialize()` This commit makes `Serialize()` more extensible by switching the rpmDownloader option to a more general `SerializeOptions` struct that can be nil if no options are required. It contains the `RpmDownloader` as the only option right now. We could YAGNI it and do it once we have the second option but arguably it is cleaner already doing it now. --- cmd/build/main.go | 2 +- cmd/gen-manifests/main.go | 2 +- cmd/osbuild-playground/playground.go | 2 +- pkg/distro/distro_test.go | 2 +- pkg/image/bootc_disk_test.go | 2 +- pkg/image/installer_image_test.go | 2 +- pkg/manifest/manifest.go | 12 ++++++++++-- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/build/main.go b/cmd/build/main.go index 5ae02444e4..64dd39d937 100644 --- a/cmd/build/main.go +++ b/cmd/build/main.go @@ -81,7 +81,7 @@ func makeManifest( return nil, fmt.Errorf("[ERROR] ostree commit resolution failed: %w", err) } - mf, err := manifest.Serialize(depsolvedSets, containerSpecs, commitSpecs, 0) + mf, err := manifest.Serialize(depsolvedSets, containerSpecs, commitSpecs, nil) if err != nil { return nil, fmt.Errorf("[ERROR] manifest serialization failed: %w", err) } diff --git a/cmd/gen-manifests/main.go b/cmd/gen-manifests/main.go index 9e89d5b993..11a6e40843 100644 --- a/cmd/gen-manifests/main.go +++ b/cmd/gen-manifests/main.go @@ -249,7 +249,7 @@ func makeManifestJob( commitSpecs = mockResolveCommits(manifest.GetOSTreeSourceSpecs()) } - mf, err := manifest.Serialize(depsolvedSets, containerSpecs, commitSpecs, 0) + mf, err := manifest.Serialize(depsolvedSets, containerSpecs, commitSpecs, nil) if err != nil { return fmt.Errorf("[%s] manifest serialization failed: %s", filename, err.Error()) } diff --git a/cmd/osbuild-playground/playground.go b/cmd/osbuild-playground/playground.go index 5d15b39d9e..8b1d708c5a 100644 --- a/cmd/osbuild-playground/playground.go +++ b/cmd/osbuild-playground/playground.go @@ -49,7 +49,7 @@ func RunPlayground(img image.ImageKind, d distro.Distro, arch distro.Arch, repos fmt.Fprintf(os.Stderr, "could not clean dnf cache: %s", err.Error()) } - bytes, err := manifest.Serialize(depsolvedSets, nil, nil, 0) + bytes, err := manifest.Serialize(depsolvedSets, nil, nil, nil) if err != nil { panic("failed to serialize manifest: " + err.Error()) } diff --git a/pkg/distro/distro_test.go b/pkg/distro/distro_test.go index af580161be..32c57fc49a 100644 --- a/pkg/distro/distro_test.go +++ b/pkg/distro/distro_test.go @@ -136,7 +136,7 @@ func TestImageTypePipelineNames(t *testing.T) { } commits[name] = commitSpecs } - mf, err := m.Serialize(depsolvedSets, containers, commits, 0) + mf, err := m.Serialize(depsolvedSets, containers, commits, nil) assert.NoError(err) pm := new(manifest) err = json.Unmarshal(mf, pm) diff --git a/pkg/image/bootc_disk_test.go b/pkg/image/bootc_disk_test.go index a1796d7c72..61cb3d8d67 100644 --- a/pkg/image/bootc_disk_test.go +++ b/pkg/image/bootc_disk_test.go @@ -88,7 +88,7 @@ func makeBootcDiskImageOsbuildManifest(t *testing.T, opts *bootcDiskImageTestOpt "image": []container.Spec{{Source: "other-src", Digest: makeFakeDigest(t), ImageID: makeFakeDigest(t)}}, } - osbuildManifest, err := m.Serialize(nil, fakeSourceSpecs, nil, 0) + osbuildManifest, err := m.Serialize(nil, fakeSourceSpecs, nil, nil) require.Nil(t, err) return osbuildManifest diff --git a/pkg/image/installer_image_test.go b/pkg/image/installer_image_test.go index 99e9047a54..2b444f60db 100644 --- a/pkg/image/installer_image_test.go +++ b/pkg/image/installer_image_test.go @@ -372,7 +372,7 @@ func instantiateAndSerialize(t *testing.T, img image.ImageKind, depsolved map[st _, err := img.InstantiateManifest(&mf, nil, &runner.CentOS{Version: 9}, rng) assert.NoError(t, err) - mfs, err := mf.Serialize(depsolved, containers, commits, 0) + mfs, err := mf.Serialize(depsolved, containers, commits, nil) assert.NoError(t, err) return string(mfs) diff --git a/pkg/manifest/manifest.go b/pkg/manifest/manifest.go index 69674d4e6c..63b16bf759 100644 --- a/pkg/manifest/manifest.go +++ b/pkg/manifest/manifest.go @@ -141,7 +141,15 @@ func (m Manifest) GetOSTreeSourceSpecs() map[string][]ostree.SourceSpec { return ostreeSpecs } -func (m Manifest) Serialize(depsolvedSets map[string]dnfjson.DepsolveResult, containerSpecs map[string][]container.Spec, ostreeCommits map[string][]ostree.CommitSpec, rpmDownloader osbuild.RpmDownloader) (OSBuildManifest, error) { +type SerializeOptions struct { + RpmDownloader osbuild.RpmDownloader +} + +func (m Manifest) Serialize(depsolvedSets map[string]dnfjson.DepsolveResult, containerSpecs map[string][]container.Spec, ostreeCommits map[string][]ostree.CommitSpec, opts *SerializeOptions) (OSBuildManifest, error) { + if opts == nil { + opts = &SerializeOptions{} + } + for _, pipeline := range m.pipelines { pipeline.serializeStart(Inputs{ Depsolved: depsolvedSets[pipeline.Name()], @@ -165,7 +173,7 @@ func (m Manifest) Serialize(depsolvedSets map[string]dnfjson.DepsolveResult, con pipeline.serializeEnd() } - sources, err := osbuild.GenSources(mergedInputs, rpmDownloader) + sources, err := osbuild.GenSources(mergedInputs, opts.RpmDownloader) if err != nil { return nil, err }