LCOW: Remove CommonContainer - just Container

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2017-04-25 12:03:45 -07:00
parent fe5b34ba88
commit 55f8828eec
10 changed files with 124 additions and 172 deletions

View file

@ -58,9 +58,8 @@ var (
errInvalidNetwork = fmt.Errorf("invalid network settings while building port map info")
)
// CommonContainer holds the fields for a container which are
// applicable across all platforms supported by the daemon.
type CommonContainer struct {
// Container holds the structure defining a container object.
type Container struct {
StreamConfig *stream.Config
// embed for Container to support states directly.
*State `json:"State"` // Needed for Engine API version <= 1.11
@ -95,21 +94,31 @@ type CommonContainer struct {
LogCopier *logger.Copier `json:"-"`
restartManager restartmanager.RestartManager
attachContext *attachContext
// Fields here are specific to Unix platforms
AppArmorProfile string
HostnamePath string
HostsPath string
ShmPath string
ResolvConfPath string
SeccompProfile string
NoNewPrivileges bool
// Fields here are specific to Windows
NetworkSharedContainerID string
}
// NewBaseContainer creates a new container with its
// basic configuration.
func NewBaseContainer(id, root string) *Container {
return &Container{
CommonContainer: CommonContainer{
ID: id,
State: NewState(),
ExecCommands: exec.NewStore(),
Root: root,
MountPoints: make(map[string]*volume.MountPoint),
StreamConfig: stream.NewConfig(),
attachContext: &attachContext{},
},
ID: id,
State: NewState(),
ExecCommands: exec.NewStore(),
Root: root,
MountPoints: make(map[string]*volume.MountPoint),
StreamConfig: stream.NewConfig(),
attachContext: &attachContext{},
}
}

View file

@ -11,9 +11,7 @@ import (
func TestContainerStopSignal(t *testing.T) {
c := &Container{
CommonContainer: CommonContainer{
Config: &container.Config{},
},
Config: &container.Config{},
}
def, err := signal.ParseSignal(signal.DefaultStopSignal)
@ -27,9 +25,7 @@ func TestContainerStopSignal(t *testing.T) {
}
c = &Container{
CommonContainer: CommonContainer{
Config: &container.Config{StopSignal: "SIGKILL"},
},
Config: &container.Config{StopSignal: "SIGKILL"},
}
s = c.StopSignal()
if s != 9 {
@ -39,9 +35,7 @@ func TestContainerStopSignal(t *testing.T) {
func TestContainerStopTimeout(t *testing.T) {
c := &Container{
CommonContainer: CommonContainer{
Config: &container.Config{},
},
Config: &container.Config{},
}
s := c.StopTimeout()
@ -51,9 +45,7 @@ func TestContainerStopTimeout(t *testing.T) {
stopTimeout := 15
c = &Container{
CommonContainer: CommonContainer{
Config: &container.Config{StopTimeout: &stopTimeout},
},
Config: &container.Config{StopTimeout: &stopTimeout},
}
s = c.StopSignal()
if s != 15 {

View file

@ -26,21 +26,6 @@ const (
containerSecretMountPath = "/run/secrets"
)
// Container holds the fields specific to unixen implementations.
// See CommonContainer for standard fields common to all containers.
type Container struct {
CommonContainer
// Fields below here are platform specific.
AppArmorProfile string
HostnamePath string
HostsPath string
ShmPath string
ResolvConfPath string
SeccompProfile string
NoNewPrivileges bool
}
// ExitStatus provides exit reasons for a container.
type ExitStatus struct {
// The exit code with which the container exited.

View file

@ -17,15 +17,6 @@ const (
containerInternalConfigsDirPath = `C:\ProgramData\Docker\internal\configs`
)
// Container holds fields specific to the Windows implementation. See
// CommonContainer for standard fields common to all containers.
type Container struct {
CommonContainer
// Fields below here are platform specific.
NetworkSharedContainerID string
}
// ExitStatus provides exit reasons for a container.
type ExitStatus struct {
// The exit code with which the container exited.

View file

@ -38,14 +38,12 @@ func TestHealthStates(t *testing.T) {
}
c := &container.Container{
CommonContainer: container.CommonContainer{
ID: "id",
Name: "name",
Config: &containertypes.Config{
Image: "image_name",
Labels: map[string]string{
"com.docker.swarm.task.id": "id",
},
ID: "id",
Name: "name",
Config: &containertypes.Config{
Image: "image_name",
Labels: map[string]string{
"com.docker.swarm.task.id": "id",
},
},
}

View file

@ -27,38 +27,28 @@ import (
func TestGetContainer(t *testing.T) {
c1 := &container.Container{
CommonContainer: container.CommonContainer{
ID: "5a4ff6a163ad4533d22d69a2b8960bf7fafdcba06e72d2febdba229008b0bf57",
Name: "tender_bardeen",
},
ID: "5a4ff6a163ad4533d22d69a2b8960bf7fafdcba06e72d2febdba229008b0bf57",
Name: "tender_bardeen",
}
c2 := &container.Container{
CommonContainer: container.CommonContainer{
ID: "3cdbd1aa394fd68559fd1441d6eff2ab7c1e6363582c82febfaa8045df3bd8de",
Name: "drunk_hawking",
},
ID: "3cdbd1aa394fd68559fd1441d6eff2ab7c1e6363582c82febfaa8045df3bd8de",
Name: "drunk_hawking",
}
c3 := &container.Container{
CommonContainer: container.CommonContainer{
ID: "3cdbd1aa394fd68559fd1441d6eff2abfafdcba06e72d2febdba229008b0bf57",
Name: "3cdbd1aa",
},
ID: "3cdbd1aa394fd68559fd1441d6eff2abfafdcba06e72d2febdba229008b0bf57",
Name: "3cdbd1aa",
}
c4 := &container.Container{
CommonContainer: container.CommonContainer{
ID: "75fb0b800922abdbef2d27e60abcdfaf7fb0698b2a96d22d3354da361a6ff4a5",
Name: "5a4ff6a163ad4533d22d69a2b8960bf7fafdcba06e72d2febdba229008b0bf57",
},
ID: "75fb0b800922abdbef2d27e60abcdfaf7fb0698b2a96d22d3354da361a6ff4a5",
Name: "5a4ff6a163ad4533d22d69a2b8960bf7fafdcba06e72d2febdba229008b0bf57",
}
c5 := &container.Container{
CommonContainer: container.CommonContainer{
ID: "d22d69a2b8960bf7fafdcba06e72d2febdba960bf7fafdcba06e72d2f9008b060b",
Name: "d22d69a2b896",
},
ID: "d22d69a2b8960bf7fafdcba06e72d2febdba960bf7fafdcba06e72d2f9008b060b",
Name: "d22d69a2b896",
}
store := container.NewMemoryStore()
@ -184,7 +174,7 @@ func TestContainerInitDNS(t *testing.T) {
"UpdateDns":false,"Volumes":{},"VolumesRW":{},"AppliedVolumesFrom":null}`
// Container struct only used to retrieve path to config file
container := &container.Container{CommonContainer: container.CommonContainer{Root: containerPath}}
container := &container.Container{Root: containerPath}
configPath, err := container.ConfigPath()
if err != nil {
t.Fatal(err)

View file

@ -26,11 +26,9 @@ func newDaemonWithTmpRoot(t *testing.T) (*Daemon, func()) {
func newContainerWithState(state *container.State) *container.Container {
return &container.Container{
CommonContainer: container.CommonContainer{
ID: "test",
State: state,
Config: &containertypes.Config{},
},
ID: "test",
State: state,
Config: &containertypes.Config{},
}
}

View file

@ -16,15 +16,13 @@ func TestLogContainerEventCopyLabels(t *testing.T) {
defer e.Evict(l)
container := &container.Container{
CommonContainer: container.CommonContainer{
ID: "container_id",
Name: "container_name",
Config: &containertypes.Config{
Image: "image_name",
Labels: map[string]string{
"node": "1",
"os": "alpine",
},
ID: "container_id",
Name: "container_name",
Config: &containertypes.Config{
Image: "image_name",
Labels: map[string]string{
"node": "1",
"os": "alpine",
},
},
}
@ -49,14 +47,12 @@ func TestLogContainerEventWithAttributes(t *testing.T) {
defer e.Evict(l)
container := &container.Container{
CommonContainer: container.CommonContainer{
ID: "container_id",
Name: "container_name",
Config: &containertypes.Config{
Labels: map[string]string{
"node": "1",
"os": "alpine",
},
ID: "container_id",
Name: "container_name",
Config: &containertypes.Config{
Labels: map[string]string{
"node": "1",
"os": "alpine",
},
},
}

View file

@ -19,17 +19,15 @@ func reset(c *container.Container) {
func TestNoneHealthcheck(t *testing.T) {
c := &container.Container{
CommonContainer: container.CommonContainer{
ID: "container_id",
Name: "container_name",
Config: &containertypes.Config{
Image: "image_name",
Healthcheck: &containertypes.HealthConfig{
Test: []string{"NONE"},
},
ID: "container_id",
Name: "container_name",
Config: &containertypes.Config{
Image: "image_name",
Healthcheck: &containertypes.HealthConfig{
Test: []string{"NONE"},
},
State: &container.State{},
},
State: &container.State{},
}
daemon := &Daemon{}
@ -58,12 +56,10 @@ func TestHealthStates(t *testing.T) {
}
c := &container.Container{
CommonContainer: container.CommonContainer{
ID: "container_id",
Name: "container_name",
Config: &containertypes.Config{
Image: "image_name",
},
ID: "container_id",
Name: "container_name",
Config: &containertypes.Config{
Image: "image_name",
},
}
daemon := &Daemon{

View file

@ -18,70 +18,67 @@ func TestBackportMountSpec(t *testing.T) {
d := Daemon{containers: container.NewMemoryStore()}
c := &container.Container{
CommonContainer: container.CommonContainer{
State: &container.State{},
MountPoints: map[string]*volume.MountPoint{
"/apple": {Destination: "/apple", Source: "/var/lib/docker/volumes/12345678", Name: "12345678", RW: true, CopyData: true}, // anonymous volume
"/banana": {Destination: "/banana", Source: "/var/lib/docker/volumes/data", Name: "data", RW: true, CopyData: true}, // named volume
"/cherry": {Destination: "/cherry", Source: "/var/lib/docker/volumes/data", Name: "data", CopyData: true}, // RO named volume
"/dates": {Destination: "/dates", Source: "/var/lib/docker/volumes/data", Name: "data"}, // named volume nocopy
"/elderberry": {Destination: "/elderberry", Source: "/var/lib/docker/volumes/data", Name: "data"}, // masks anon vol
"/fig": {Destination: "/fig", Source: "/data", RW: true}, // RW bind
"/guava": {Destination: "/guava", Source: "/data", RW: false, Propagation: "shared"}, // RO bind + propagation
"/kumquat": {Destination: "/kumquat", Name: "data", RW: false, CopyData: true}, // volumes-from
State: &container.State{},
MountPoints: map[string]*volume.MountPoint{
"/apple": {Destination: "/apple", Source: "/var/lib/docker/volumes/12345678", Name: "12345678", RW: true, CopyData: true}, // anonymous volume
"/banana": {Destination: "/banana", Source: "/var/lib/docker/volumes/data", Name: "data", RW: true, CopyData: true}, // named volume
"/cherry": {Destination: "/cherry", Source: "/var/lib/docker/volumes/data", Name: "data", CopyData: true}, // RO named volume
"/dates": {Destination: "/dates", Source: "/var/lib/docker/volumes/data", Name: "data"}, // named volume nocopy
"/elderberry": {Destination: "/elderberry", Source: "/var/lib/docker/volumes/data", Name: "data"}, // masks anon vol
"/fig": {Destination: "/fig", Source: "/data", RW: true}, // RW bind
"/guava": {Destination: "/guava", Source: "/data", RW: false, Propagation: "shared"}, // RO bind + propagation
"/kumquat": {Destination: "/kumquat", Name: "data", RW: false, CopyData: true}, // volumes-from
// partially configured mountpoint due to #32613
// specifically, `mp.Spec.Source` is not set
"/honeydew": {
Type: mounttypes.TypeVolume,
Destination: "/honeydew",
Name: "data",
Source: "/var/lib/docker/volumes/data",
Spec: mounttypes.Mount{Type: mounttypes.TypeVolume, Target: "/honeydew", VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}},
},
// partially configured mountpoint due to #32613
// specifically, `mp.Spec.Source` is not set
"/honeydew": {
Type: mounttypes.TypeVolume,
Destination: "/honeydew",
Name: "data",
Source: "/var/lib/docker/volumes/data",
Spec: mounttypes.Mount{Type: mounttypes.TypeVolume, Target: "/honeydew", VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}},
},
// from hostconfig.Mounts
"/jambolan": {
Type: mounttypes.TypeVolume,
Destination: "/jambolan",
Source: "/var/lib/docker/volumes/data",
RW: true,
Name: "data",
Spec: mounttypes.Mount{Type: mounttypes.TypeVolume, Target: "/jambolan", Source: "data"},
},
// from hostconfig.Mounts
"/jambolan": {
Type: mounttypes.TypeVolume,
Destination: "/jambolan",
Source: "/var/lib/docker/volumes/data",
RW: true,
Name: "data",
Spec: mounttypes.Mount{Type: mounttypes.TypeVolume, Target: "/jambolan", Source: "data"},
},
HostConfig: &containertypes.HostConfig{
Binds: []string{
"data:/banana",
"data:/cherry:ro",
"data:/dates:ro,nocopy",
"data:/elderberry:ro,nocopy",
"/data:/fig",
"/data:/guava:ro,shared",
"data:/honeydew:nocopy",
},
VolumesFrom: []string{"1:ro"},
Mounts: []mounttypes.Mount{
{Type: mounttypes.TypeVolume, Target: "/jambolan"},
},
},
HostConfig: &containertypes.HostConfig{
Binds: []string{
"data:/banana",
"data:/cherry:ro",
"data:/dates:ro,nocopy",
"data:/elderberry:ro,nocopy",
"/data:/fig",
"/data:/guava:ro,shared",
"data:/honeydew:nocopy",
},
Config: &containertypes.Config{Volumes: map[string]struct{}{
"/apple": {},
"/elderberry": {},
}},
}}
VolumesFrom: []string{"1:ro"},
Mounts: []mounttypes.Mount{
{Type: mounttypes.TypeVolume, Target: "/jambolan"},
},
},
Config: &containertypes.Config{Volumes: map[string]struct{}{
"/apple": {},
"/elderberry": {},
}},
}
d.containers.Add("1", &container.Container{
CommonContainer: container.CommonContainer{
State: &container.State{},
ID: "1",
MountPoints: map[string]*volume.MountPoint{
"/kumquat": {Destination: "/kumquat", Name: "data", RW: false, CopyData: true},
},
HostConfig: &containertypes.HostConfig{
Binds: []string{
"data:/kumquat:ro",
},
State: &container.State{},
ID: "1",
MountPoints: map[string]*volume.MountPoint{
"/kumquat": {Destination: "/kumquat", Name: "data", RW: false, CopyData: true},
},
HostConfig: &containertypes.HostConfig{
Binds: []string{
"data:/kumquat:ro",
},
},
})