Make await timeout configurable

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

@ -4,6 +4,7 @@ import (
"flag" "flag"
"os" "os"
"os/signal" "os/signal"
"time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -42,7 +43,15 @@ func main() {
log.StandardLogger().Out = f 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 { if err != nil {
log.WithError(err).Fatal("Failed to create plugin") log.WithError(err).Fatal("Failed to create plugin")
} }

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

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

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

Loading…
Cancel
Save