Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #46 from dweomer/buildkit/cni-config
Browse files Browse the repository at this point in the history
buildkit: slave config to values from cri and k3c
  • Loading branch information
dweomer authored May 13, 2020
2 parents 8050e06 + 87a73ab commit 3166266
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
8 changes: 0 additions & 8 deletions cmd/daemon/daemon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
criconfig "github.com/containerd/cri/pkg/config"
"github.com/rancher/k3c/pkg/daemon"
"github.com/rancher/k3c/pkg/daemon/config"
"github.com/rancher/k3c/pkg/daemon/services/buildkit"
"github.com/sirupsen/logrus"
cliv1 "github.com/urfave/cli"
cliv2 "github.com/urfave/cli/v2"
Expand Down Expand Up @@ -189,10 +188,6 @@ the backend to support the Docker work-alike frontend of k3c.`
Type: plugin.RuntimeRuncV2,
},
}
buildkit.Config.Workers.Containerd.NetworkConfig.Mode = "cni"
buildkit.Config.Workers.Containerd.NetworkConfig.CNIBinaryPath = cri.Config.NetworkPluginBinDir
buildkit.Config.Workers.Containerd.NetworkConfig.CNIConfigPath = filepath.Join(cri.Config.NetworkPluginConfDir, "90-k3c.json")

if err := os.MkdirAll(cri.Config.NetworkPluginBinDir, 0700); err != nil {
return err
}
Expand All @@ -211,9 +206,6 @@ the backend to support the Docker work-alike frontend of k3c.`
if err := os.MkdirAll(cri.Config.NetworkPluginConfDir, 0700); err != nil {
return err
}
if err := config.WriteFileJSON(buildkit.Config.Workers.Containerd.NetworkConfig.CNIConfigPath, config.DefaultCniConf(daemon.Config.BridgeName, daemon.Config.BridgeCIDR), 0600); err != nil {
return err
}
if err := config.WriteFileJSON(filepath.Join(cri.Config.NetworkPluginConfDir, "90-k3c.conflist"), config.DefaultCniConflist(daemon.Config.BridgeName, daemon.Config.BridgeCIDR), 0600); err != nil {
return err
}
Expand Down
24 changes: 6 additions & 18 deletions pkg/daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (

"github.com/BurntSushi/toml"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/plugin"
cri "github.com/containerd/cri/pkg/config"
buildkit "github.com/moby/buildkit/cmd/buildkitd/config"
"github.com/rancher/k3c/pkg/defaults"
)
Expand All @@ -31,13 +29,12 @@ var (
)

type K3Config struct {
BootstrapSkip bool `toml:"bootstrap_skip"`
BootstrapImage string `toml:"bootstrap_image"`
BridgeName string `toml:"bridge_name"`
BridgeCIDR string `toml:"bridge_cidr"`
PodLogs string `toml:"pod_logs"`
Volumes string `toml:"volumes"`
CRI cri.PluginConfig `toml:"cri"`
BootstrapSkip bool `toml:"bootstrap_skip"`
BootstrapImage string `toml:"bootstrap_image"`
BridgeName string `toml:"bridge_name"`
BridgeCIDR string `toml:"bridge_cidr"`
PodLogs string `toml:"pod_logs"`
Volumes string `toml:"volumes"`
}

func DefaultBuildkitConfig() *buildkit.Config {
Expand All @@ -61,16 +58,7 @@ func DefaultK3Config() *K3Config {
BootstrapImage: DefaultBootstrapImage,
PodLogs: DefaultPodLogsDir,
Volumes: DefaultVolumesDir,
CRI: cri.DefaultConfig(),
}
config.CRI.SandboxImage = DefaultSandboxImage
config.CRI.DefaultRuntimeName = "runc"
config.CRI.Runtimes = map[string]cri.Runtime{
config.CRI.DefaultRuntimeName: {
Type: plugin.RuntimeRuncV2,
},
}
config.CRI.NetworkPluginMaxConfNum = 1
return config
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func PluginInitFunc(ic *plugin.InitContext) (interface{}, error) {
log.G(ic.Context).Debugf("K3C config %+v", *cfg)

// exports
ic.Meta.Exports["K3CVersion"] = "v1alpha1"
ic.Meta.Exports["api-version"] = "v1alpha1"
ic.Meta.Exports["bridge-name"] = cfg.BridgeName
ic.Meta.Exports["bridge-cidr"] = cfg.BridgeCIDR
ic.Meta.Exports["pod-logs-dir"] = cfg.PodLogs
Expand Down
1 change: 0 additions & 1 deletion pkg/daemon/services/buildkit/containerd_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func newContainerdWorkerOpt(ic *plugin.InitContext) (base.WorkerOpt, error) {

client, err := containerd.New("",
containerd.WithDefaultNamespace(cfg.Workers.Containerd.Namespace),
containerd.WithDefaultRuntime(plugin.RuntimeLinuxV1),
containerd.WithServices(servicesOpts...),
)
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions pkg/daemon/services/buildkit/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/plugin"
"github.com/containerd/cri"
"github.com/moby/buildkit/cache/remotecache"
inlineremotecache "github.com/moby/buildkit/cache/remotecache/inline"
localremotecache "github.com/moby/buildkit/cache/remotecache/local"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/moby/buildkit/solver/bboltcachestorage"
"github.com/moby/buildkit/worker"
"github.com/moby/buildkit/worker/base"
"github.com/pkg/errors"
"github.com/rancher/k3c/pkg/daemon/config"
)

Expand Down Expand Up @@ -47,6 +49,8 @@ func PluginInitFunc(ic *plugin.InitContext) (interface{}, error) {
).Info("BuildKit init")
cfg := ic.Config.(*buildkit.Config)
cfg.Workers.Containerd.Address = ic.Address
cfg.Workers.Containerd.NetworkConfig.CNIBinaryPath = cri.Config.NetworkPluginBinDir
cfg.Workers.Containerd.NetworkConfig.CNIConfigPath = filepath.Join(cri.Config.NetworkPluginConfDir, "90-k3c.json")
cfg.Root = ic.Root
log.G(ic.Context).Debugf("BuildKit config %+v", *cfg)

Expand All @@ -58,6 +62,25 @@ func PluginInitFunc(ic *plugin.InitContext) (interface{}, error) {
ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
}

plugins, err := ic.GetByType(plugin.GRPCPlugin)
if err != nil {
return nil, err
}
k3cPlugin, ok := plugins["k3c"]
if !ok {
return nil, errors.New("failed to find k3c plugin")
}
var bridgeName, bridgeCIDR string
if bridgeName, ok = k3cPlugin.Meta.Exports["bridge-name"]; !ok {
bridgeName = config.DefaultBridgeName
}
if bridgeCIDR, ok = k3cPlugin.Meta.Exports["bridge-cidr"]; !ok {
bridgeCIDR = config.DefaultBridgeCIDR
}
if err := config.WriteFileJSON(cfg.Workers.Containerd.NetworkConfig.CNIConfigPath, config.DefaultCniConf(bridgeName, bridgeCIDR), 0600); err != nil {
return nil, err
}

controllerOpt := control.Opt{
WorkerController: &worker.Controller{},
Entitlements: cfg.Entitlements,
Expand Down

0 comments on commit 3166266

Please sign in to comment.