buildkitd: cdi config

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2024-10-09 11:24:10 +02:00
parent 577c6ebee5
commit ca49048881
6 changed files with 44 additions and 1 deletions

View File

@@ -23,6 +23,8 @@ type Config struct {
OTEL OTELConfig `toml:"otel"`
CDI CDIConfig `toml:"cdi"`
Workers struct {
OCI OCIConfig `toml:"oci"`
Containerd ContainerdConfig `toml:"containerd"`
@@ -74,6 +76,11 @@ type OTELConfig struct {
SocketPath string `toml:"socketPath"`
}
type CDIConfig struct {
Enabled *bool `toml:"enabled"`
SpecDirs []string `toml:"specDirs"`
}
type GCConfig struct {
GC *bool `toml:"gc"`
// Deprecated: use GCReservedSpace instead

View File

@@ -74,6 +74,7 @@ import (
"google.golang.org/grpc/health"
healthv1 "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection"
"tags.cncf.io/container-device-interface/pkg/cdi"
)
func init() {
@@ -216,6 +217,14 @@ func main() {
Name: "otel-socket-path",
Usage: "OTEL collector trace socket path",
},
cli.BoolFlag{
Name: "cdi-enabled",
Usage: "enables support of the Container Device Interface (CDI)",
},
cli.StringSliceFlag{
Name: "cdi-spec-dir",
Usage: "list of directories to scan for CDI spec files",
},
)
app.Flags = append(app.Flags, appFlags...)
app.Flags = append(app.Flags, serviceFlags()...)
@@ -281,6 +290,12 @@ func main() {
}
closers = append(closers, mp.Shutdown)
if cfg.CDI.Enabled != nil && *cfg.CDI.Enabled {
if err := cdi.Configure(cdi.WithSpecDirs(cfg.CDI.SpecDirs...)); err != nil {
return errors.Wrap(err, "failed to configure CDI registry")
}
}
statsHandler := tracing.ServerStatsHandler(
otelgrpc.WithTracerProvider(tp),
otelgrpc.WithMeterProvider(mp),
@@ -537,6 +552,10 @@ func setDefaultConfig(cfg *config.Config) {
if cfg.OTEL.SocketPath == "" {
cfg.OTEL.SocketPath = appdefaults.TraceSocketPath(isRootlessConfig())
}
if len(cfg.CDI.SpecDirs) == 0 {
cfg.CDI.SpecDirs = appdefaults.CDISpecDirs
}
}
// isRootlessConfig is true if we should be using the rootless config
@@ -619,6 +638,14 @@ func applyMainFlags(c *cli.Context, cfg *config.Config) error {
cfg.OTEL.SocketPath = c.String("otel-socket-path")
}
if c.IsSet("cdi-enabled") {
cdiEnabled := c.Bool("cdi-enabled")
cfg.CDI.Enabled = &cdiEnabled
}
if c.IsSet("cdi-spec-dir") {
cfg.CDI.SpecDirs = c.StringSlice("cdi-spec-dir")
}
applyPlatformFlags(c)
return nil

View File

@@ -46,6 +46,13 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
# OTEL collector trace socket path
socketPath = "/run/buildkit/otel-grpc.sock"
[cdi]
# Enables support of the Container Device Interface (CDI).
enabled = true
# List of directories to scan for CDI spec files. For more details about CDI
# specification, please refer to https://github.com/cncf-tags/container-device-interface/blob/main/SPEC.md#cdi-json-specification
specDirs = ["/etc/cdi", "/var/run/cdi"]
# config for build history API that stores information about completed build commands
[history]
# maxAge is the maximum age of history entries to keep, in seconds.

2
go.mod
View File

@@ -107,6 +107,7 @@ require (
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1
google.golang.org/protobuf v1.35.2
kernel.org/pub/linux/libs/security/libcap/cap v1.2.73
tags.cncf.io/container-device-interface v0.8.0
)
require (
@@ -183,7 +184,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
kernel.org/pub/linux/libs/security/libcap/psx v1.2.73 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
tags.cncf.io/container-device-interface v0.8.0 // indirect
tags.cncf.io/container-device-interface/specs-go v0.8.0 // indirect
)

View File

@@ -17,6 +17,7 @@ const (
var (
UserCNIConfigPath = filepath.Join(UserConfigDir(), "cni.json")
CDISpecDirs = []string{"/etc/buildkit/cdi"}
)
// UserAddress typically returns /run/user/$UID/buildkit/buildkitd.sock

View File

@@ -18,6 +18,7 @@ var (
var (
UserCNIConfigPath = DefaultCNIConfigPath
CDISpecDirs []string
)
func UserAddress() string {