From 9884640e56f99292393f045019f022e760126ebb Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Wed, 30 Oct 2024 15:19:57 +0100 Subject: [PATCH] osbuild-composer: log NoReposLoadedError and continue osbuild/images added an error type that's returned when the reporegistry loader doesn't find any repository configurations to load [1]. This lets callers decide whether to stop or continue execution based on whether repository configurations are required. Weldr (running on-prem) requires local repository configurations, while the API (SaaS) doesn't. However, at the time during startup when reporegistry.LoadAllRepositories() is called, it is still not known whether the Weldr API will be initialised. Log the error message as an info message when it is detected but continue execution. [1] https://github.com/osbuild/images/pull/946 --- cmd/osbuild-composer/composer.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/osbuild-composer/composer.go b/cmd/osbuild-composer/composer.go index 485248d6fe..128d96c2b7 100644 --- a/cmd/osbuild-composer/composer.go +++ b/cmd/osbuild-composer/composer.go @@ -78,16 +78,29 @@ func NewComposer(config *ComposerConfigFile, stateDir, cacheDir string) (*Compos } repoConfigs, err := reporegistry.LoadAllRepositories(repositoryConfigs) - if err != nil { - return nil, fmt.Errorf("error loading repository definitions: %v", err) + switch err.(type) { + case *reporegistry.NoReposLoadedError: + // When running as a service (cloud API), there are no repositories + // configured, so this is OK. The weldr initialiser should check if + // there are no repositories configured and behave accordingly. + // Log for troubleshooting. + logrus.Info(err.Error()) + case nil: + c.repos = reporegistry.NewFromDistrosRepoConfigs(repoConfigs) + default: + return nil, fmt.Errorf("error loading repository definitions: %w", err) } - c.repos = reporegistry.NewFromDistrosRepoConfigs(repoConfigs) c.solver = dnfjson.NewBaseSolver(path.Join(c.cacheDir, "rpmmd")) c.solver.SetDNFJSONPath(c.config.DNFJson) - // Clean up the cache, removes unknown distros and files - c.solver.CleanupOldCacheDirs(c.repos.ListDistros()) + // Clean up the cache, removes unknown distros and files. + // If no repos are configured, the cache is cleared out completely. + var repoDistros []string + if c.repos != nil { + repoDistros = c.repos.ListDistros() + } + c.solver.CleanupOldCacheDirs(repoDistros) var jobs jobqueue.JobQueue if config.Worker.PGDatabase != "" {