Make await timeout configurable

pull/20/head
Jack O'Sullivan 3 years ago
parent 7981235453
commit f5faea00b6

@ -4,6 +4,7 @@ import (
"flag"
"os"
"os/signal"
"time"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
@ -42,7 +43,15 @@ func main() {
log.StandardLogger().Out = f
}
p, err := plugin.NewPlugin()
awaitTimeout := 5 * time.Second
if t, ok := os.LookupEnv("AWAIT_TIMEOUT"); ok {
awaitTimeout, err = time.ParseDuration(t)
if err != nil {
log.WithError(err).Fatal("Failed to parse await timeout")
}
}
p, err := plugin.NewPlugin(awaitTimeout)
if err != nil {
log.WithError(err).Fatal("Failed to create plugin")
}

@ -15,6 +15,14 @@
"settable": [
"value"
]
},
{
"description": "Log level",
"name": "AWAIT_TIMEOUT",
"value": "10s",
"settable": [
"value"
]
}
],
"workdir": "/",

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net"
"time"
dTypes "github.com/docker/docker/api/types"
"github.com/mitchellh/mapstructure"
@ -441,8 +440,7 @@ func (p *Plugin) Join(ctx context.Context, r JoinRequest) (JoinResponse, error)
}
go func() {
// TODO: Make timeout configurable?
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), p.awaitTimeout)
defer cancel()
m := newDHCPManager(p.docker, r, opts)

@ -55,6 +55,8 @@ type joinHint struct {
// Plugin is the DHCP network plugin
type Plugin struct {
awaitTimeout time.Duration
docker *docker.Client
server http.Server
@ -63,13 +65,15 @@ type Plugin struct {
}
// NewPlugin creates a new Plugin
func NewPlugin() (*Plugin, error) {
func NewPlugin(awaitTimeout time.Duration) (*Plugin, error) {
client, err := docker.NewClient("unix:///run/docker.sock", "v1.13.1", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to create docker client: %w", err)
}
p := Plugin{
awaitTimeout: awaitTimeout,
docker: client,
joinHints: make(map[string]joinHint),

Loading…
Cancel
Save