Merge pull request #2859 from crosbymichael/shim-config
Add shim config for shim binary options
This commit is contained in:
commit
f05672357f
@ -62,6 +62,17 @@ type Opts struct {
|
|||||||
Debug bool
|
Debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BinaryOpts allows the configuration of a shims binary setup
|
||||||
|
type BinaryOpts func(*Config)
|
||||||
|
|
||||||
|
// Config of shim binary options provided by shim implementations
|
||||||
|
type Config struct {
|
||||||
|
// NoSubreaper disables setting the shim as a child subreaper
|
||||||
|
NoSubreaper bool
|
||||||
|
// NoReaper disables the shim binary from reaping any child process implicitly
|
||||||
|
NoReaper bool
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
debugFlag bool
|
debugFlag bool
|
||||||
idFlag string
|
idFlag string
|
||||||
@ -118,27 +129,34 @@ func setLogger(ctx context.Context, id string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run initializes and runs a shim server
|
// Run initializes and runs a shim server
|
||||||
func Run(id string, initFunc Init) {
|
func Run(id string, initFunc Init, opts ...BinaryOpts) {
|
||||||
if err := run(id, initFunc); err != nil {
|
var config Config
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&config)
|
||||||
|
}
|
||||||
|
if err := run(id, initFunc, config); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%s: %s\n", id, err)
|
fmt.Fprintf(os.Stderr, "%s: %s\n", id, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(id string, initFunc Init) error {
|
func run(id string, initFunc Init, config Config) error {
|
||||||
parseFlags()
|
parseFlags()
|
||||||
setRuntime()
|
setRuntime()
|
||||||
|
|
||||||
signals, err := setupSignals()
|
signals, err := setupSignals(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := subreaper(); err != nil {
|
if !config.NoSubreaper {
|
||||||
return err
|
if err := subreaper(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
publisher := &remoteEventsPublisher{
|
publisher := &remoteEventsPublisher{
|
||||||
address: addressFlag,
|
address: addressFlag,
|
||||||
containerdBinaryPath: containerdBinaryFlag,
|
containerdBinaryPath: containerdBinaryFlag,
|
||||||
|
noReaper: config.NoReaper,
|
||||||
}
|
}
|
||||||
if namespaceFlag == "" {
|
if namespaceFlag == "" {
|
||||||
return fmt.Errorf("shim namespace cannot be empty")
|
return fmt.Errorf("shim namespace cannot be empty")
|
||||||
@ -266,4 +284,5 @@ func dumpStacks(logger *logrus.Entry) {
|
|||||||
type remoteEventsPublisher struct {
|
type remoteEventsPublisher struct {
|
||||||
address string
|
address string
|
||||||
containerdBinaryPath string
|
containerdBinaryPath string
|
||||||
|
noReaper bool
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,13 @@ import (
|
|||||||
|
|
||||||
// setupSignals creates a new signal handler for all signals and sets the shim as a
|
// setupSignals creates a new signal handler for all signals and sets the shim as a
|
||||||
// sub-reaper so that the container processes are reparented
|
// sub-reaper so that the container processes are reparented
|
||||||
func setupSignals() (chan os.Signal, error) {
|
func setupSignals(config Config) (chan os.Signal, error) {
|
||||||
signals := make(chan os.Signal, 32)
|
signals := make(chan os.Signal, 32)
|
||||||
signal.Notify(signals, unix.SIGTERM, unix.SIGINT, unix.SIGCHLD, unix.SIGPIPE)
|
smp := []os.Signal{unix.SIGTERM, unix.SIGINT, unix.SIGPIPE}
|
||||||
|
if !config.NoReaper {
|
||||||
|
smp = append(smp, unix.SIGCHLD)
|
||||||
|
}
|
||||||
|
signal.Notify(signals, smp...)
|
||||||
return signals, nil
|
return signals, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +106,15 @@ func (l *remoteEventsPublisher) Publish(ctx context.Context, topic string, event
|
|||||||
}
|
}
|
||||||
cmd := exec.CommandContext(ctx, l.containerdBinaryPath, "--address", l.address, "publish", "--topic", topic, "--namespace", ns)
|
cmd := exec.CommandContext(ctx, l.containerdBinaryPath, "--address", l.address, "publish", "--topic", topic, "--namespace", ns)
|
||||||
cmd.Stdin = bytes.NewReader(data)
|
cmd.Stdin = bytes.NewReader(data)
|
||||||
|
if l.noReaper {
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to publish event")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
c, err := Default.Start(cmd)
|
c, err := Default.Start(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -40,7 +40,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// setupSignals creates a new signal handler for all signals
|
// setupSignals creates a new signal handler for all signals
|
||||||
func setupSignals() (chan os.Signal, error) {
|
func setupSignals(config Config) (chan os.Signal, error) {
|
||||||
signals := make(chan os.Signal, 32)
|
signals := make(chan os.Signal, 32)
|
||||||
return signals, nil
|
return signals, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user