Permalink
Browse files

Add containerd restart plugin over moby services

Signed-off-by: Omar Ramadan <omar.ramadan93@gmail.com>
  • Loading branch information...
kkroo committed Nov 27, 2018
1 parent 36aa581 commit 1d1c8fcee99d58781b90bc646398046d22e286ef
@@ -208,6 +208,7 @@ which specifies some actions to take place when the container is being started.
- `bindNS` specifies a namespace type and a path where the namespace from the container being created will be bound. This allows a namespace to be set up in an `onboot` container, and then
using `net: path` for a `service` container to use that network namespace later.
- `namespace` overrides the LinuxKit default containerd namespace to put the container in; only applicable to services.
- `noRestart` By default, long running services in the `service` section are restarted upon exit. This boolean allows to disabling service restart.

An example of using the `runtime` config to configure a network namespace with `wireguard` and then run `nginx` in that namespace is shown below:
```
@@ -11,6 +11,7 @@ import (
"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/runtime/restart"
specs "github.com/opencontainers/runtime-spec/specs-go"
log "github.com/sirupsen/logrus"
)
@@ -118,6 +119,11 @@ func stop(ctx context.Context, service, sock, basePath string) (string, uint32,
return "", 0, "loading container", err
}

err = ctr.Update(ctx, restart.WithNoRestarts)
if err != nil {
return "", 0, "failed to clear restart monitor", err
}

task, err := ctr.Task(ctx, nil)
if err != nil {
return "", 0, "fetching task", err
@@ -227,5 +233,12 @@ func start(ctx context.Context, service, sock, basePath, dumpSpec string) (strin
return "", 0, "failed to start task", err
}

if runtimeConfig.NoRestart == nil || *runtimeConfig.NoRestart == false {
err = ctr.Update(ctx, restart.WithStatus(containerd.Running))
if err != nil {
return "", 0, "failed to add restart monitor", err
}
}

return ctr.ID(), task.Pid(), "", nil
}
@@ -24,6 +24,7 @@ type Runtime struct {
Interfaces []Interface `yaml:"interfaces" json:"interfaces,omitempty"`
BindNS Namespaces `yaml:"bindNS" json:"bindNS,omitempty"`
Namespace string `yaml:"namespace,omitempty" json:"namespace,omitempty"`
NoRestart *bool `yaml:"noRestart,omitempty" json:"noRestart,omitempty"`
}

// Namespaces is the type for configuring paths to bind namespaces
@@ -116,6 +116,7 @@ type Runtime struct {
Interfaces *[]Interface `yaml:"interfaces,omitempty,omitempty" json:"interfaces,omitempty"`
BindNS Namespaces `yaml:"bindNS,omitempty" json:"bindNS,omitempty"`
Namespace *string `yaml:"namespace,omitempty" json:"namespace,omitempty"`
NoRestart *bool `yaml:"noRestart,omitempty" json:"noRestart,omitempty"`
}

// Namespaces is the type for configuring paths to bind namespaces
@@ -590,6 +591,7 @@ func assignRuntime(v1, v2 *Runtime) Runtime {
runtimeMkdir := assignStrings(v1.Mkdir, v2.Mkdir)
runtimeInterfaces := assignRuntimeInterfaceArray(v1.Interfaces, v2.Interfaces)
runtimeNamespace := assignString(v1.Namespace, v2.Namespace)
runtimeNoRestart := assignBool(v1.NoRestart, v2.NoRestart)
runtime := Runtime{
Cgroups: &runtimeCgroups,
Mounts: &runtimeMounts,
@@ -605,6 +607,7 @@ func assignRuntime(v1, v2 *Runtime) Runtime {
Uts: assignStringPtr(v1.BindNS.Uts, v2.BindNS.Uts),
},
Namespace: &runtimeNamespace,
NoRestart: &runtimeNoRestart,
}
return runtime
}
@@ -249,7 +249,8 @@ var schema = string(`
"mkdir": {"$ref": "#/definitions/strings"},
"interfaces": {"$ref": "#/definitions/interfaces"},
"bindNS": {"$ref": "#/definitions/namespaces"},
"namespace": {"type": "string"}
"namespace": {"type": "string"},
"noRestart": {"type": "boolean"}
}
},
"image": {

0 comments on commit 1d1c8fc

Please sign in to comment.