Skip to content

Commit 2a7c1cc

Browse files
committed
libcontainerd/supervisor: replace BurntSushi/toml with pelletier/go-toml
Taking the same approach as was taken in containerd The new library has a slightly different output; - keys at the same level are sorted alphabetically - empty sections not omitted (`proxy_plugins`, `stream_processors`, `timeouts`), which could possibly be be addressed with an "omitempty" in containerd's struct. - empty slices are not omitted (`imports`, `required_plugins`) After sorting the "before" configuration the diff looks like this: ```patch diff --git a/config-before-sorted.toml b/config-after.toml index cc771ce7ab..43a727f589 100644 --- a/config-before-sorted.toml +++ b/config-after.toml @@ -1,6 +1,8 @@ disabled_plugins = ["cri"] +imports = [] oom_score = 0 plugin_dir = "" +required_plugins = [] root = "/var/lib/docker/containerd/daemon" state = "/var/run/docker/containerd/daemon" version = 0 @@ -37,6 +39,12 @@ version = 0 shim = "containerd-shim" shim_debug = true +[proxy_plugins] + +[stream_processors] + +[timeouts] + [ttrpc] address = "" gid = 0 ``` Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 1d4a273 commit 2a7c1cc

File tree

19 files changed

+4569
-19
lines changed

19 files changed

+4569
-19
lines changed

libcontainerd/supervisor/remote_daemon.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
"sync"
1414
"time"
1515

16-
"github.com/BurntSushi/toml"
1716
"github.com/containerd/containerd"
1817
"github.com/containerd/containerd/services/server/config"
1918
"github.com/docker/docker/pkg/system"
19+
"github.com/pelletier/go-toml"
2020
"github.com/pkg/errors"
2121
"github.com/sirupsen/logrus"
2222
)
@@ -31,13 +31,11 @@ const (
3131
pidFile = "containerd.pid"
3232
)
3333

34-
type pluginConfigs struct {
35-
Plugins map[string]interface{} `toml:"plugins"`
36-
}
37-
3834
type remote struct {
3935
sync.RWMutex
4036
config.Config
37+
// Plugins overrides `Plugins map[string]toml.Tree` in config config.
38+
Plugins map[string]interface{} `toml:"plugins"`
4139

4240
daemonPid int
4341
logger *logrus.Entry
@@ -46,9 +44,8 @@ type remote struct {
4644
daemonStartCh chan error
4745
daemonStopCh chan struct{}
4846

49-
rootDir string
50-
stateDir string
51-
pluginConfs pluginConfigs
47+
rootDir string
48+
stateDir string
5249
}
5350

5451
// Daemon represents a running containerd daemon
@@ -69,7 +66,7 @@ func Start(ctx context.Context, rootDir, stateDir string, opts ...DaemonOpt) (Da
6966
Root: filepath.Join(rootDir, "daemon"),
7067
State: filepath.Join(stateDir, "daemon"),
7168
},
72-
pluginConfs: pluginConfigs{make(map[string]interface{})},
69+
Plugins: make(map[string]interface{}),
7370
daemonPid: -1,
7471
logger: logrus.WithField("module", "libcontainerd"),
7572
daemonStartCh: make(chan error, 1),
@@ -157,14 +154,9 @@ func (r *remote) getContainerdConfig() (string, error) {
157154
}
158155
defer f.Close()
159156

160-
enc := toml.NewEncoder(f)
161-
if err = enc.Encode(r.Config); err != nil {
162-
return "", errors.Wrapf(err, "failed to encode general config")
163-
}
164-
if err = enc.Encode(r.pluginConfs); err != nil {
165-
return "", errors.Wrapf(err, "failed to encode plugin configs")
157+
if err := toml.NewEncoder(f).Encode(r); err != nil {
158+
return "", errors.Wrapf(err, "failed to write containerd config file (%s)", path)
166159
}
167-
168160
return path, nil
169161
}
170162

libcontainerd/supervisor/remote_daemon_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ func (r *remote) setDefaults() {
2929
r.Debug.Address = filepath.Join(r.stateDir, debugSockFile)
3030
}
3131

32-
for key, conf := range r.pluginConfs.Plugins {
32+
for key, conf := range r.Plugins {
3333
if conf == nil {
3434
r.DisabledPlugins = append(r.DisabledPlugins, key)
35-
delete(r.pluginConfs.Plugins, key)
35+
delete(r.Plugins, key)
3636
}
3737
}
3838
}

libcontainerd/supervisor/remote_daemon_options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func WithMetricsAddress(addr string) DaemonOpt {
4949
// the toml format.
5050
func WithPlugin(name string, conf interface{}) DaemonOpt {
5151
return func(r *remote) error {
52-
r.pluginConfs.Plugins[name] = conf
52+
r.Plugins[name] = conf
5353
return nil
5454
}
5555
}

vendor.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ github.com/containerd/typeurl cd3ce7159eae562a4f60ceff37da
139139
github.com/containerd/ttrpc bfba540dc45464586c106b1f31c8547933c1eb41 # v1.0.2
140140
github.com/gogo/googleapis 01e0f9cca9b92166042241267ee2a5cdf5cff46c # v1.3.2
141141
github.com/cilium/ebpf 1c8d4c9ef7759622653a1d319284a44652333b28
142+
github.com/pelletier/go-toml 65ca8064882c8c308e5c804c5d5443d409e0738c # v1.8.1
142143

143144
# cluster
144145
github.com/docker/swarmkit 17d8d4e4d8bdec33d386e6362d3537fa9493ba00

vendor/github.com/pelletier/go-toml/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pelletier/go-toml/README.md

Lines changed: 151 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pelletier/go-toml/doc.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pelletier/go-toml/fuzz.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pelletier/go-toml/go.mod

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)