Skip to content

Commit

Permalink
distro: remove PackageSets() from the ImageType interface
Browse files Browse the repository at this point in the history
Drop the PackageSets() function completely since it's no longer needed.
  • Loading branch information
achilleas-k committed May 17, 2023
1 parent 159d28b commit 395f41c
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 415 deletions.
5 changes: 0 additions & 5 deletions internal/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ type ImageType interface {
// has no partition table. Only support for RHEL 8.5+
PartitionType() string

// Returns the sets of packages to include and exclude when building the image.
// Indexed by a string label. How each set is labeled and used depends on the
// image type.
PackageSets(bp blueprint.Blueprint, options ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet

// Returns the names of the pipelines that set up the build environment (buildroot).
BuildPipelines() []string

Expand Down
99 changes: 0 additions & 99 deletions internal/distro/fedora/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import (
"github.com/osbuild/osbuild-composer/internal/image"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/oscap"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/workload"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
)

Expand Down Expand Up @@ -91,103 +89,6 @@ func (t *imageType) Size(size uint64) uint64 {
return size
}

func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
// merge package sets that appear in the image type with the package sets
// of the same name from the distro and arch
packageSets := make(map[string]rpmmd.PackageSet)

for name, getter := range t.packageSets {
packageSets[name] = getter(t)
}

// amend with repository information
for _, repo := range repos {
if len(repo.PackageSets) > 0 {
// only apply the repo to the listed package sets
for _, psName := range repo.PackageSets {
ps := packageSets[psName]
ps.Repositories = append(ps.Repositories, repo)
packageSets[psName] = ps
}
}
}

// For iot-commit and iot-container, we need to set an ImageRef if one
// isn't defined already in order to properly initialize the manifest and
// package selection.
if options.OSTree == nil {
options.OSTree = &ostree.ImageOptions{
ImageRef: t.OSTreeRef(),
}
}

// In case of Cloud API, this method is called before the ostree commit
// is resolved. Unfortunately, initializeManifest when called for
// an ostree installer returns an error.
//
// Work around this by providing a dummy FetchChecksum to convince the
// method that it's fine to initialize the manifest. Note that the ostree
// content has no effect on the package sets, so this is fine.
//
// See: https://github.com/osbuild/osbuild-composer/issues/3125
//
// TODO: Remove me when it's possible the get the package set chain without
// resolving the ostree reference before. Also remove the test for
// this workaround
if t.rpmOstree && t.bootISO && options.OSTree.FetchChecksum == "" {
options.OSTree.FetchChecksum = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
logrus.Warn("FIXME: Requesting package sets for iot-installer without a resolved ostree ref. Faking one.")
}

// create a temporary container spec array with the info from the blueprint
// to initialize the manifest
containers := make([]container.Spec, len(bp.Containers))
for idx := range bp.Containers {
containers[idx] = container.Spec{
Source: bp.Containers[idx].Source,
TLSVerify: bp.Containers[idx].TLSVerify,
LocalName: bp.Containers[idx].Name,
}
}

_, err := t.checkOptions(&bp, options)
if err != nil {
logrus.Errorf("Initializing the manifest failed for %s (%s/%s): %v", t.Name(), t.arch.distro.Name(), t.arch.Name(), err)
return nil
}

// TODO: let image types specify valid workloads, rather than
// always assume Custom.
w := &workload.Custom{
BaseWorkload: workload.BaseWorkload{
Repos: packageSets[blueprintPkgsKey].Repositories,
},
Packages: bp.GetPackagesEx(false),
}
if services := bp.Customizations.GetServices(); services != nil {
w.Services = services.Enabled
w.DisabledServices = services.Disabled
}

source := rand.NewSource(0)
// math/rand is good enough in this case
/* #nosec G404 */
rng := rand.New(source)

img, err := t.image(w, t, bp.Customizations, options, packageSets, nil, rng)
if err != nil {
logrus.Errorf("Initializing the manifest failed for %s (%s/%s): %v", t.Name(), t.arch.distro.Name(), t.arch.Name(), err)
return nil
}
manifest := manifest.New()
_, err = img.InstantiateManifest(&manifest, repos, t.arch.distro.runner, rng)
if err != nil {
logrus.Errorf("Initializing the manifest failed for %s (%s/%s): %v", t.Name(), t.arch.distro.Name(), t.arch.Name(), err)
return nil
}
return manifest.GetPackageSetChains()
}

func (t *imageType) BuildPipelines() []string {
return t.buildPipelines
}
Expand Down
82 changes: 0 additions & 82 deletions internal/distro/rhel7/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/workload"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
)

Expand Down Expand Up @@ -232,87 +231,6 @@ func (t *imageType) Manifest(bp *blueprint.Blueprint,
return &manifest, warnings, err
}

func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
// merge package sets that appear in the image type with the package sets
// of the same name from the distro and arch
packageSets := make(map[string]rpmmd.PackageSet)

for name, getter := range t.packageSets {
packageSets[name] = getter(t)
}

// amend with repository information
for _, repo := range repos {
if len(repo.PackageSets) > 0 {
// only apply the repo to the listed package sets
for _, psName := range repo.PackageSets {
ps := packageSets[psName]
ps.Repositories = append(ps.Repositories, repo)
packageSets[psName] = ps
}
}
}

// Similar to above, for edge-commit and edge-container, we need to set an
// ImageRef in order to properly initialize the manifest and package
// selection.
options.OSTree.ImageRef = t.OSTreeRef()

// create a temporary container spec array with the info from the blueprint
// to initialize the manifest
containers := make([]container.Spec, len(bp.Containers))
for idx := range bp.Containers {
containers[idx] = container.Spec{
Source: bp.Containers[idx].Source,
TLSVerify: bp.Containers[idx].TLSVerify,
LocalName: bp.Containers[idx].Name,
}
}

_, err := t.checkOptions(&bp, options)
if err != nil {
logrus.Errorf("Initializing the manifest failed for %s (%s/%s): %v", t.Name(), t.arch.distro.Name(), t.arch.Name(), err)
return nil
}

w := t.workload
if w == nil {
cw := &workload.Custom{
BaseWorkload: workload.BaseWorkload{
Repos: packageSets[blueprintPkgsKey].Repositories,
},
Packages: bp.GetPackagesEx(false),
}
if services := bp.Customizations.GetServices(); services != nil {
cw.Services = services.Enabled
cw.DisabledServices = services.Disabled
}
w = cw
}

source := rand.NewSource(0)
// math/rand is good enough in this case
/* #nosec G404 */
rng := rand.New(source)

if t.image == nil {
logrus.Errorf("Initializing the manifest failed for %s (%s/%s): %v", t.Name(), t.arch.distro.Name(), t.arch.Name(), err)
return nil
}
img, err := t.image(w, t, bp.Customizations, options, packageSets, nil, rng)
if err != nil {
logrus.Errorf("Initializing the manifest failed for %s (%s/%s): %v", t.Name(), t.arch.distro.Name(), t.arch.Name(), err)
return nil
}
manifest := manifest.New()
_, err = img.InstantiateManifest(&manifest, repos, t.arch.distro.runner, rng)
if err != nil {
logrus.Errorf("Initializing the manifest failed for %s (%s/%s): %v", t.Name(), t.arch.distro.Name(), t.arch.Name(), err)
return nil
}
return overridePackageNamesInSets(manifest.GetPackageSetChains())
}

// Runs overridePackageNames() on each package set's Include and Exclude list
// and replaces package names.
func overridePackageNamesInSets(chains map[string][]rpmmd.PackageSet) map[string][]rpmmd.PackageSet {
Expand Down
102 changes: 0 additions & 102 deletions internal/distro/rhel8/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"math/rand"
"strings"

"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"

"github.com/osbuild/osbuild-composer/internal/blueprint"
Expand All @@ -18,7 +17,6 @@ import (
"github.com/osbuild/osbuild-composer/internal/image"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/oscap"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
Expand Down Expand Up @@ -266,106 +264,6 @@ func (t *imageType) Manifest(bp *blueprint.Blueprint,
return &manifest, warnings, err
}

func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
// merge package sets that appear in the image type with the package sets
// of the same name from the distro and arch
packageSets := make(map[string]rpmmd.PackageSet)

for name, getter := range t.packageSets {
packageSets[name] = getter(t)
}

// amend with repository information
for _, repo := range repos {
if len(repo.PackageSets) > 0 {
// only apply the repo to the listed package sets
for _, psName := range repo.PackageSets {
ps := packageSets[psName]
ps.Repositories = append(ps.Repositories, repo)
packageSets[psName] = ps
}
}
}

// For edge-commit and edge-container, we need to set an ImageRef if one
// isn't defined already in order to properly initialize the manifest and
// package selection.
if options.OSTree == nil {
options.OSTree = &ostree.ImageOptions{
ImageRef: t.OSTreeRef(),
}
}

// In case of Cloud API, this method is called before the ostree commit
// is resolved. Unfortunately, initializeManifest when called for
// an ostree installer returns an error.
//
// Work around this by providing a dummy FetchChecksum to convince the
// method that it's fine to initialize the manifest. Note that the ostree
// content has no effect on the package sets, so this is fine.
//
// See: https://github.com/osbuild/osbuild-composer/issues/3125
//
// TODO: Remove me when it's possible the get the package set chain without
// resolving the ostree reference before. Also remove the test for
// this workaround
if t.rpmOstree && t.bootISO && options.OSTree.FetchChecksum == "" {
options.OSTree.FetchChecksum = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
logrus.Warn("FIXME: Requesting package sets for iot-installer without a resolved ostree ref. Faking one.")
}

// create a temporary container spec array with the info from the blueprint
// to initialize the manifest
containers := make([]container.Spec, len(bp.Containers))
for idx := range bp.Containers {
containers[idx] = container.Spec{
Source: bp.Containers[idx].Source,
TLSVerify: bp.Containers[idx].TLSVerify,
LocalName: bp.Containers[idx].Name,
}
}

_, err := t.checkOptions(&bp, options)
if err != nil {
logrus.Errorf("Initializing the manifest failed for %s (%s/%s): %v", t.Name(), t.arch.distro.Name(), t.arch.Name(), err)
return nil
}

w := t.workload
if w == nil {
cw := &workload.Custom{
BaseWorkload: workload.BaseWorkload{
Repos: packageSets[blueprintPkgsKey].Repositories,
},
Packages: bp.GetPackagesEx(false),
}
if services := bp.Customizations.GetServices(); services != nil {
cw.Services = services.Enabled
cw.DisabledServices = services.Disabled
}
w = cw
}

source := rand.NewSource(0)
// math/rand is good enough in this case
/* #nosec G404 */
rng := rand.New(source)

img, err := t.image(w, t, bp.Customizations, options, packageSets, nil, rng)
if err != nil {
logrus.Errorf("Initializing the manifest failed for %s (%s/%s): %v", t.Name(), t.arch.distro.Name(), t.arch.Name(), err)
return nil
}
manifest := manifest.New()
_, err = img.InstantiateManifest(&manifest, repos, t.arch.distro.runner, rng)
if err != nil {
logrus.Errorf("Initializing the manifest failed for %s (%s/%s): %v", t.Name(), t.arch.distro.Name(), t.arch.Name(), err)
return nil
}

return overridePackageNamesInSets(manifest.GetPackageSetChains())
}

// Runs overridePackageNames() on each package set's Include and Exclude list
// and replaces package names.
func overridePackageNamesInSets(chains map[string][]rpmmd.PackageSet) map[string][]rpmmd.PackageSet {
Expand Down
Loading

0 comments on commit 395f41c

Please sign in to comment.