Skip to content

Commit ca49048

Browse files
committed
buildkitd: cdi config
Signed-off-by: CrazyMax <[email protected]>
1 parent 577c6eb commit ca49048

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed

cmd/buildkitd/config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type Config struct {
2323

2424
OTEL OTELConfig `toml:"otel"`
2525

26+
CDI CDIConfig `toml:"cdi"`
27+
2628
Workers struct {
2729
OCI OCIConfig `toml:"oci"`
2830
Containerd ContainerdConfig `toml:"containerd"`
@@ -74,6 +76,11 @@ type OTELConfig struct {
7476
SocketPath string `toml:"socketPath"`
7577
}
7678

79+
type CDIConfig struct {
80+
Enabled *bool `toml:"enabled"`
81+
SpecDirs []string `toml:"specDirs"`
82+
}
83+
7784
type GCConfig struct {
7885
GC *bool `toml:"gc"`
7986
// Deprecated: use GCReservedSpace instead

cmd/buildkitd/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ 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"
7778
)
7879

7980
func init() {
@@ -216,6 +217,14 @@ func main() {
216217
Name: "otel-socket-path",
217218
Usage: "OTEL collector trace socket path",
218219
},
220+
cli.BoolFlag{
221+
Name: "cdi-enabled",
222+
Usage: "enables support of the Container Device Interface (CDI)",
223+
},
224+
cli.StringSliceFlag{
225+
Name: "cdi-spec-dir",
226+
Usage: "list of directories to scan for CDI spec files",
227+
},
219228
)
220229
app.Flags = append(app.Flags, appFlags...)
221230
app.Flags = append(app.Flags, serviceFlags()...)
@@ -281,6 +290,12 @@ func main() {
281290
}
282291
closers = append(closers, mp.Shutdown)
283292

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+
284299
statsHandler := tracing.ServerStatsHandler(
285300
otelgrpc.WithTracerProvider(tp),
286301
otelgrpc.WithMeterProvider(mp),
@@ -537,6 +552,10 @@ func setDefaultConfig(cfg *config.Config) {
537552
if cfg.OTEL.SocketPath == "" {
538553
cfg.OTEL.SocketPath = appdefaults.TraceSocketPath(isRootlessConfig())
539554
}
555+
556+
if len(cfg.CDI.SpecDirs) == 0 {
557+
cfg.CDI.SpecDirs = appdefaults.CDISpecDirs
558+
}
540559
}
541560

542561
// isRootlessConfig is true if we should be using the rootless config
@@ -619,6 +638,14 @@ func applyMainFlags(c *cli.Context, cfg *config.Config) error {
619638
cfg.OTEL.SocketPath = c.String("otel-socket-path")
620639
}
621640

641+
if c.IsSet("cdi-enabled") {
642+
cdiEnabled := c.Bool("cdi-enabled")
643+
cfg.CDI.Enabled = &cdiEnabled
644+
}
645+
if c.IsSet("cdi-spec-dir") {
646+
cfg.CDI.SpecDirs = c.StringSlice("cdi-spec-dir")
647+
}
648+
622649
applyPlatformFlags(c)
623650

624651
return nil

docs/buildkitd.toml.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
4646
# OTEL collector trace socket path
4747
socketPath = "/run/buildkit/otel-grpc.sock"
4848

49+
[cdi]
50+
# Enables support of the Container Device Interface (CDI).
51+
enabled = true
52+
# List of directories to scan for CDI spec files. For more details about CDI
53+
# specification, please refer to https://github.com/cncf-tags/container-device-interface/blob/main/SPEC.md#cdi-json-specification
54+
specDirs = ["/etc/cdi", "/var/run/cdi"]
55+
4956
# config for build history API that stores information about completed build commands
5057
[history]
5158
# maxAge is the maximum age of history entries to keep, in seconds.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ require (
107107
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1
108108
google.golang.org/protobuf v1.35.2
109109
kernel.org/pub/linux/libs/security/libcap/cap v1.2.73
110+
tags.cncf.io/container-device-interface v0.8.0
110111
)
111112

112113
require (
@@ -183,7 +184,6 @@ require (
183184
gopkg.in/yaml.v3 v3.0.1 // indirect
184185
kernel.org/pub/linux/libs/security/libcap/psx v1.2.73 // indirect
185186
sigs.k8s.io/yaml v1.4.0 // indirect
186-
tags.cncf.io/container-device-interface v0.8.0 // indirect
187187
tags.cncf.io/container-device-interface/specs-go v0.8.0 // indirect
188188
)
189189

util/appdefaults/appdefaults_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717

1818
var (
1919
UserCNIConfigPath = filepath.Join(UserConfigDir(), "cni.json")
20+
CDISpecDirs = []string{"/etc/buildkit/cdi"}
2021
)
2122

2223
// UserAddress typically returns /run/user/$UID/buildkit/buildkitd.sock

util/appdefaults/appdefaults_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818

1919
var (
2020
UserCNIConfigPath = DefaultCNIConfigPath
21+
CDISpecDirs []string
2122
)
2223

2324
func UserAddress() string {

0 commit comments

Comments
 (0)