builder: Pass cdi cache instead of CDISpecDirs

Instead of passing the dirs for buildkit to configure the same cache
instance, just pass the shared CDI cache instance.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2025-05-26 18:00:33 +02:00
parent bc6bc7aafa
commit 027588eba0
5 changed files with 22 additions and 27 deletions

View File

@@ -251,8 +251,9 @@ func (cli *daemonCLI) start(ctx context.Context) (err error) {
// In order to lift this restriction the following would have to be addressed:
// - Support needs to be added to the cdi package for injecting Windows devices: https://tags.cncf.io/container-device-interface/issues/28
// - The DeviceRequests API must be extended to non-linux platforms.
var cdiCache *cdi.Cache
if cdiEnabled(cli.Config) {
daemon.RegisterCDIDriver(cli.Config.CDISpecDirs...)
cdiCache = daemon.RegisterCDIDriver(cli.Config.CDISpecDirs...)
}
var apiServer apiserver.Server
@@ -289,7 +290,7 @@ func (cli *daemonCLI) start(ctx context.Context) (err error) {
// initialized the cluster.
d.RestartSwarmContainers()
b, shutdownBuildKit, err := initBuildkit(ctx, d)
b, shutdownBuildKit, err := initBuildkit(ctx, d, cdiCache)
if err != nil {
return fmt.Errorf("error initializing buildkit: %w", err)
}
@@ -390,7 +391,7 @@ func setOTLPProtoDefault() {
}
}
func initBuildkit(ctx context.Context, d *daemon.Daemon) (_ builderOptions, closeFn func(), _ error) {
func initBuildkit(ctx context.Context, d *daemon.Daemon, cdiCache *cdi.Cache) (_ builderOptions, closeFn func(), _ error) {
log.G(ctx).Info("Initializing buildkit")
closeFn = func() {}
@@ -406,11 +407,6 @@ func initBuildkit(ctx context.Context, d *daemon.Daemon) (_ builderOptions, clos
cfg := d.Config()
var cdiSpecDirs []string
if cdiEnabled(&cfg) {
cdiSpecDirs = cfg.CDISpecDirs
}
bk, err := buildkit.New(ctx, buildkit.Opt{
SessionManager: sm,
Root: filepath.Join(cfg.Root, "buildkit"),
@@ -432,7 +428,7 @@ func initBuildkit(ctx context.Context, d *daemon.Daemon) (_ builderOptions, clos
Callbacks: exporter.BuildkitCallbacks{
Exported: d.ImageExportedByBuildkit,
},
CDISpecDirs: cdiSpecDirs,
CDICache: cdiCache,
})
if err != nil {
return builderOptions{}, closeFn, errors.Wrap(err, "error creating buildkit instance")