Commit e8273249 authored by Michael Schurter's avatar Michael Schurter Committed by Alex Dadgar
Browse files

Add Network method to Handle interface

Should probably be moved to an Inspect method in the Driver Plugin world
parent b972153e
Showing with 49 additions and 9 deletions
+49 -9
......@@ -500,6 +500,7 @@ type DockerHandle struct {
waitCh chan *dstructs.WaitResult
doneCh chan bool
removeContainerOnExit bool
net *cstructs.DriverNetwork
}
func NewDockerDriver(ctx *DriverContext) Driver {
......@@ -908,6 +909,15 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (*StartRespon
container.ID, container.State.String())
}
// Detect container address
ip, autoUse := d.detectIP(container)
net := &cstructs.DriverNetwork{
PortMap: d.driverConfig.PortMap,
IP: ip,
AutoAdvertise: autoUse,
}
// Return a driver handle
maxKill := d.DriverContext.config.MaxKillTimeout
h := &DockerHandle{
......@@ -928,22 +938,17 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (*StartRespon
doneCh: make(chan bool),
waitCh: make(chan *dstructs.WaitResult, 1),
removeContainerOnExit: d.config.ReadBoolDefault(dockerCleanupContainerConfigOption, dockerCleanupContainerConfigDefault),
net: net,
}
go h.collectStats()
go h.run()
// Detect container address
ip, autoUse := d.detectIP(container)
// Create a response with the driver handle and container network metadata
resp := &StartResponse{
Handle: h,
Network: &cstructs.DriverNetwork{
PortMap: d.driverConfig.PortMap,
IP: ip,
AutoAdvertise: autoUse,
},
Handle: h,
Network: net,
}
return resp, nil
}
......@@ -1811,6 +1816,7 @@ func (d *DockerDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, er
maxKillTimeout: pid.MaxKillTimeout,
doneCh: make(chan bool),
waitCh: make(chan *dstructs.WaitResult, 1),
net: nil, //FIXME Need to get driver network
}
go h.collectStats()
go h.run()
......@@ -1843,6 +1849,10 @@ func (h *DockerHandle) WaitCh() chan *dstructs.WaitResult {
return h.waitCh
}
func (h *DockerHandle) Network() *cstructs.DriverNetwork {
return h.net
}
func (h *DockerHandle) Update(task *structs.Task) error {
// Store the updated kill timeout.
h.killTimeout = GetKillTimeout(task.KillTimeout, h.maxKillTimeout)
......
......@@ -320,6 +320,10 @@ type DriverHandle interface {
// ScriptExecutor is an interface used to execute commands such as
// health check scripts in the a DriverHandle's context.
ScriptExecutor
// Network returns the driver's network or nil if the driver did not
// create a network.
Network() *cstructs.DriverNetwork
}
// ScriptExecutor is an interface that supports Exec()ing commands in the
......
......@@ -270,6 +270,10 @@ func (h *execHandle) Signal(s os.Signal) error {
return h.executor.Signal(s)
}
func (d *execHandle) Network() *cstructs.DriverNetwork {
return nil
}
func (h *execHandle) Kill() error {
if err := h.executor.ShutDown(); err != nil {
if h.pluginClient.Exited() {
......
......@@ -408,6 +408,10 @@ func (h *javaHandle) Signal(s os.Signal) error {
return h.executor.Signal(s)
}
func (d *javaHandle) Network() *cstructs.DriverNetwork {
return nil
}
func (h *javaHandle) Kill() error {
if err := h.executor.ShutDown(); err != nil {
if h.pluginClient.Exited() {
......
......@@ -372,6 +372,11 @@ func (h *mockDriverHandle) Update(task *structs.Task) error {
return nil
}
// TODO Implement when we need it.
func (d *mockDriverHandle) Network() *cstructs.DriverNetwork {
return nil
}
// TODO Implement when we need it.
func (h *mockDriverHandle) Signal(s os.Signal) error {
return h.signalErr
......
......@@ -451,6 +451,10 @@ func (h *qemuHandle) Signal(s os.Signal) error {
return fmt.Errorf("Qemu driver can't send signals")
}
func (d *qemuHandle) Network() *cstructs.DriverNetwork {
return nil
}
func (h *qemuHandle) Kill() error {
gracefulShutdownSent := false
// Attempt a graceful shutdown only if it was configured in the job
......
......@@ -299,6 +299,10 @@ func (h *rawExecHandle) Signal(s os.Signal) error {
return h.executor.Signal(s)
}
func (d *rawExecHandle) Network() *cstructs.DriverNetwork {
return nil
}
func (h *rawExecHandle) Kill() error {
if err := h.executor.ShutDown(); err != nil {
if h.pluginClient.Exited() {
......
......@@ -815,6 +815,11 @@ func (h *rktHandle) Signal(s os.Signal) error {
return fmt.Errorf("Rkt does not support signals")
}
//FIXME implement
func (d *rktHandle) Network() *cstructs.DriverNetwork {
return nil
}
// Kill is used to terminate the task. We send an Interrupt
// and then provide a 5 second grace period before doing a Kill.
func (h *rktHandle) Kill() error {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment