mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #51711 from robmry/nri-config-reload
NRI: config reload
This commit is contained in:
@@ -47,10 +47,10 @@ const (
|
||||
)
|
||||
|
||||
type NRI struct {
|
||||
cfg Config
|
||||
|
||||
// mu protects nri - read lock for container operations, write lock for sync and shutdown.
|
||||
// mu protects cfg and adap
|
||||
// Read lock for container operations, write lock for sync, config update and shutdown.
|
||||
mu sync.RWMutex
|
||||
cfg Config
|
||||
adap *adaptation.Adaptation
|
||||
}
|
||||
|
||||
@@ -123,6 +123,43 @@ func (n *NRI) Shutdown(ctx context.Context) {
|
||||
n.adap = nil
|
||||
}
|
||||
|
||||
// PrepareReload validates and prepares for a configuration reload. It returns
|
||||
// a function to perform the actual reload when called.
|
||||
func (n *NRI) PrepareReload(nriCfg opts.NRIOpts) (func() error, error) {
|
||||
var newNRI *adaptation.Adaptation
|
||||
newCfg := n.cfg
|
||||
newCfg.DaemonConfig = nriCfg
|
||||
if err := setDefaultPaths(&newCfg.DaemonConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if nriCfg.Enable {
|
||||
var err error
|
||||
newNRI, err = adaptation.New("docker", dockerversion.Version, n.syncFn, n.updateFn, nriOptions(newCfg.DaemonConfig)...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return func() error {
|
||||
n.mu.Lock()
|
||||
if n.adap != nil {
|
||||
log.G(context.TODO()).Info("Shutting down old NRI instance")
|
||||
n.adap.Stop()
|
||||
}
|
||||
n.cfg = newCfg
|
||||
n.adap = newNRI
|
||||
// Release the lock before starting newNRI, because it'll call back to syncFn
|
||||
// which will acquire the lock.
|
||||
n.mu.Unlock()
|
||||
|
||||
if newNRI == nil {
|
||||
return nil
|
||||
}
|
||||
return newNRI.Start()
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateContainer notifies plugins of a "creation" NRI-lifecycle event for a container,
|
||||
// allowing the plugin to adjust settings before the container is created.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user