From cdf57e5bc1187c7fac5446dfb030f16af533d3fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 9 Jan 2024 22:20:41 +0100 Subject: [PATCH] osbuild-composer/config: support specifying distro aliases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new configuration option `distro_aliases`, which is a map of strings, allowing to specify distro name alias for supported distributions. Define aliases for RHEL major versions without the minor version specified. For now, the distro aliases map is not used by any API implementation and it is ignored. Signed-off-by: Tomáš Hozza --- cmd/osbuild-composer/composer.go | 3 +++ cmd/osbuild-composer/config.go | 24 +++++++++++++++--------- cmd/osbuild-composer/config_test.go | 16 ++++++++++++++++ cmd/osbuild-composer/testdata/test.toml | 4 ++++ 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/cmd/osbuild-composer/composer.go b/cmd/osbuild-composer/composer.go index 25786e794..6a6e65551 100644 --- a/cmd/osbuild-composer/composer.go +++ b/cmd/osbuild-composer/composer.go @@ -69,6 +69,9 @@ func NewComposer(config *ComposerConfigFile, stateDir, cacheDir string) (*Compos } c.distros = distrofactory.NewDefault() + // TODO: set the c.config.DistroAliases to the distrofactory + // More work is needed to make the distro aliases behavior consistent for Weldr API, + // specifically for picking the correct repositories definition. c.solver = dnfjson.NewBaseSolver(path.Join(c.cacheDir, "rpmmd")) c.solver.SetDNFJSONPath(c.config.DNFJson) diff --git a/cmd/osbuild-composer/config.go b/cmd/osbuild-composer/config.go index a36a1f667..d89dea58c 100644 --- a/cmd/osbuild-composer/config.go +++ b/cmd/osbuild-composer/config.go @@ -11,15 +11,16 @@ import ( ) type ComposerConfigFile struct { - Koji KojiAPIConfig `toml:"koji"` - Worker WorkerAPIConfig `toml:"worker"` - WeldrAPI WeldrAPIConfig `toml:"weldr_api"` - LogLevel string `toml:"log_level"` - LogFormat string `toml:"log_format"` - DNFJson string `toml:"dnf-json"` - SplunkHost string `env:"SPLUNK_HEC_HOST"` - SplunkPort string `env:"SPLUNK_HEC_PORT"` - SplunkToken string `env:"SPLUNK_HEC_TOKEN"` + Koji KojiAPIConfig `toml:"koji"` + Worker WorkerAPIConfig `toml:"worker"` + WeldrAPI WeldrAPIConfig `toml:"weldr_api"` + DistroAliases map[string]string `toml:"distro_aliases"` + LogLevel string `toml:"log_level"` + LogFormat string `toml:"log_format"` + DNFJson string `toml:"dnf-json"` + SplunkHost string `env:"SPLUNK_HEC_HOST"` + SplunkPort string `env:"SPLUNK_HEC_PORT"` + SplunkToken string `env:"SPLUNK_HEC_TOKEN"` } type KojiAPIConfig struct { @@ -112,6 +113,11 @@ func GetDefaultConfig() *ComposerConfigFile { }, }, }, + DistroAliases: map[string]string{ + "rhel-7": "rhel-7.9", + "rhel-8": "rhel-8.10", + "rhel-9": "rhel-9.4", + }, LogLevel: "info", LogFormat: "text", DNFJson: "/usr/libexec/osbuild-composer/dnf-json", diff --git a/cmd/osbuild-composer/config_test.go b/cmd/osbuild-composer/config_test.go index 96ef7c804..009cd1129 100644 --- a/cmd/osbuild-composer/config_test.go +++ b/cmd/osbuild-composer/config_test.go @@ -61,6 +61,14 @@ func TestDefaultConfig(t *testing.T) { } require.Equal(t, expectedWeldrAPIConfig, defaultConfig.WeldrAPI) + + expectedDistroAliases := map[string]string{ + "rhel-7": "rhel-7.9", + "rhel-8": "rhel-8.10", + "rhel-9": "rhel-9.4", + } + require.Equal(t, expectedDistroAliases, defaultConfig.DistroAliases) + require.Equal(t, "text", defaultConfig.LogFormat) } @@ -90,6 +98,14 @@ func TestConfig(t *testing.T) { require.Equal(t, []string{"https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/certs"}, config.Koji.JWTKeysURLs) require.Equal(t, "", config.Koji.JWTKeysCA) require.Equal(t, "/var/lib/osbuild-composer/acl", config.Koji.JWTACLFile) + + // 'rhel-8' and 'rhel-9' aliases are overwritten by the config file + expectedDistroAliases := map[string]string{ + "rhel-7": "rhel-7.9", // this value is from the default config + "rhel-8": "rhel-8.9", + "rhel-9": "rhel-9.3", + } + require.Equal(t, expectedDistroAliases, config.DistroAliases) } func TestWeldrDistrosImageTypeDenyList(t *testing.T) { diff --git a/cmd/osbuild-composer/testdata/test.toml b/cmd/osbuild-composer/testdata/test.toml index d47cd026b..2ba1b7a69 100644 --- a/cmd/osbuild-composer/testdata/test.toml +++ b/cmd/osbuild-composer/testdata/test.toml @@ -18,3 +18,7 @@ image_type_denylist = [ "qcow2" ] # overrides the default rhel-* configuration [weldr_api.distros."rhel-*"] + +[distro_aliases] +rhel-8 = "rhel-8.9" +rhel-9 = "rhel-9.3"