1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

daemon: rename some variables, import-aliases and receivers

- 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>
This commit is contained in:
Sebastiaan van Stijn 2021-08-22 00:46:07 +02:00
parent c4e3a16373
commit 4430992af8
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
4 changed files with 56 additions and 56 deletions

View file

@ -12,19 +12,19 @@ import (
"go.etcd.io/bbolt"
)
func (d *Daemon) configureLocalContentStore() (content.Store, leases.Manager, error) {
if err := os.MkdirAll(filepath.Join(d.root, "content"), 0700); err != nil {
func (daemon *Daemon) configureLocalContentStore() (content.Store, leases.Manager, error) {
if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0700); err != nil {
return nil, nil, errors.Wrap(err, "error creating dir for content store")
}
db, err := bbolt.Open(filepath.Join(d.root, "content", "metadata.db"), 0600, nil)
db, err := bbolt.Open(filepath.Join(daemon.root, "content", "metadata.db"), 0600, nil)
if err != nil {
return nil, nil, errors.Wrap(err, "error opening bolt db for content metadata store")
}
cs, err := local.NewStore(filepath.Join(d.root, "content", "data"))
cs, err := local.NewStore(filepath.Join(daemon.root, "content", "data"))
if err != nil {
return nil, nil, errors.Wrap(err, "error setting up content store")
}
md := metadata.NewDB(db, cs, nil)
d.mdDB = db
daemon.mdDB = db
return md.ContentStore(), metadata.NewLeaseManager(md), nil
}

View file

@ -22,28 +22,28 @@ import (
// network links are removed.
func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig) error {
start := time.Now()
container, err := daemon.GetContainer(name)
ctr, err := daemon.GetContainer(name)
if err != nil {
return err
}
// Container state RemovalInProgress should be used to avoid races.
if inProgress := container.SetRemovalInProgress(); inProgress {
if inProgress := ctr.SetRemovalInProgress(); inProgress {
err := fmt.Errorf("removal of container %s is already in progress", name)
return errdefs.Conflict(err)
}
defer container.ResetRemovalInProgress()
defer ctr.ResetRemovalInProgress()
// check if container wasn't deregistered by previous rm since Get
if c := daemon.containers.Get(container.ID); c == nil {
if c := daemon.containers.Get(ctr.ID); c == nil {
return nil
}
if config.RemoveLink {
return daemon.rmLink(container, name)
return daemon.rmLink(ctr, name)
}
err = daemon.cleanupContainer(container, config.ForceRemove, config.RemoveVolume)
err = daemon.cleanupContainer(ctr, config.ForceRemove, config.RemoveVolume)
containerActions.WithValues("delete").UpdateSince(start)
return err

View file

@ -7,10 +7,10 @@ import (
"testing"
coci "github.com/containerd/containerd/oci"
config "github.com/docker/docker/api/types/container"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/container"
dconfig "github.com/docker/docker/daemon/config"
doci "github.com/docker/docker/oci"
"github.com/docker/docker/oci"
"github.com/docker/docker/pkg/sysinfo"
"github.com/docker/docker/profiles/seccomp"
specs "github.com/opencontainers/runtime-spec/specs-go"
@ -36,12 +36,12 @@ func TestWithSeccomp(t *testing.T) {
},
c: &container.Container{
SeccompProfile: dconfig.SeccompProfileUnconfined,
HostConfig: &config.HostConfig{
HostConfig: &containertypes.HostConfig{
Privileged: false,
},
},
inSpec: doci.DefaultLinuxSpec(),
outSpec: doci.DefaultLinuxSpec(),
inSpec: oci.DefaultLinuxSpec(),
outSpec: oci.DefaultLinuxSpec(),
},
{
comment: "privileged container w/ custom profile runs unconfined",
@ -50,12 +50,12 @@ func TestWithSeccomp(t *testing.T) {
},
c: &container.Container{
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_LOG\" }",
HostConfig: &config.HostConfig{
HostConfig: &containertypes.HostConfig{
Privileged: true,
},
},
inSpec: doci.DefaultLinuxSpec(),
outSpec: doci.DefaultLinuxSpec(),
inSpec: oci.DefaultLinuxSpec(),
outSpec: oci.DefaultLinuxSpec(),
},
{
comment: "privileged container w/ default runs unconfined",
@ -64,12 +64,12 @@ func TestWithSeccomp(t *testing.T) {
},
c: &container.Container{
SeccompProfile: "",
HostConfig: &config.HostConfig{
HostConfig: &containertypes.HostConfig{
Privileged: true,
},
},
inSpec: doci.DefaultLinuxSpec(),
outSpec: doci.DefaultLinuxSpec(),
inSpec: oci.DefaultLinuxSpec(),
outSpec: oci.DefaultLinuxSpec(),
},
{
comment: "privileged container w/ daemon profile runs unconfined",
@ -79,12 +79,12 @@ func TestWithSeccomp(t *testing.T) {
},
c: &container.Container{
SeccompProfile: "",
HostConfig: &config.HostConfig{
HostConfig: &containertypes.HostConfig{
Privileged: true,
},
},
inSpec: doci.DefaultLinuxSpec(),
outSpec: doci.DefaultLinuxSpec(),
inSpec: oci.DefaultLinuxSpec(),
outSpec: oci.DefaultLinuxSpec(),
},
{
comment: "custom profile when seccomp is disabled returns error",
@ -93,12 +93,12 @@ func TestWithSeccomp(t *testing.T) {
},
c: &container.Container{
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }",
HostConfig: &config.HostConfig{
HostConfig: &containertypes.HostConfig{
Privileged: false,
},
},
inSpec: doci.DefaultLinuxSpec(),
outSpec: doci.DefaultLinuxSpec(),
inSpec: oci.DefaultLinuxSpec(),
outSpec: oci.DefaultLinuxSpec(),
err: "seccomp is not enabled in your kernel, cannot run a custom seccomp profile",
},
{
@ -108,13 +108,13 @@ func TestWithSeccomp(t *testing.T) {
},
c: &container.Container{
SeccompProfile: "",
HostConfig: &config.HostConfig{
HostConfig: &containertypes.HostConfig{
Privileged: false,
},
},
inSpec: doci.DefaultLinuxSpec(),
inSpec: oci.DefaultLinuxSpec(),
outSpec: func() coci.Spec {
s := doci.DefaultLinuxSpec()
s := oci.DefaultLinuxSpec()
profile, _ := seccomp.GetDefaultProfile(&s)
s.Linux.Seccomp = profile
return s
@ -127,13 +127,13 @@ func TestWithSeccomp(t *testing.T) {
},
c: &container.Container{
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }",
HostConfig: &config.HostConfig{
HostConfig: &containertypes.HostConfig{
Privileged: false,
},
},
inSpec: doci.DefaultLinuxSpec(),
inSpec: oci.DefaultLinuxSpec(),
outSpec: func() coci.Spec {
s := doci.DefaultLinuxSpec()
s := oci.DefaultLinuxSpec()
profile := &specs.LinuxSeccomp{
DefaultAction: specs.LinuxSeccompAction("SCMP_ACT_ERRNO"),
}
@ -149,13 +149,13 @@ func TestWithSeccomp(t *testing.T) {
},
c: &container.Container{
SeccompProfile: "",
HostConfig: &config.HostConfig{
HostConfig: &containertypes.HostConfig{
Privileged: false,
},
},
inSpec: doci.DefaultLinuxSpec(),
inSpec: oci.DefaultLinuxSpec(),
outSpec: func() coci.Spec {
s := doci.DefaultLinuxSpec()
s := oci.DefaultLinuxSpec()
profile := &specs.LinuxSeccomp{
DefaultAction: specs.LinuxSeccompAction("SCMP_ACT_ERRNO"),
}
@ -171,13 +171,13 @@ func TestWithSeccomp(t *testing.T) {
},
c: &container.Container{
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_LOG\" }",
HostConfig: &config.HostConfig{
HostConfig: &containertypes.HostConfig{
Privileged: false,
},
},
inSpec: doci.DefaultLinuxSpec(),
inSpec: oci.DefaultLinuxSpec(),
outSpec: func() coci.Spec {
s := doci.DefaultLinuxSpec()
s := oci.DefaultLinuxSpec()
profile := &specs.LinuxSeccomp{
DefaultAction: specs.LinuxSeccompAction("SCMP_ACT_LOG"),
}

View file

@ -4,7 +4,7 @@ import (
"context"
"time"
containerpkg "github.com/docker/docker/container"
"github.com/docker/docker/container"
"github.com/docker/docker/errdefs"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@ -19,28 +19,28 @@ import (
// otherwise the engine default. A negative timeout value can be specified,
// meaning no timeout, i.e. no forceful termination is performed.
func (daemon *Daemon) ContainerStop(name string, timeout *int) error {
container, err := daemon.GetContainer(name)
ctr, err := daemon.GetContainer(name)
if err != nil {
return err
}
if !container.IsRunning() {
if !ctr.IsRunning() {
return containerNotModifiedError{running: false}
}
if timeout == nil {
stopTimeout := container.StopTimeout()
stopTimeout := ctr.StopTimeout()
timeout = &stopTimeout
}
if err := daemon.containerStop(container, *timeout); err != nil {
if err := daemon.containerStop(ctr, *timeout); err != nil {
return errdefs.System(errors.Wrapf(err, "cannot stop container: %s", name))
}
return nil
}
// containerStop sends a stop signal, waits, sends a kill signal.
func (daemon *Daemon) containerStop(container *containerpkg.Container, seconds int) error {
func (daemon *Daemon) containerStop(ctr *container.Container, seconds int) error {
// TODO propagate a context down to this function
ctx := context.TODO()
if !container.IsRunning() {
if !ctr.IsRunning() {
return nil
}
var wait time.Duration
@ -48,13 +48,13 @@ func (daemon *Daemon) containerStop(container *containerpkg.Container, seconds i
wait = time.Duration(seconds) * time.Second
}
success := func() error {
daemon.LogContainerEvent(container, "stop")
daemon.LogContainerEvent(ctr, "stop")
return nil
}
stopSignal := container.StopSignal()
stopSignal := ctr.StopSignal()
// 1. Send a stop signal
err := daemon.killPossiblyDeadProcess(container, stopSignal)
err := daemon.killPossiblyDeadProcess(ctr, stopSignal)
if err != nil {
wait = 2 * time.Second
}
@ -68,14 +68,14 @@ func (daemon *Daemon) containerStop(container *containerpkg.Container, seconds i
}
defer cancel()
if status := <-container.Wait(subCtx, containerpkg.WaitConditionNotRunning); status.Err() == nil {
if status := <-ctr.Wait(subCtx, container.WaitConditionNotRunning); status.Err() == nil {
// container did exit, so ignore any previous errors and return
return success()
}
if err != nil {
// the container has still not exited, and the kill function errored, so log the error here:
logrus.WithError(err).WithField("container", container.ID).Errorf("Error sending stop (signal %d) to container", stopSignal)
logrus.WithError(err).WithField("container", ctr.ID).Errorf("Error sending stop (signal %d) to container", stopSignal)
}
if seconds < 0 {
// 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
return err
}
logrus.WithField("container", container.ID).Infof("Container failed to exit within %s of signal %d - using the force", wait, stopSignal)
logrus.WithField("container", ctr.ID).Infof("Container failed to exit within %s of signal %d - using the force", wait, stopSignal)
// Stop either failed or container didnt exit, so fallback to kill.
if err := daemon.Kill(container); err != nil {
if err := daemon.Kill(ctr); err != nil {
// got a kill error, but give container 2 more seconds to exit just in case
subCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
if status := <-container.Wait(subCtx, containerpkg.WaitConditionNotRunning); status.Err() == nil {
if status := <-ctr.Wait(subCtx, container.WaitConditionNotRunning); status.Err() == nil {
// container did exit, so ignore error and return
return success()
}
logrus.WithError(err).WithField("container", container.ID).Error("Error killing the container")
logrus.WithError(err).WithField("container", ctr.ID).Error("Error killing the container")
return err
}