- daemon/delete: rename var that collided with import, remove output var
- daemon: fix inconsistent receiver name and package aliases
- daemon/stop: rename imports and variables to standard naming
This is in preparation of some changes, but keeping it in a
separate commit to make review of other changes easier.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -12,19 +12,19 @@ import ( |
| 12 | 12 |
"go.etcd.io/bbolt" |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 |
-func (d *Daemon) configureLocalContentStore() (content.Store, leases.Manager, error) {
|
|
| 16 |
- if err := os.MkdirAll(filepath.Join(d.root, "content"), 0700); err != nil {
|
|
| 15 |
+func (daemon *Daemon) configureLocalContentStore() (content.Store, leases.Manager, error) {
|
|
| 16 |
+ if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0700); err != nil {
|
|
| 17 | 17 |
return nil, nil, errors.Wrap(err, "error creating dir for content store") |
| 18 | 18 |
} |
| 19 |
- db, err := bbolt.Open(filepath.Join(d.root, "content", "metadata.db"), 0600, nil) |
|
| 19 |
+ db, err := bbolt.Open(filepath.Join(daemon.root, "content", "metadata.db"), 0600, nil) |
|
| 20 | 20 |
if err != nil {
|
| 21 | 21 |
return nil, nil, errors.Wrap(err, "error opening bolt db for content metadata store") |
| 22 | 22 |
} |
| 23 |
- cs, err := local.NewStore(filepath.Join(d.root, "content", "data")) |
|
| 23 |
+ cs, err := local.NewStore(filepath.Join(daemon.root, "content", "data")) |
|
| 24 | 24 |
if err != nil {
|
| 25 | 25 |
return nil, nil, errors.Wrap(err, "error setting up content store") |
| 26 | 26 |
} |
| 27 | 27 |
md := metadata.NewDB(db, cs, nil) |
| 28 |
- d.mdDB = db |
|
| 28 |
+ daemon.mdDB = db |
|
| 29 | 29 |
return md.ContentStore(), metadata.NewLeaseManager(md), nil |
| 30 | 30 |
} |
| ... | ... |
@@ -22,28 +22,28 @@ import ( |
| 22 | 22 |
// network links are removed. |
| 23 | 23 |
func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig) error {
|
| 24 | 24 |
start := time.Now() |
| 25 |
- container, err := daemon.GetContainer(name) |
|
| 25 |
+ ctr, err := daemon.GetContainer(name) |
|
| 26 | 26 |
if err != nil {
|
| 27 | 27 |
return err |
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 | 30 |
// Container state RemovalInProgress should be used to avoid races. |
| 31 |
- if inProgress := container.SetRemovalInProgress(); inProgress {
|
|
| 31 |
+ if inProgress := ctr.SetRemovalInProgress(); inProgress {
|
|
| 32 | 32 |
err := fmt.Errorf("removal of container %s is already in progress", name)
|
| 33 | 33 |
return errdefs.Conflict(err) |
| 34 | 34 |
} |
| 35 |
- defer container.ResetRemovalInProgress() |
|
| 35 |
+ defer ctr.ResetRemovalInProgress() |
|
| 36 | 36 |
|
| 37 | 37 |
// check if container wasn't deregistered by previous rm since Get |
| 38 |
- if c := daemon.containers.Get(container.ID); c == nil {
|
|
| 38 |
+ if c := daemon.containers.Get(ctr.ID); c == nil {
|
|
| 39 | 39 |
return nil |
| 40 | 40 |
} |
| 41 | 41 |
|
| 42 | 42 |
if config.RemoveLink {
|
| 43 |
- return daemon.rmLink(container, name) |
|
| 43 |
+ return daemon.rmLink(ctr, name) |
|
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
- err = daemon.cleanupContainer(container, config.ForceRemove, config.RemoveVolume) |
|
| 46 |
+ err = daemon.cleanupContainer(ctr, config.ForceRemove, config.RemoveVolume) |
|
| 47 | 47 |
containerActions.WithValues("delete").UpdateSince(start)
|
| 48 | 48 |
|
| 49 | 49 |
return err |
| ... | ... |
@@ -7,10 +7,10 @@ import ( |
| 7 | 7 |
"testing" |
| 8 | 8 |
|
| 9 | 9 |
coci "github.com/containerd/containerd/oci" |
| 10 |
- config "github.com/docker/docker/api/types/container" |
|
| 10 |
+ containertypes "github.com/docker/docker/api/types/container" |
|
| 11 | 11 |
"github.com/docker/docker/container" |
| 12 | 12 |
dconfig "github.com/docker/docker/daemon/config" |
| 13 |
- doci "github.com/docker/docker/oci" |
|
| 13 |
+ "github.com/docker/docker/oci" |
|
| 14 | 14 |
"github.com/docker/docker/pkg/sysinfo" |
| 15 | 15 |
"github.com/docker/docker/profiles/seccomp" |
| 16 | 16 |
specs "github.com/opencontainers/runtime-spec/specs-go" |
| ... | ... |
@@ -36,12 +36,12 @@ func TestWithSeccomp(t *testing.T) {
|
| 36 | 36 |
}, |
| 37 | 37 |
c: &container.Container{
|
| 38 | 38 |
SeccompProfile: dconfig.SeccompProfileUnconfined, |
| 39 |
- HostConfig: &config.HostConfig{
|
|
| 39 |
+ HostConfig: &containertypes.HostConfig{
|
|
| 40 | 40 |
Privileged: false, |
| 41 | 41 |
}, |
| 42 | 42 |
}, |
| 43 |
- inSpec: doci.DefaultLinuxSpec(), |
|
| 44 |
- outSpec: doci.DefaultLinuxSpec(), |
|
| 43 |
+ inSpec: oci.DefaultLinuxSpec(), |
|
| 44 |
+ outSpec: oci.DefaultLinuxSpec(), |
|
| 45 | 45 |
}, |
| 46 | 46 |
{
|
| 47 | 47 |
comment: "privileged container w/ custom profile runs unconfined", |
| ... | ... |
@@ -50,12 +50,12 @@ func TestWithSeccomp(t *testing.T) {
|
| 50 | 50 |
}, |
| 51 | 51 |
c: &container.Container{
|
| 52 | 52 |
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_LOG\" }",
|
| 53 |
- HostConfig: &config.HostConfig{
|
|
| 53 |
+ HostConfig: &containertypes.HostConfig{
|
|
| 54 | 54 |
Privileged: true, |
| 55 | 55 |
}, |
| 56 | 56 |
}, |
| 57 |
- inSpec: doci.DefaultLinuxSpec(), |
|
| 58 |
- outSpec: doci.DefaultLinuxSpec(), |
|
| 57 |
+ inSpec: oci.DefaultLinuxSpec(), |
|
| 58 |
+ outSpec: oci.DefaultLinuxSpec(), |
|
| 59 | 59 |
}, |
| 60 | 60 |
{
|
| 61 | 61 |
comment: "privileged container w/ default runs unconfined", |
| ... | ... |
@@ -64,12 +64,12 @@ func TestWithSeccomp(t *testing.T) {
|
| 64 | 64 |
}, |
| 65 | 65 |
c: &container.Container{
|
| 66 | 66 |
SeccompProfile: "", |
| 67 |
- HostConfig: &config.HostConfig{
|
|
| 67 |
+ HostConfig: &containertypes.HostConfig{
|
|
| 68 | 68 |
Privileged: true, |
| 69 | 69 |
}, |
| 70 | 70 |
}, |
| 71 |
- inSpec: doci.DefaultLinuxSpec(), |
|
| 72 |
- outSpec: doci.DefaultLinuxSpec(), |
|
| 71 |
+ inSpec: oci.DefaultLinuxSpec(), |
|
| 72 |
+ outSpec: oci.DefaultLinuxSpec(), |
|
| 73 | 73 |
}, |
| 74 | 74 |
{
|
| 75 | 75 |
comment: "privileged container w/ daemon profile runs unconfined", |
| ... | ... |
@@ -79,12 +79,12 @@ func TestWithSeccomp(t *testing.T) {
|
| 79 | 79 |
}, |
| 80 | 80 |
c: &container.Container{
|
| 81 | 81 |
SeccompProfile: "", |
| 82 |
- HostConfig: &config.HostConfig{
|
|
| 82 |
+ HostConfig: &containertypes.HostConfig{
|
|
| 83 | 83 |
Privileged: true, |
| 84 | 84 |
}, |
| 85 | 85 |
}, |
| 86 |
- inSpec: doci.DefaultLinuxSpec(), |
|
| 87 |
- outSpec: doci.DefaultLinuxSpec(), |
|
| 86 |
+ inSpec: oci.DefaultLinuxSpec(), |
|
| 87 |
+ outSpec: oci.DefaultLinuxSpec(), |
|
| 88 | 88 |
}, |
| 89 | 89 |
{
|
| 90 | 90 |
comment: "custom profile when seccomp is disabled returns error", |
| ... | ... |
@@ -93,12 +93,12 @@ func TestWithSeccomp(t *testing.T) {
|
| 93 | 93 |
}, |
| 94 | 94 |
c: &container.Container{
|
| 95 | 95 |
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }",
|
| 96 |
- HostConfig: &config.HostConfig{
|
|
| 96 |
+ HostConfig: &containertypes.HostConfig{
|
|
| 97 | 97 |
Privileged: false, |
| 98 | 98 |
}, |
| 99 | 99 |
}, |
| 100 |
- inSpec: doci.DefaultLinuxSpec(), |
|
| 101 |
- outSpec: doci.DefaultLinuxSpec(), |
|
| 100 |
+ inSpec: oci.DefaultLinuxSpec(), |
|
| 101 |
+ outSpec: oci.DefaultLinuxSpec(), |
|
| 102 | 102 |
err: "seccomp is not enabled in your kernel, cannot run a custom seccomp profile", |
| 103 | 103 |
}, |
| 104 | 104 |
{
|
| ... | ... |
@@ -108,13 +108,13 @@ func TestWithSeccomp(t *testing.T) {
|
| 108 | 108 |
}, |
| 109 | 109 |
c: &container.Container{
|
| 110 | 110 |
SeccompProfile: "", |
| 111 |
- HostConfig: &config.HostConfig{
|
|
| 111 |
+ HostConfig: &containertypes.HostConfig{
|
|
| 112 | 112 |
Privileged: false, |
| 113 | 113 |
}, |
| 114 | 114 |
}, |
| 115 |
- inSpec: doci.DefaultLinuxSpec(), |
|
| 115 |
+ inSpec: oci.DefaultLinuxSpec(), |
|
| 116 | 116 |
outSpec: func() coci.Spec {
|
| 117 |
- s := doci.DefaultLinuxSpec() |
|
| 117 |
+ s := oci.DefaultLinuxSpec() |
|
| 118 | 118 |
profile, _ := seccomp.GetDefaultProfile(&s) |
| 119 | 119 |
s.Linux.Seccomp = profile |
| 120 | 120 |
return s |
| ... | ... |
@@ -127,13 +127,13 @@ func TestWithSeccomp(t *testing.T) {
|
| 127 | 127 |
}, |
| 128 | 128 |
c: &container.Container{
|
| 129 | 129 |
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }",
|
| 130 |
- HostConfig: &config.HostConfig{
|
|
| 130 |
+ HostConfig: &containertypes.HostConfig{
|
|
| 131 | 131 |
Privileged: false, |
| 132 | 132 |
}, |
| 133 | 133 |
}, |
| 134 |
- inSpec: doci.DefaultLinuxSpec(), |
|
| 134 |
+ inSpec: oci.DefaultLinuxSpec(), |
|
| 135 | 135 |
outSpec: func() coci.Spec {
|
| 136 |
- s := doci.DefaultLinuxSpec() |
|
| 136 |
+ s := oci.DefaultLinuxSpec() |
|
| 137 | 137 |
profile := &specs.LinuxSeccomp{
|
| 138 | 138 |
DefaultAction: specs.LinuxSeccompAction("SCMP_ACT_ERRNO"),
|
| 139 | 139 |
} |
| ... | ... |
@@ -149,13 +149,13 @@ func TestWithSeccomp(t *testing.T) {
|
| 149 | 149 |
}, |
| 150 | 150 |
c: &container.Container{
|
| 151 | 151 |
SeccompProfile: "", |
| 152 |
- HostConfig: &config.HostConfig{
|
|
| 152 |
+ HostConfig: &containertypes.HostConfig{
|
|
| 153 | 153 |
Privileged: false, |
| 154 | 154 |
}, |
| 155 | 155 |
}, |
| 156 |
- inSpec: doci.DefaultLinuxSpec(), |
|
| 156 |
+ inSpec: oci.DefaultLinuxSpec(), |
|
| 157 | 157 |
outSpec: func() coci.Spec {
|
| 158 |
- s := doci.DefaultLinuxSpec() |
|
| 158 |
+ s := oci.DefaultLinuxSpec() |
|
| 159 | 159 |
profile := &specs.LinuxSeccomp{
|
| 160 | 160 |
DefaultAction: specs.LinuxSeccompAction("SCMP_ACT_ERRNO"),
|
| 161 | 161 |
} |
| ... | ... |
@@ -171,13 +171,13 @@ func TestWithSeccomp(t *testing.T) {
|
| 171 | 171 |
}, |
| 172 | 172 |
c: &container.Container{
|
| 173 | 173 |
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_LOG\" }",
|
| 174 |
- HostConfig: &config.HostConfig{
|
|
| 174 |
+ HostConfig: &containertypes.HostConfig{
|
|
| 175 | 175 |
Privileged: false, |
| 176 | 176 |
}, |
| 177 | 177 |
}, |
| 178 |
- inSpec: doci.DefaultLinuxSpec(), |
|
| 178 |
+ inSpec: oci.DefaultLinuxSpec(), |
|
| 179 | 179 |
outSpec: func() coci.Spec {
|
| 180 |
- s := doci.DefaultLinuxSpec() |
|
| 180 |
+ s := oci.DefaultLinuxSpec() |
|
| 181 | 181 |
profile := &specs.LinuxSeccomp{
|
| 182 | 182 |
DefaultAction: specs.LinuxSeccompAction("SCMP_ACT_LOG"),
|
| 183 | 183 |
} |
| ... | ... |
@@ -4,7 +4,7 @@ import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"time" |
| 6 | 6 |
|
| 7 |
- containerpkg "github.com/docker/docker/container" |
|
| 7 |
+ "github.com/docker/docker/container" |
|
| 8 | 8 |
"github.com/docker/docker/errdefs" |
| 9 | 9 |
"github.com/pkg/errors" |
| 10 | 10 |
"github.com/sirupsen/logrus" |
| ... | ... |
@@ -19,28 +19,28 @@ import ( |
| 19 | 19 |
// otherwise the engine default. A negative timeout value can be specified, |
| 20 | 20 |
// meaning no timeout, i.e. no forceful termination is performed. |
| 21 | 21 |
func (daemon *Daemon) ContainerStop(name string, timeout *int) error {
|
| 22 |
- container, err := daemon.GetContainer(name) |
|
| 22 |
+ ctr, err := daemon.GetContainer(name) |
|
| 23 | 23 |
if err != nil {
|
| 24 | 24 |
return err |
| 25 | 25 |
} |
| 26 |
- if !container.IsRunning() {
|
|
| 26 |
+ if !ctr.IsRunning() {
|
|
| 27 | 27 |
return containerNotModifiedError{running: false}
|
| 28 | 28 |
} |
| 29 | 29 |
if timeout == nil {
|
| 30 |
- stopTimeout := container.StopTimeout() |
|
| 30 |
+ stopTimeout := ctr.StopTimeout() |
|
| 31 | 31 |
timeout = &stopTimeout |
| 32 | 32 |
} |
| 33 |
- if err := daemon.containerStop(container, *timeout); err != nil {
|
|
| 33 |
+ if err := daemon.containerStop(ctr, *timeout); err != nil {
|
|
| 34 | 34 |
return errdefs.System(errors.Wrapf(err, "cannot stop container: %s", name)) |
| 35 | 35 |
} |
| 36 | 36 |
return nil |
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 | 39 |
// containerStop sends a stop signal, waits, sends a kill signal. |
| 40 |
-func (daemon *Daemon) containerStop(container *containerpkg.Container, seconds int) error {
|
|
| 40 |
+func (daemon *Daemon) containerStop(ctr *container.Container, seconds int) error {
|
|
| 41 | 41 |
// TODO propagate a context down to this function |
| 42 | 42 |
ctx := context.TODO() |
| 43 |
- if !container.IsRunning() {
|
|
| 43 |
+ if !ctr.IsRunning() {
|
|
| 44 | 44 |
return nil |
| 45 | 45 |
} |
| 46 | 46 |
var wait time.Duration |
| ... | ... |
@@ -48,13 +48,13 @@ func (daemon *Daemon) containerStop(container *containerpkg.Container, seconds i |
| 48 | 48 |
wait = time.Duration(seconds) * time.Second |
| 49 | 49 |
} |
| 50 | 50 |
success := func() error {
|
| 51 |
- daemon.LogContainerEvent(container, "stop") |
|
| 51 |
+ daemon.LogContainerEvent(ctr, "stop") |
|
| 52 | 52 |
return nil |
| 53 | 53 |
} |
| 54 |
- stopSignal := container.StopSignal() |
|
| 54 |
+ stopSignal := ctr.StopSignal() |
|
| 55 | 55 |
|
| 56 | 56 |
// 1. Send a stop signal |
| 57 |
- err := daemon.killPossiblyDeadProcess(container, stopSignal) |
|
| 57 |
+ err := daemon.killPossiblyDeadProcess(ctr, stopSignal) |
|
| 58 | 58 |
if err != nil {
|
| 59 | 59 |
wait = 2 * time.Second |
| 60 | 60 |
} |
| ... | ... |
@@ -68,14 +68,14 @@ func (daemon *Daemon) containerStop(container *containerpkg.Container, seconds i |
| 68 | 68 |
} |
| 69 | 69 |
defer cancel() |
| 70 | 70 |
|
| 71 |
- if status := <-container.Wait(subCtx, containerpkg.WaitConditionNotRunning); status.Err() == nil {
|
|
| 71 |
+ if status := <-ctr.Wait(subCtx, container.WaitConditionNotRunning); status.Err() == nil {
|
|
| 72 | 72 |
// container did exit, so ignore any previous errors and return |
| 73 | 73 |
return success() |
| 74 | 74 |
} |
| 75 | 75 |
|
| 76 | 76 |
if err != nil {
|
| 77 | 77 |
// the container has still not exited, and the kill function errored, so log the error here: |
| 78 |
- logrus.WithError(err).WithField("container", container.ID).Errorf("Error sending stop (signal %d) to container", stopSignal)
|
|
| 78 |
+ logrus.WithError(err).WithField("container", ctr.ID).Errorf("Error sending stop (signal %d) to container", stopSignal)
|
|
| 79 | 79 |
} |
| 80 | 80 |
if seconds < 0 {
|
| 81 | 81 |
// if the client requested that we never kill / wait forever, but container.Wait was still |
| ... | ... |
@@ -83,17 +83,17 @@ func (daemon *Daemon) containerStop(container *containerpkg.Container, seconds i |
| 83 | 83 |
return err |
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 |
- logrus.WithField("container", container.ID).Infof("Container failed to exit within %s of signal %d - using the force", wait, stopSignal)
|
|
| 86 |
+ logrus.WithField("container", ctr.ID).Infof("Container failed to exit within %s of signal %d - using the force", wait, stopSignal)
|
|
| 87 | 87 |
// Stop either failed or container didnt exit, so fallback to kill. |
| 88 |
- if err := daemon.Kill(container); err != nil {
|
|
| 88 |
+ if err := daemon.Kill(ctr); err != nil {
|
|
| 89 | 89 |
// got a kill error, but give container 2 more seconds to exit just in case |
| 90 | 90 |
subCtx, cancel := context.WithTimeout(ctx, 2*time.Second) |
| 91 | 91 |
defer cancel() |
| 92 |
- if status := <-container.Wait(subCtx, containerpkg.WaitConditionNotRunning); status.Err() == nil {
|
|
| 92 |
+ if status := <-ctr.Wait(subCtx, container.WaitConditionNotRunning); status.Err() == nil {
|
|
| 93 | 93 |
// container did exit, so ignore error and return |
| 94 | 94 |
return success() |
| 95 | 95 |
} |
| 96 |
- logrus.WithError(err).WithField("container", container.ID).Error("Error killing the container")
|
|
| 96 |
+ logrus.WithError(err).WithField("container", ctr.ID).Error("Error killing the container")
|
|
| 97 | 97 |
return err |
| 98 | 98 |
} |
| 99 | 99 |
|