diff --git a/internal/distro/fedora/distro.go b/internal/distro/fedora/distro.go index 9fbf4b3a3..f8c1ecbfd 100644 --- a/internal/distro/fedora/distro.go +++ b/internal/distro/fedora/distro.go @@ -784,20 +784,6 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio return nil } -func NewHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - parts := strings.Split(name, "-") - if len(parts) != 2 || parts[0] != "fedora" { - panic("invalid distro name: " + name) - } - - version, err := strconv.Atoi(parts[1]) - if err != nil { - panic("invalid distro version: " + name + ": " + err.Error()) - } - - return newDistro(version) -} - // New creates a new distro object, defining the supported architectures and image types func NewF36() distro.Distro { return newDistro(36) diff --git a/internal/distro/rhel7/distro.go b/internal/distro/rhel7/distro.go index fd9ce95b7..3b0b7f40a 100644 --- a/internal/distro/rhel7/distro.go +++ b/internal/distro/rhel7/distro.go @@ -451,10 +451,6 @@ func New() distro.Distro { return newDistro("rhel-7") } -func NewHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - return newDistro("rhel-7") -} - func newDistro(distroName string) distro.Distro { rd := distroMap[distroName] diff --git a/internal/distro/rhel8/distro.go b/internal/distro/rhel8/distro.go index f7e714ad8..eb71b1681 100644 --- a/internal/distro/rhel8/distro.go +++ b/internal/distro/rhel8/distro.go @@ -598,58 +598,30 @@ func New() distro.Distro { } -func NewHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - return New() -} - func NewRHEL84() distro.Distro { return newDistro("rhel", 4) } -func NewRHEL84HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - return NewRHEL84() -} - func NewRHEL85() distro.Distro { return newDistro("rhel", 5) } -func NewRHEL85HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - return NewRHEL85() -} - func NewRHEL86() distro.Distro { return newDistro("rhel", 6) } -func NewRHEL86HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - return NewRHEL86() -} - func NewRHEL87() distro.Distro { return newDistro("rhel", 7) } -func NewRHEL87HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - return NewRHEL87() -} - func NewRHEL88() distro.Distro { return newDistro("rhel", 8) } -func NewRHEL88HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - return NewRHEL88() -} - func NewCentos() distro.Distro { return newDistro("centos", 0) } -func NewCentosHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - return NewCentos() -} - func newDistro(name string, minor int) *distribution { var rd distribution switch name { diff --git a/internal/distro/rhel9/distro.go b/internal/distro/rhel9/distro.go index 053531851..2a4674c7e 100644 --- a/internal/distro/rhel9/distro.go +++ b/internal/distro/rhel9/distro.go @@ -131,47 +131,22 @@ func New() distro.Distro { return d } -func NewHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - // NOTE: args are ignored - host distro constructors are deprecated - return New() -} - func NewCentOS9() distro.Distro { return newDistro("centos", 0) } -func NewCentOS9HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - // NOTE: args are ignored - host distro constructors are deprecated - return NewCentOS9() -} - func NewRHEL90() distro.Distro { return newDistro("rhel", 0) } -func NewRHEL90HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - // NOTE: args are ignored - host distro constructors are deprecated - return NewRHEL90() -} - func NewRHEL91() distro.Distro { return newDistro("rhel", 1) } -func NewRHEL91HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - // NOTE: args are ignored - host distro constructors are deprecated - return NewRHEL91() -} - func NewRHEL92() distro.Distro { return newDistro("rhel", 2) } -func NewRHEL92HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro { - // NOTE: args are ignored - host distro constructors are deprecated - return NewRHEL92() -} - func newDistro(name string, minor int) *distribution { var rd distribution switch name { diff --git a/internal/distro/rhel9/distro_test.go b/internal/distro/rhel9/distro_test.go index d14818ee1..b02a434c4 100644 --- a/internal/distro/rhel9/distro_test.go +++ b/internal/distro/rhel9/distro_test.go @@ -591,7 +591,7 @@ func TestRhel9_GetArch(t *testing.T) { func TestRhel9_Name(t *testing.T) { distro := rhel9.New() - assert.Equal(t, "rhel-90", distro.Name()) + assert.Equal(t, "rhel-9", distro.Name()) } func TestRhel9_ModulePlatformID(t *testing.T) { diff --git a/internal/distroregistry/distroregistry.go b/internal/distroregistry/distroregistry.go index 1c174dbda..9dc32d421 100644 --- a/internal/distroregistry/distroregistry.go +++ b/internal/distroregistry/distroregistry.go @@ -15,31 +15,26 @@ import ( // When adding support for a new distribution, add it here. // Note that this is a constant, do not write to this array. -var supportedDistros = []supportedDistro{ - {fedora.NewF36, fedora.NewHostDistro}, - {fedora.NewF37, fedora.NewHostDistro}, - {fedora.NewF38, fedora.NewHostDistro}, +var supportedDistros = []func() distro.Distro{ + fedora.NewF36, + fedora.NewF37, + fedora.NewF38, - {rhel7.New, rhel7.NewHostDistro}, + rhel7.New, - {rhel8.New, rhel8.NewHostDistro}, - {rhel8.NewRHEL84, rhel8.NewRHEL84HostDistro}, - {rhel8.NewRHEL85, rhel8.NewRHEL85HostDistro}, - {rhel8.NewRHEL86, rhel8.NewRHEL86HostDistro}, - {rhel8.NewRHEL87, rhel8.NewRHEL87HostDistro}, - {rhel8.NewRHEL88, rhel8.NewRHEL88HostDistro}, - {rhel8.NewCentos, rhel8.NewCentosHostDistro}, + rhel8.New, + rhel8.NewRHEL84, + rhel8.NewRHEL85, + rhel8.NewRHEL86, + rhel8.NewRHEL87, + rhel8.NewRHEL88, + rhel8.NewCentos, - {rhel9.New, rhel9.NewHostDistro}, - {rhel9.NewRHEL90, rhel9.NewRHEL90HostDistro}, - {rhel9.NewRHEL91, rhel9.NewRHEL91HostDistro}, - {rhel9.NewRHEL92, rhel9.NewRHEL92HostDistro}, - {rhel9.NewCentOS9, rhel9.NewCentOS9HostDistro}, -} - -type supportedDistro struct { - defaultDistro func() distro.Distro - hostDistro func(name, modulePlatformID, ostreeRef string) distro.Distro + rhel9.New, + rhel9.NewRHEL90, + rhel9.NewRHEL91, + rhel9.NewRHEL92, + rhel9.NewCentOS9, } type Registry struct { @@ -75,19 +70,12 @@ func NewDefault() *Registry { // If there was an error, then the hostDistroName will be an empty string // and as a result, the hostDistro will have a nil value when calling New(). // Getting the host distro later using FromHost() will return nil as well. - hostDistroName, hostDistroIsBeta, hostDistroIsStream, _ := common.GetHostDistroName() - + hostDistroName, _, _, _ := common.GetHostDistroName() for _, supportedDistro := range supportedDistros { - distro := supportedDistro.defaultDistro() - + distro := supportedDistro() if distro.Name() == hostDistroName { - hostDistro = supportedDistro.hostDistro( - mangleHostDistroName(distro.Name(), hostDistroIsBeta, hostDistroIsStream), - distro.ModulePlatformID(), - distro.OSTreeRef(), - ) + hostDistro = supportedDistro() } - distros = append(distros, distro) } diff --git a/internal/distroregistry/distroregistry_test.go b/internal/distroregistry/distroregistry_test.go index 6eb9a6323..6778194ed 100644 --- a/internal/distroregistry/distroregistry_test.go +++ b/internal/distroregistry/distroregistry_test.go @@ -15,7 +15,7 @@ func TestRegistry_List(t *testing.T) { // build expected distros var expected []string for _, supportedDistro := range supportedDistros { - d := supportedDistro.defaultDistro() + d := supportedDistro() expected = append(expected, d.Name()) } @@ -98,7 +98,7 @@ func TestRegistry_FromHost(t *testing.T) { // expected distros var distros []distro.Distro for _, supportedDistro := range supportedDistros { - distros = append(distros, supportedDistro.defaultDistro()) + distros = append(distros, supportedDistro()) } t.Run("host distro is nil", func(t *testing.T) { @@ -109,9 +109,7 @@ func TestRegistry_FromHost(t *testing.T) { }) t.Run("host distro not nil", func(t *testing.T) { - // NOTE(akoutsou): The arguments to NewHostDistro are ignored since RHEL 8.6 - // The function signature will change in the near future. - hostDistro := rhel8.NewHostDistro("", "", "") + hostDistro := rhel8.New() fmt.Println(hostDistro.Name()) registry, err := New(hostDistro, distros...) require.Nil(t, err)