Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func run() error {
os.Exit(1)
}

distroFac := distrofactory.NewDefault()
distroFac := distrofactory.NewDefault("")
config, err := buildconfig.New(configFile, nil)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/gen-manifests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func main() {
panic(fmt.Sprintf("failed to create repo registry with tested distros: %v", err))
}

distroFac := distrofactory.NewDefault()
distroFac := distrofactory.NewDefault("")
jobs := make([]manifestJob, 0)

contentResolve := map[string]bool{
Expand Down
2 changes: 1 addition & 1 deletion cmd/list-images/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func main() {
if err != nil {
panic(fmt.Sprintf("failed to create repo registry with tested distros: %v", err))
}
distroFac := distrofactory.NewDefault()
distroFac := distrofactory.NewDefault("")
distros, invalidDistros := resolveArgValues(distros, testedRepoRegistry.ListDistros())
if len(invalidDistros) > 0 {
fmt.Fprintf(os.Stderr, "WARNING: invalid distro names: [%s]\n", strings.Join(invalidDistros, ","))
Expand Down
2 changes: 1 addition & 1 deletion cmd/osbuild-playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {
}
}

distroFac := distrofactory.NewDefault()
distroFac := distrofactory.NewDefault("")
var d distro.Distro
if distroArg == "host" {
d = distroFac.FromHost()
Expand Down
11 changes: 6 additions & 5 deletions pkg/distro/bootc/bootc.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,14 +605,14 @@ func NewBootcDistro(imgref string, opts *DistroOptions) (*BootcDistro, error) {
// if no direct match can be found it will it will use the ID_LIKE.
// This should ensure we work on every bootc image that puts a correct
// ID_LIKE= in /etc/os-release
func newDistroYAMLFrom(sourceInfo *osinfo.Info) (*defs.DistroYAML, *distro.ID, error) {
func newDistroYAMLFrom(defsDir string, sourceInfo *osinfo.Info) (*defs.DistroYAML, *distro.ID, error) {
for _, distroID := range append([]string{sourceInfo.OSRelease.ID}, sourceInfo.OSRelease.IDLike...) {
nameVer := fmt.Sprintf("%s-%s", distroID, sourceInfo.OSRelease.VersionID)
id, err := distro.ParseID(nameVer)
if err != nil {
return nil, nil, err
}
distroYAML, err := defs.NewDistroYAML(nameVer)
distroYAML, err := defs.NewDistroYAML(defsDir, nameVer)
if err != nil {
return nil, nil, err
}
Expand All @@ -631,7 +631,8 @@ func (t *BootcImageType) manifestForLegacyISO(bp *blueprint.Blueprint, options d
if t.arch.distro.imgref == "" {
return nil, nil, fmt.Errorf("pipeline: no base image defined")
}
distroYAML, id, err := newDistroYAMLFrom(t.arch.distro.sourceInfo)
// XXX defsdir?
distroYAML, id, err := newDistroYAMLFrom("", t.arch.distro.sourceInfo)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -766,7 +767,7 @@ func newBootcDistroAfterIntrospect(archStr string, info *osinfo.Info, imgref, de
arch: archi,
}

distroYAML, err := defs.LoadDistroWithoutImageTypes("bootc-generic-1")
distroYAML, err := defs.LoadDistroWithoutImageTypes("", "bootc-generic-1")
if err != nil {
return nil, err
}
Expand All @@ -793,7 +794,7 @@ func newBootcDistroAfterIntrospect(archStr string, info *osinfo.Info, imgref, de
// anything but tests.
var NewBootcDistroForTesting = newBootcDistroAfterIntrospect

func DistroFactory(idStr string) distro.Distro {
func DistroFactory(defsDir string, idStr string) distro.Distro {
l := strings.SplitN(idStr, ":", 2)
if l[0] != "bootc" {
return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/distro/defs/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func matchAndNormalize(reStr, nameVer string) (string, error) {
//
// If no match is found it will "nil" and no error (
func ParseID(nameVer string) (*distro.ID, error) {
distros, err := loadDistros()
// XXX defsDir?
distros, err := loadDistros("")
if err != nil {
return nil, err
}
Expand Down
25 changes: 16 additions & 9 deletions pkg/distro/defs/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ var (
// this can be overriden in tests
var defaultDataFS fs.FS = distrodefs.Data

func dataFS() fs.FS {
func dataFS(defsDir string) fs.FS {
// XXX: this is a short term measure, pass a set of
// searchPaths down the stack instead
dataFS := defaultDataFS
if defsDir != "" {
dataFS = os.DirFS(defsDir)
}
if overrideDir := experimentalflags.String("yamldir"); overrideDir != "" {
olog.Printf("WARNING: using experimental override dir %q", overrideDir)
dataFS = os.DirFS(overrideDir)
Expand Down Expand Up @@ -110,6 +113,8 @@ type DistroYAML struct {

// set by the loader
ID distro.ID

defsRoot string
}

func (d *DistroYAML) ImageTypes() map[string]ImageTypeYAML {
Expand Down Expand Up @@ -166,16 +171,16 @@ func (d *DistroYAML) runTemplates(id distro.ID) error {
// are appended together.
// Note that files are read separately from each other, so anchors and other
// references can only be done within the same file.
func loadDistros() (*distrosYAML, error) {
dents, err := fs.Glob(dataFS(), "*.yaml")
func loadDistros(defsDir string) (*distrosYAML, error) {
dents, err := fs.Glob(dataFS(defsDir), "*.yaml")
if err != nil {
return nil, err
}

var allDistros distrosYAML

for _, name := range dents {
f, err := dataFS().Open(name)
f, err := dataFS(defsDir).Open(name)
if err != nil {
return nil, err
}
Expand All @@ -202,23 +207,25 @@ func loadDistros() (*distrosYAML, error) {
// that returns all known distros but for now we keep compatibility
// with the way distrofactory/reporegistry work which is by defining
// distros via repository files.
func NewDistroYAML(nameVer string) (*DistroYAML, error) {
foundDistro, err := LoadDistroWithoutImageTypes(nameVer)
func NewDistroYAML(defsDir string, nameVer string) (*DistroYAML, error) {
foundDistro, err := LoadDistroWithoutImageTypes(defsDir, nameVer)
if err != nil {
return nil, err
}
if foundDistro == nil {
return nil, nil
}

foundDistro.defsRoot = defsDir

if err := foundDistro.LoadImageTypes(); err != nil {
return nil, err
}
return foundDistro, nil
}

func LoadDistroWithoutImageTypes(nameVer string) (*DistroYAML, error) {
distros, err := loadDistros()
func LoadDistroWithoutImageTypes(defsDir, nameVer string) (*DistroYAML, error) {
distros, err := loadDistros(defsDir)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -259,7 +266,7 @@ func LoadDistroWithoutImageTypes(nameVer string) (*DistroYAML, error) {
}

func (d *DistroYAML) LoadImageTypes() error {
f, err := dataFS().Open(filepath.Join(d.DefsPath, "imagetypes.yaml"))
f, err := dataFS(d.defsRoot).Open(filepath.Join(d.DefsPath, "imagetypes.yaml"))
if err != nil {
return err
}
Expand Down
34 changes: 17 additions & 17 deletions pkg/distro/defs/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func makeTestImageType(t *testing.T, fakeContent string) defs.ImageTypeYAML {
restore := defs.MockDataFS(baseDir)
t.Cleanup(restore)

distro, err := defs.NewDistroYAML("test-distro-1")
distro, err := defs.NewDistroYAML("", "test-distro-1")
require.NoError(t, err)
it, ok := distro.ImageTypes()["test_type"]
require.True(t, ok, "cannot find test_type in %s", fakeContent)
Expand Down Expand Up @@ -163,7 +163,7 @@ image_types:
fakeBaseDir := makeFakeDistrosYAML(t, "", fakeImgTypesYAML)

t.Setenv("IMAGE_BUILDER_EXPERIMENTAL", fmt.Sprintf("yamldir=%s", fakeBaseDir))
dist := generic.DistroFactory("test-distro-1")
dist := generic.DistroFactory("", "test-distro-1")
assert.NotNil(t, dist)
ar, err := dist.GetArch("x86_64")
assert.NoError(t, err)
Expand Down Expand Up @@ -344,7 +344,7 @@ image_types:
baseDir := makeFakeDistrosYAML(t, fakeDistrosYaml, fakeImageTypesYaml)
restore := defs.MockDataFS(baseDir)
defer restore()
td, err := defs.NewDistroYAML("test-distro-1")
td, err := defs.NewDistroYAML("", "test-distro-1")
require.NoError(t, err)
it := td.ImageTypes()["test_type"]
require.NotNil(t, it)
Expand Down Expand Up @@ -395,7 +395,7 @@ image_types:
baseDir := makeFakeDistrosYAML(t, fakeDistrosYaml, fakeImageTypesYaml)
restore := defs.MockDataFS(baseDir)
defer restore()
td, err := defs.NewDistroYAML("test-distro-1")
td, err := defs.NewDistroYAML("", "test-distro-1")
require.NoError(t, err)
it := td.ImageTypes()["test_type"]
require.NotNil(t, it)
Expand Down Expand Up @@ -437,7 +437,7 @@ image_types:
baseDir := makeFakeDistrosYAML(t, fakeDistrosYaml, fakeImageTypesYaml)
restore := defs.MockDataFS(baseDir)
defer restore()
_, err := defs.NewDistroYAML("test-distro-1")
_, err := defs.NewDistroYAML("", "test-distro-1")
assert.EqualError(t, err, `no default fs set: mount "/" requires a filesystem but none set`)
}

Expand Down Expand Up @@ -645,7 +645,7 @@ image_types:
`
makeTestImageType(t, fakeDistroYaml)

dist, err := defs.NewDistroYAML("test-distro-1")
dist, err := defs.NewDistroYAML("", "test-distro-1")
assert.NoError(t, err)
assert.Equal(t, dist.ImageConfig(), &distro.ImageConfig{
Locale: common.ToPtr("C.UTF-8"),
Expand Down Expand Up @@ -757,7 +757,7 @@ image_types:
`
makeTestImageType(t, fakeDistroYaml)

distro, err := defs.NewDistroYAML("test-distro-1")
distro, err := defs.NewDistroYAML("", "test-distro-1")
require.NoError(t, err)

imgTypes := distro.ImageTypes()
Expand Down Expand Up @@ -803,7 +803,7 @@ image_types:
restore := defs.MockDataFS(baseDir)
defer restore()

_, err := defs.NewDistroYAML("test-distro-1")
_, err := defs.NewDistroYAML("", "test-distro-1")
require.ErrorContains(t, err, `cannot execute template for "vendor" field (is it set?)`)
}

Expand Down Expand Up @@ -962,7 +962,7 @@ func TestDistrosLoadingExact(t *testing.T) {
restore := defs.MockDataFS(baseDir)
defer restore()

dist, err := defs.NewDistroYAML("fedora-43")
dist, err := defs.NewDistroYAML("", "fedora-43")
require.NoError(t, err)
assert.Equal(t, dist, &defs.DistroYAML{
Name: "fedora-43",
Expand All @@ -987,7 +987,7 @@ func TestDistrosLoadingExact(t *testing.T) {
ID: distro.ID{Name: "fedora", MajorVersion: 43, MinorVersion: -1},
})

dist, err = defs.NewDistroYAML("centos-10")
dist, err = defs.NewDistroYAML("", "centos-10")
require.NoError(t, err)
assert.Equal(t, dist, &defs.DistroYAML{
Name: "centos-10",
Expand All @@ -1008,7 +1008,7 @@ func TestDistrosLoadingFactoryCompat(t *testing.T) {
restore := defs.MockDataFS(baseDir)
defer restore()

dist, err := defs.NewDistroYAML("rhel-10.1")
dist, err := defs.NewDistroYAML("", "rhel-10.1")
require.NoError(t, err)
assert.Equal(t, dist, &defs.DistroYAML{
Name: "rhel-10.1",
Expand All @@ -1024,7 +1024,7 @@ func TestDistrosLoadingFactoryCompat(t *testing.T) {
ID: distro.ID{Name: "rhel", MajorVersion: 10, MinorVersion: 1},
})

dist, err = defs.NewDistroYAML("fedora-40")
dist, err = defs.NewDistroYAML("", "fedora-40")
require.NoError(t, err)
assert.Equal(t, dist, &defs.DistroYAML{
Name: "fedora-40",
Expand Down Expand Up @@ -1100,7 +1100,7 @@ distros:
// this layer. XXX: consolidate it to the YAML level
// already?

distro := generic.DistroFactory(tc.distroNameVer)
distro := generic.DistroFactory("", tc.distroNameVer)
require.NotNil(t, distro)
assert.Equal(t, tc.distroNameVer, distro.Name())
a, err := distro.GetArch("x86_64")
Expand All @@ -1116,7 +1116,7 @@ func TestDistrosLoadingNotFound(t *testing.T) {
restore := defs.MockDataFS(baseDir)
defer restore()

distro, err := defs.NewDistroYAML("non-exiting")
distro, err := defs.NewDistroYAML("", "non-exiting")
assert.Nil(t, err)
assert.Nil(t, distro)
}
Expand Down Expand Up @@ -1177,7 +1177,7 @@ distros:
{"test-distro-2", "some-uefi-vendor"},
} {

distro, err := defs.NewDistroYAML(tc.distroNameVer)
distro, err := defs.NewDistroYAML("", tc.distroNameVer)
require.NoError(t, err)

imgTypes := distro.ImageTypes()
Expand Down Expand Up @@ -1219,7 +1219,7 @@ image_types:
`
makeTestImageType(t, fakeImageTypesYaml)

distro, err := defs.NewDistroYAML("test-distro-1")
distro, err := defs.NewDistroYAML("", "test-distro-1")
assert.NoError(t, err)
require.NotNil(t, distro)
imgTypes := distro.ImageTypes()
Expand Down Expand Up @@ -1254,7 +1254,7 @@ distros:
{"rhel-8.10", "rhel-8.10", "8.10"},
{"rhel-810", "rhel-8.10", "8.10"},
} {
dist, err := defs.NewDistroYAML(tc.nameVer)
dist, err := defs.NewDistroYAML("", tc.nameVer)
require.NoError(t, err)
assert.Equal(t, dist, &defs.DistroYAML{
Name: tc.expectedDistroNameVer,
Expand Down
8 changes: 4 additions & 4 deletions pkg/distro/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestImageTypePipelineNames(t *testing.T) {
Pipelines []pipeline `json:"pipelines"`
}

distroFactory := distrofactory.NewDefault()
distroFactory := distrofactory.NewDefault("")
distros := listTestedDistros(t)
for _, distroName := range distros {
d := distroFactory.GetDistro(distroName)
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestPipelineRepositories(t *testing.T) {
},
}

distroFactory := distrofactory.NewDefault()
distroFactory := distrofactory.NewDefault("")
distros := listTestedDistros(t)
for tName, tCase := range testCases {
t.Run(tName, func(t *testing.T) {
Expand Down Expand Up @@ -607,7 +607,7 @@ func TestDistro_ManifestFIPSWarning(t *testing.T) {
"iot-qcow2",
}

distroFactory := distrofactory.NewDefault()
distroFactory := distrofactory.NewDefault("")
distros := listTestedDistros(t)
for _, distroName := range distros {
// FIPS blueprint customization is not supported for RHEL 7 images
Expand Down Expand Up @@ -660,7 +660,7 @@ func TestDistro_ManifestFIPSWarning(t *testing.T) {
// Test that passing options.OSTree for non-OSTree image types results in an error
func TestOSTreeOptionsErrorForNonOSTreeImgTypes(t *testing.T) {
assert := assert.New(t)
distroFactory := distrofactory.NewDefault()
distroFactory := distrofactory.NewDefault("")
assert.NotNil(distroFactory)

distros := listTestedDistros(t)
Expand Down
8 changes: 4 additions & 4 deletions pkg/distro/generic/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (d *distribution) getISOLabelFunc(isoLabel string) isoLabelFunc {
}
}

func newDistro(nameVer string) (distro.Distro, error) {
distroYAML, err := defs.NewDistroYAML(nameVer)
func newDistro(defsDir, nameVer string) (distro.Distro, error) {
distroYAML, err := defs.NewDistroYAML(defsDir, nameVer)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -224,8 +224,8 @@ func (a *architecture) Distro() distro.Distro {
return a.distro
}

func DistroFactory(idStr string) distro.Distro {
distro, err := newDistro(idStr)
func DistroFactory(defsDir string, idStr string) distro.Distro {
distro, err := newDistro(defsDir, idStr)
if errors.Is(err, ErrDistroNotFound) {
return nil
}
Expand Down
Loading
Loading