Skip to content

Commit 5703f41

Browse files
authored
Merge pull request #3197 from Random-Liu/add-required-plugins
Add support for required plugins.
2 parents 475619c + 4b3b99e commit 5703f41

5 files changed

Lines changed: 25 additions & 0 deletions

File tree

cmd/containerd/command/config_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ func defaultConfig() *srvconfig.Config {
3030
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
3131
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
3232
},
33+
DisabledPlugins: []string{},
34+
RequiredPlugins: []string{},
3335
}
3436
}

cmd/containerd/command/config_unsupported.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ func defaultConfig() *srvconfig.Config {
3434
Level: "info",
3535
Address: defaults.DefaultDebugAddress,
3636
},
37+
DisabledPlugins: []string{},
38+
RequiredPlugins: []string{},
3739
}
3840
}

cmd/containerd/command/config_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ func defaultConfig() *srvconfig.Config {
3030
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
3131
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
3232
},
33+
DisabledPlugins: []string{},
34+
RequiredPlugins: []string{},
3335
}
3436
}

services/server/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type Config struct {
3939
// DisabledPlugins are IDs of plugins to disable. Disabled plugins won't be
4040
// initialized and started.
4141
DisabledPlugins []string `toml:"disabled_plugins"`
42+
// RequiredPlugins are IDs of required plugins. Containerd exits if any
43+
// required plugin doesn't exist or fails to be initialized or started.
44+
RequiredPlugins []string `toml:"required_plugins"`
4245
// Plugins provides plugin specific configuration for the initialization of a plugin
4346
Plugins map[string]toml.Primitive `toml:"plugins"`
4447
// OOMScore adjust the containerd's oom score

services/server/server.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
107107
config: config,
108108
}
109109
initialized = plugin.NewPluginSet()
110+
required = make(map[string]struct{})
110111
)
112+
for _, r := range config.RequiredPlugins {
113+
required[r] = struct{}{}
114+
}
111115
for _, p := range plugins {
112116
id := p.URI()
113117
log.G(ctx).WithField("type", p.Type).Infof("loading plugin %q...", id)
@@ -142,8 +146,12 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
142146
} else {
143147
log.G(ctx).WithError(err).Warnf("failed to load plugin %s", id)
144148
}
149+
if _, ok := required[p.ID]; ok {
150+
return nil, errors.Wrapf(err, "load required plugin %s", id)
151+
}
145152
continue
146153
}
154+
delete(required, p.ID)
147155
// check for grpc services that should be registered with the server
148156
if src, ok := instance.(plugin.Service); ok {
149157
grpcServices = append(grpcServices, src)
@@ -153,6 +161,14 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
153161
}
154162
s.plugins = append(s.plugins, result)
155163
}
164+
if len(required) != 0 {
165+
var missing []string
166+
for id := range required {
167+
missing = append(missing, id)
168+
}
169+
return nil, errors.Errorf("required plugin %s not included", missing)
170+
}
171+
156172
// register services after all plugins have been initialized
157173
for _, service := range grpcServices {
158174
if err := service.Register(grpcServer); err != nil {

0 commit comments

Comments
 (0)