From 3d53ca5d8d2d3793c4ee82364d7053376c5b5bdc Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Mon, 4 Apr 2022 19:01:30 +0200 Subject: [PATCH] distro: deduplicate *kickstartStageOptions() Use single NewKickstartStageOptions() and replace image-type-specific implementation from each distro. - Followup from cb186df208d80074ff8db9e4cfa8bf42b5a3937d, copied to the rest of the RHEL distro definitions. NB: The change was not made in the Fedora distro definitions as they are currently being rewritten. --- internal/distro/rhel84/distro_v2.go | 32 ++++++++++----------- internal/distro/rhel85/pipelines.go | 11 +++++-- internal/distro/rhel85/stage_options.go | 20 ------------- internal/distro/rhel90beta/pipelines.go | 12 ++++++-- internal/distro/rhel90beta/stage_options.go | 21 -------------- 5 files changed, 35 insertions(+), 61 deletions(-) diff --git a/internal/distro/rhel84/distro_v2.go b/internal/distro/rhel84/distro_v2.go index 7692ca51a..f1d8439ad 100644 --- a/internal/distro/rhel84/distro_v2.go +++ b/internal/distro/rhel84/distro_v2.go @@ -14,6 +14,10 @@ import ( "github.com/osbuild/osbuild-composer/internal/rpmmd" ) +const ( + kspath = "/usr/share/anaconda/interactive-defaults.ks" +) + type imageTypeS2 struct { arch *architecture name string @@ -261,7 +265,11 @@ func (t *imageTypeS2) pipelines(customizations *blueprint.Customizations, option } // TODO: panic if not found kernelVer := fmt.Sprintf("%s-%s.%s", kernelPkg.Version, kernelPkg.Release, kernelPkg.Arch) - pipelines = append(pipelines, *t.anacondaTreePipeline(repos, packageSetSpecs["installer"], options, kernelVer)) + anacondaPipeline, err := t.anacondaTreePipeline(repos, packageSetSpecs["installer"], options, kernelVer) + if err != nil { + return nil, err + } + pipelines = append(pipelines, *anacondaPipeline) pipelines = append(pipelines, *t.bootISOTreePipeline(kernelVer)) pipelines = append(pipelines, *t.bootISOPipeline()) } else { @@ -431,7 +439,7 @@ func (t *imageTypeS2) containerPipeline() *osbuild.Pipeline { return p } -func (t *imageTypeS2) anacondaTreePipeline(repos []rpmmd.RepoConfig, packages []rpmmd.PackageSpec, options distro.ImageOptions, kernelVer string) *osbuild.Pipeline { +func (t *imageTypeS2) anacondaTreePipeline(repos []rpmmd.RepoConfig, packages []rpmmd.PackageSpec, options distro.ImageOptions, kernelVer string) (*osbuild.Pipeline, error) { ostreeRepoPath := "/ostree/repo" p := new(osbuild.Pipeline) p.Name = "anaconda-tree" @@ -473,9 +481,13 @@ func (t *imageTypeS2) anacondaTreePipeline(repos []rpmmd.RepoConfig, packages [] p.AddStage(osbuild.NewAnacondaStage(t.anacondaStageOptions())) p.AddStage(osbuild.NewLoraxScriptStage(t.loraxScriptStageOptions())) p.AddStage(osbuild.NewDracutStage(t.dracutStageOptions(kernelVer))) - p.AddStage(osbuild.NewKickstartStage(t.kickstartStageOptions(fmt.Sprintf("file://%s", ostreeRepoPath), options.OSTree.Ref))) + kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", nil, nil, fmt.Sprintf("file://%s", ostreeRepoPath), options.OSTree.Ref) + if err != nil { + return nil, err + } + p.AddStage(osbuild.NewKickstartStage(kickstartOptions)) - return p + return p, nil } func (t *imageTypeS2) bootISOTreePipeline(kernelVer string) *osbuild.Pipeline { @@ -665,18 +677,6 @@ func (t *imageTypeS2) dracutStageOptions(kernelVer string) *osbuild.DracutStageO } } -func (t *imageTypeS2) kickstartStageOptions(ostreeURL, ostreeRef string) *osbuild.KickstartStageOptions { - return &osbuild.KickstartStageOptions{ - Path: "/usr/share/anaconda/interactive-defaults.ks", - OSTree: &osbuild.OSTreeOptions{ - OSName: "rhel", - URL: ostreeURL, - Ref: ostreeRef, - GPG: false, - }, - } -} - func (t *imageTypeS2) bootISOMonoStageOptions(kernelVer string) *osbuild.BootISOMonoStageOptions { return &osbuild.BootISOMonoStageOptions{ Product: osbuild.Product{ diff --git a/internal/distro/rhel85/pipelines.go b/internal/distro/rhel85/pipelines.go index 997703249..6d77af048 100644 --- a/internal/distro/rhel85/pipelines.go +++ b/internal/distro/rhel85/pipelines.go @@ -493,7 +493,10 @@ func edgeInstallerPipelines(t *imageType, customizations *blueprint.Customizatio kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(installerPackages, "kernel") ostreeRepoPath := "/ostree/repo" payloadStages := ostreePayloadStages(options, ostreeRepoPath) - kickstartOptions := ostreeKickstartStageOptions(makeISORootPath(ostreeRepoPath), options.OSTree.Ref) + kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", nil, nil, makeISORootPath(ostreeRepoPath), options.OSTree.Ref) + if err != nil { + return nil, err + } pipelines = append(pipelines, *anacondaTreePipeline(repos, installerPackages, kernelVer, t.Arch().Name())) pipelines = append(pipelines, *bootISOTreePipeline(kernelVer, t.Arch().Name(), kickstartOptions, payloadStages)) pipelines = append(pipelines, *bootISOPipeline(t.Filename(), t.Arch().Name(), false)) @@ -528,7 +531,11 @@ func tarInstallerPipelines(t *imageType, customizations *blueprint.Customization tarPath := "/liveimg.tar" tarPayloadStages := []*osbuild.Stage{tarStage("os", tarPath)} - kickstartOptions := tarKickstartStageOptions(makeISORootPath(tarPath)) + kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, makeISORootPath(tarPath), nil, nil, "", "") + if err != nil { + return nil, err + } + pipelines = append(pipelines, *anacondaTreePipeline(repos, installerPackages, kernelVer, t.Arch().Name())) pipelines = append(pipelines, *bootISOTreePipeline(kernelVer, t.Arch().Name(), kickstartOptions, tarPayloadStages)) pipelines = append(pipelines, *bootISOPipeline(t.Filename(), t.Arch().Name(), true)) diff --git a/internal/distro/rhel85/stage_options.go b/internal/distro/rhel85/stage_options.go index 204f3904f..d1f792f9b 100644 --- a/internal/distro/rhel85/stage_options.go +++ b/internal/distro/rhel85/stage_options.go @@ -168,26 +168,6 @@ func dracutStageOptions(kernelVer, arch string, additionalModules []string) *osb } } -func tarKickstartStageOptions(tarURL string) *osbuild.KickstartStageOptions { - return &osbuild.KickstartStageOptions{ - Path: kspath, - LiveIMG: &osbuild.LiveIMG{ - URL: tarURL, - }, - } -} - -func ostreeKickstartStageOptions(ostreeURL, ostreeRef string) *osbuild.KickstartStageOptions { - return &osbuild.KickstartStageOptions{ - Path: kspath, - OSTree: &osbuild.OSTreeOptions{ - OSName: "rhel", - URL: ostreeURL, - Ref: ostreeRef, - GPG: false, - }, - } -} func bootISOMonoStageOptions(kernelVer string, arch string) *osbuild.BootISOMonoStageOptions { comprOptions := new(osbuild.FSCompressionOptions) if bcj := osbuild.BCJOption(arch); bcj != "" { diff --git a/internal/distro/rhel90beta/pipelines.go b/internal/distro/rhel90beta/pipelines.go index f8ee7429c..2b8fcbc76 100644 --- a/internal/distro/rhel90beta/pipelines.go +++ b/internal/distro/rhel90beta/pipelines.go @@ -625,7 +625,11 @@ func edgeInstallerPipelines(t *imageType, customizations *blueprint.Customizatio kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(installerPackages, "kernel") ostreeRepoPath := "/ostree/repo" pipelines = append(pipelines, *anacondaTreePipeline(repos, installerPackages, kernelVer, t.Arch().Name(), ostreePayloadStages(options, ostreeRepoPath))) - pipelines = append(pipelines, *bootISOTreePipeline(kernelVer, t.Arch().Name(), ostreeKickstartStageOptions(fmt.Sprintf("file://%s", ostreeRepoPath), options.OSTree.Ref))) + kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", nil, nil, fmt.Sprintf("file://%s", ostreeRepoPath), options.OSTree.Ref) + if err != nil { + return nil, err + } + pipelines = append(pipelines, *bootISOTreePipeline(kernelVer, t.Arch().Name(), kickstartOptions)) pipelines = append(pipelines, *bootISOPipeline(t.Filename(), t.Arch().Name())) return pipelines, nil } @@ -659,7 +663,11 @@ func tarInstallerPipelines(t *imageType, customizations *blueprint.Customization tarPath := "/liveimg.tar" tarPayloadStages := []*osbuild.Stage{tarStage("os", tarPath)} pipelines = append(pipelines, *anacondaTreePipeline(repos, installerPackages, kernelVer, t.Arch().Name(), tarPayloadStages)) - pipelines = append(pipelines, *bootISOTreePipeline(kernelVer, t.Arch().Name(), tarKickstartStageOptions(fmt.Sprintf("file://%s", tarPath)))) + kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, fmt.Sprintf("file://%s", tarPath), nil, nil, "", "") + if err != nil { + return nil, err + } + pipelines = append(pipelines, *bootISOTreePipeline(kernelVer, t.Arch().Name(), kickstartOptions)) pipelines = append(pipelines, *bootISOPipeline(t.Filename(), t.Arch().Name())) return pipelines, nil } diff --git a/internal/distro/rhel90beta/stage_options.go b/internal/distro/rhel90beta/stage_options.go index 6bd3b8c45..d881b97b5 100644 --- a/internal/distro/rhel90beta/stage_options.go +++ b/internal/distro/rhel90beta/stage_options.go @@ -161,27 +161,6 @@ func dracutStageOptions(kernelVer string) *osbuild.DracutStageOptions { } } -func tarKickstartStageOptions(tarURL string) *osbuild.KickstartStageOptions { - return &osbuild.KickstartStageOptions{ - Path: kspath, - LiveIMG: &osbuild.LiveIMG{ - URL: tarURL, - }, - } -} - -func ostreeKickstartStageOptions(ostreeURL, ostreeRef string) *osbuild.KickstartStageOptions { - return &osbuild.KickstartStageOptions{ - Path: kspath, - OSTree: &osbuild.OSTreeOptions{ - OSName: "rhel", - URL: ostreeURL, - Ref: ostreeRef, - GPG: false, - }, - } -} - func bootISOMonoStageOptions(kernelVer string, arch string) *osbuild.BootISOMonoStageOptions { comprOptions := new(osbuild.FSCompressionOptions) if bcj := osbuild.BCJOption(arch); bcj != "" {