func (pm *Manager) restorePlugin(p *v2.Plugin) error { p.RuntimeSourcePath = filepath.Join(pm.runRoot, p.GetID()) if p.IsEnabled() { return pm.restore(p) } return nil }
func (pm *Manager) enable(p *v2.Plugin, force bool) error { if p.IsEnabled() && !force { return fmt.Errorf("plugin %s is already enabled", p.Name()) } spec, err := p.InitSpec(oci.DefaultSpec(), pm.libRoot) if err != nil { return err } p.RestartManager = restartmanager.New(container.RestartPolicy{Name: "always"}, 0) if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec), libcontainerd.WithRestartManager(p.RestartManager)); err != nil { if err := p.RestartManager.Cancel(); err != nil { logrus.Errorf("enable: restartManager.Cancel failed due to %v", err) } return err } p.PClient, err = plugins.NewClient("unix://"+filepath.Join(p.RuntimeSourcePath, p.GetSocket()), nil) if err != nil { if err := p.RestartManager.Cancel(); err != nil { logrus.Errorf("enable: restartManager.Cancel failed due to %v", err) } return err } pm.pluginStore.SetState(p, true) pm.pluginStore.CallHandler(p) return nil }
func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error { if p.IsEnabled() && !force { return fmt.Errorf("plugin %s is already enabled", p.Name()) } spec, err := p.InitSpec(oci.DefaultSpec(), pm.libRoot) if err != nil { return err } c.restart = true c.exitChan = make(chan bool) pm.mu.Lock() pm.cMap[p] = c pm.mu.Unlock() if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec), attachToLog(p.GetID())); err != nil { return err } client, err := plugins.NewClientWithTimeout("unix://"+filepath.Join(p.GetRuntimeSourcePath(), p.GetSocket()), nil, c.timeoutInSecs) if err != nil { c.restart = false shutdownPlugin(p, c, pm.containerdClient) return err } p.SetPClient(client) pm.pluginStore.SetState(p, true) pm.pluginStore.CallHandler(p) return nil }
func (pm *Manager) restorePlugin(p *v2.Plugin) error { p.Restore(pm.runRoot) if p.IsEnabled() { return pm.restore(p) } return nil }
// Get returns an enabled plugin matching the given name and capability. func (ps *Store) Get(name, capability string, mode int) (plugingetter.CompatPlugin, error) { var ( p *v2.Plugin err error ) // Lookup using new model. if ps != nil { p, err = ps.GetV2Plugin(name) if err == nil { p.AddRefCount(mode) if p.IsEnabled() { return p.FilterByCap(capability) } // Plugin was found but it is disabled, so we should not fall back to legacy plugins // but we should error out right away return nil, ErrNotFound(name) } if _, ok := errors.Cause(err).(ErrNotFound); !ok { return nil, err } } // Lookup using legacy model. if allowV1PluginsFallback { p, err := plugins.Get(name, capability) if err != nil { return nil, fmt.Errorf("legacy plugin: %v", err) } return p, nil } return nil, err }
func (pm *Manager) enable(p *v2.Plugin, force bool) error { if p.IsEnabled() && !force { return fmt.Errorf("plugin %s is already enabled", p.Name()) } spec, err := p.InitSpec(oci.DefaultSpec(), pm.libRoot) if err != nil { return err } p.Lock() p.Restart = true p.Unlock() if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec)); err != nil { return err } p.PClient, err = plugins.NewClient("unix://"+filepath.Join(p.RuntimeSourcePath, p.GetSocket()), nil) if err != nil { p.Lock() p.Restart = false p.Unlock() return err } pm.pluginStore.SetState(p, true) pm.pluginStore.CallHandler(p) return nil }
func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error { p.Rootfs = filepath.Join(pm.libRoot, p.PluginObj.ID, "rootfs") if p.IsEnabled() && !force { return fmt.Errorf("plugin %s is already enabled", p.Name()) } spec, err := p.InitSpec(oci.DefaultSpec()) if err != nil { return err } c.restart = true c.exitChan = make(chan bool) pm.mu.Lock() pm.cMap[p] = c pm.mu.Unlock() if p.PropagatedMount != "" { if err := mount.MakeRShared(p.PropagatedMount); err != nil { return err } } if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec), attachToLog(p.GetID())); err != nil { if p.PropagatedMount != "" { if err := mount.Unmount(p.PropagatedMount); err != nil { logrus.Warnf("Could not unmount %s: %v", p.PropagatedMount, err) } } return err } return pm.pluginPostStart(p, c) }
func (pm *Manager) disable(p *v2.Plugin, c *controller) error { if !p.IsEnabled() { return fmt.Errorf("plugin %s is already disabled", p.Name()) } c.restart = false shutdownPlugin(p, c, pm.containerdClient) pm.pluginStore.SetState(p, false) return nil }
func (pm *Manager) disable(p *v2.Plugin) error { if !p.IsEnabled() { return fmt.Errorf("plugin %s is already disabled", p.Name()) } p.Lock() p.Restart = false p.Unlock() shutdownPlugin(p, pm.containerdClient) pm.pluginStore.SetState(p, false) return nil }
func (pm *Manager) disable(p *v2.Plugin) error { if !p.IsEnabled() { return fmt.Errorf("plugin %s is already disabled", p.Name()) } p.Lock() p.Restart = false p.Unlock() if err := pm.containerdClient.Signal(p.GetID(), int(syscall.SIGKILL)); err != nil { logrus.Error(err) } pm.pluginStore.SetState(p, false) return nil }
// Get returns an enabled plugin matching the given name and capability. func (ps *Store) Get(name, capability string, mode int) (plugingetter.CompatPlugin, error) { var ( p *v2.Plugin err error ) // Lookup using new model. if ps != nil { fullName := name if named, err := reference.ParseNamed(fullName); err == nil { // FIXME: validate if reference.IsNameOnly(named) { named = reference.WithDefaultTag(named) } ref, ok := named.(reference.NamedTagged) if !ok { return nil, fmt.Errorf("invalid name: %s", named.String()) } fullName = ref.String() } p, err = ps.GetByName(fullName) if err == nil { p.Lock() p.RefCount += mode p.Unlock() if p.IsEnabled() { return p.FilterByCap(capability) } // Plugin was found but it is disabled, so we should not fall back to legacy plugins // but we should error out right away return nil, ErrNotFound(fullName) } if _, ok := err.(ErrNotFound); !ok { return nil, err } } // Lookup using legacy model. if allowV1PluginsFallback { p, err := plugins.Get(name, capability) if err != nil { return nil, fmt.Errorf("legacy plugin: %v", err) } return p, nil } return nil, err }