Skip to content

Commit 17f46d1

Browse files
committed
worker: cdi manager
Signed-off-by: CrazyMax <[email protected]>
1 parent 33f2164 commit 17f46d1

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

cmd/buildkitd/main.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ import (
7474
"google.golang.org/grpc/health"
7575
healthv1 "google.golang.org/grpc/health/grpc_health_v1"
7676
"google.golang.org/grpc/reflection"
77-
"tags.cncf.io/container-device-interface/pkg/cdi"
7877
)
7978

8079
func init() {
@@ -290,12 +289,6 @@ func main() {
290289
}
291290
closers = append(closers, mp.Shutdown)
292291

293-
if cfg.CDI.Enabled != nil && *cfg.CDI.Enabled {
294-
if err := cdi.Configure(cdi.WithSpecDirs(cfg.CDI.SpecDirs...)); err != nil {
295-
return errors.Wrap(err, "failed to configure CDI registry")
296-
}
297-
}
298-
299292
statsHandler := tracing.ServerStatsHandler(
300293
otelgrpc.WithTracerProvider(tp),
301294
otelgrpc.WithMeterProvider(mp),

cmd/buildkitd/main_oci_worker.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
"google.golang.org/grpc"
4949
"google.golang.org/grpc/backoff"
5050
"google.golang.org/grpc/credentials/insecure"
51+
"tags.cncf.io/container-device-interface/pkg/cdi"
5152
)
5253

5354
func init() {
@@ -323,6 +324,17 @@ func ociWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([]worker
323324
opt.BuildkitVersion = getBuildkitVersion()
324325
opt.RegistryHosts = hosts
325326

327+
if common.config.CDI.Enabled != nil && *common.config.CDI.Enabled {
328+
if len(common.config.CDI.SpecDirs) == 0 {
329+
return nil, errors.New("No CDI specification directories specified")
330+
}
331+
cdiCache, err := cdi.NewCache(cdi.WithSpecDirs(common.config.CDI.SpecDirs...))
332+
if err != nil {
333+
return nil, errors.Wrapf(err, "CDI registry initialization failure")
334+
}
335+
opt.CDIManager = cdiCache
336+
}
337+
326338
if platformsStr := cfg.Platforms; len(platformsStr) != 0 {
327339
platforms, err := parsePlatforms(platformsStr)
328340
if err != nil {

worker/base/worker.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import (
5252
"github.com/pkg/errors"
5353
"golang.org/x/sync/errgroup"
5454
"golang.org/x/sync/semaphore"
55+
"tags.cncf.io/container-device-interface/pkg/cdi"
5556
)
5657

5758
const labelCreatedAt = "buildkit/createdat"
@@ -82,6 +83,7 @@ type WorkerOpt struct {
8283
MetadataStore *metadata.Store
8384
MountPoolRoot string
8485
ResourceMonitor *resources.Monitor
86+
CDIManager *cdi.Cache
8587
}
8688

8789
// Worker is a local worker instance with dedicated snapshotter, cache, and so on.
@@ -245,6 +247,10 @@ func (w *Worker) LeaseManager() *leaseutil.Manager {
245247
return w.WorkerOpt.LeaseManager
246248
}
247249

250+
func (w *Worker) CDIManager() *cdi.Cache {
251+
return w.WorkerOpt.CDIManager
252+
}
253+
248254
func (w *Worker) ID() string {
249255
return w.WorkerOpt.ID
250256
}

0 commit comments

Comments
 (0)