plugin: Executor.Signal() accept syscall.Signal
This helps reducing some type-juggling / conversions further up the stack. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
21df9a04e0
commit
521807837b
4 changed files with 25 additions and 35 deletions
|
@ -113,8 +113,8 @@ func (e *Executor) IsRunning(id string) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal sends the specified signal to the container
|
// Signal sends the specified signal to the container
|
||||||
func (e *Executor) Signal(id string, signal int) error {
|
func (e *Executor) Signal(id string, signal syscall.Signal) error {
|
||||||
return e.client.SignalProcess(context.Background(), id, libcontainerdtypes.InitProcessName, syscall.Signal(signal))
|
return e.client.SignalProcess(context.Background(), id, libcontainerdtypes.InitProcessName, signal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessEvent handles events from containerd
|
// ProcessEvent handles events from containerd
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
"github.com/containerd/containerd/content/local"
|
"github.com/containerd/containerd/content/local"
|
||||||
|
@ -37,7 +38,7 @@ type Executor interface {
|
||||||
Create(id string, spec specs.Spec, stdout, stderr io.WriteCloser) error
|
Create(id string, spec specs.Spec, stdout, stderr io.WriteCloser) error
|
||||||
IsRunning(id string) (bool, error)
|
IsRunning(id string) (bool, error)
|
||||||
Restore(id string, stdout, stderr io.WriteCloser) (alive bool, err error)
|
Restore(id string, stdout, stderr io.WriteCloser) (alive bool, err error)
|
||||||
Signal(id string, signal int) error
|
Signal(id string, signal syscall.Signal) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// EndpointResolver provides looking up registry endpoints for pulling.
|
// EndpointResolver provides looking up registry endpoints for pulling.
|
||||||
|
|
|
@ -154,31 +154,30 @@ const shutdownTimeout = 10 * time.Second
|
||||||
func shutdownPlugin(p *v2.Plugin, ec chan bool, executor Executor) {
|
func shutdownPlugin(p *v2.Plugin, ec chan bool, executor Executor) {
|
||||||
pluginID := p.GetID()
|
pluginID := p.GetID()
|
||||||
|
|
||||||
err := executor.Signal(pluginID, int(unix.SIGTERM))
|
if err := executor.Signal(pluginID, unix.SIGTERM); err != nil {
|
||||||
if err != nil {
|
|
||||||
logrus.Errorf("Sending SIGTERM to plugin failed with error: %v", err)
|
logrus.Errorf("Sending SIGTERM to plugin failed with error: %v", err)
|
||||||
} else {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
timeout := time.NewTimer(shutdownTimeout)
|
timeout := time.NewTimer(shutdownTimeout)
|
||||||
defer timeout.Stop()
|
defer timeout.Stop()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-ec:
|
||||||
|
logrus.Debug("Clean shutdown of plugin")
|
||||||
|
case <-timeout.C:
|
||||||
|
logrus.Debug("Force shutdown plugin")
|
||||||
|
if err := executor.Signal(pluginID, unix.SIGKILL); err != nil {
|
||||||
|
logrus.Errorf("Sending SIGKILL to plugin failed with error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout.Reset(shutdownTimeout)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ec:
|
case <-ec:
|
||||||
logrus.Debug("Clean shutdown of plugin")
|
logrus.Debug("SIGKILL plugin shutdown")
|
||||||
case <-timeout.C:
|
case <-timeout.C:
|
||||||
logrus.Debug("Force shutdown plugin")
|
logrus.WithField("plugin", p.Name).Warn("Force shutdown plugin FAILED")
|
||||||
if err := executor.Signal(pluginID, int(unix.SIGKILL)); err != nil {
|
|
||||||
logrus.Errorf("Sending SIGKILL to plugin failed with error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout.Reset(shutdownTimeout)
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-ec:
|
|
||||||
logrus.Debug("SIGKILL plugin shutdown")
|
|
||||||
case <-timeout.C:
|
|
||||||
logrus.WithField("plugin", p.Name).Warn("Force shutdown plugin FAILED")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
@ -87,24 +88,13 @@ func newTestPlugin(t *testing.T, name, cap, root string) *v2.Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
type simpleExecutor struct {
|
type simpleExecutor struct {
|
||||||
|
Executor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *simpleExecutor) Create(id string, spec specs.Spec, stdout, stderr io.WriteCloser) error {
|
func (e *simpleExecutor) Create(id string, spec specs.Spec, stdout, stderr io.WriteCloser) error {
|
||||||
return errors.New("Create failed")
|
return errors.New("Create failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *simpleExecutor) Restore(id string, stdout, stderr io.WriteCloser) (bool, error) {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *simpleExecutor) IsRunning(id string) (bool, error) {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *simpleExecutor) Signal(id string, signal int) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateFailed(t *testing.T) {
|
func TestCreateFailed(t *testing.T) {
|
||||||
root, err := os.MkdirTemp("", "test-create-failed")
|
root, err := os.MkdirTemp("", "test-create-failed")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -165,7 +155,7 @@ func (e *executorWithRunning) Restore(id string, stdout, stderr io.WriteCloser)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *executorWithRunning) Signal(id string, signal int) error {
|
func (e *executorWithRunning) Signal(id string, signal syscall.Signal) error {
|
||||||
ch := e.exitChans[id]
|
ch := e.exitChans[id]
|
||||||
ch <- struct{}{}
|
ch <- struct{}{}
|
||||||
<-ch
|
<-ch
|
||||||
|
|
Loading…
Add table
Reference in a new issue