Skip to content

Commit

Permalink
osbuild-composer: log NoReposLoadedError and continue
Browse files Browse the repository at this point in the history
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] osbuild/images#946
  • Loading branch information
achilleas-k committed Oct 30, 2024
1 parent cd0669d commit 9884640
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions cmd/osbuild-composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down

0 comments on commit 9884640

Please sign in to comment.