Merge pull request #258 from cpuguy83/better_mounts_api

Add new APIs for safer mount specifications
This commit is contained in:
Brian Goff 2016-08-11 12:27:23 -04:00 коммит произвёл GitHub
Родитель 3342859391 61712aa11e
Коммит b54bc2593f
5 изменённых файлов: 74 добавлений и 56 удалений

Просмотреть файл

@ -4,6 +4,7 @@ import (
"strings"
"github.com/docker/engine-api/types/blkiodev"
"github.com/docker/engine-api/types/mount"
"github.com/docker/engine-api/types/strslice"
"github.com/docker/go-connections/nat"
"github.com/docker/go-units"
@ -317,4 +318,7 @@ type HostConfig struct {
// Contains container's resources (cgroups, ulimits)
Resources
// Mounts specs used by the container
Mounts []mount.Mount `json:",omitempty"`
}

58
types/mount/mount.go Normal file
Просмотреть файл

@ -0,0 +1,58 @@
package mount
// Type represents the type of a mount.
type Type string
const (
// TypeBind BIND
TypeBind Type = "bind"
// TypeVolume VOLUME
TypeVolume Type = "volume"
)
// Mount represents a mount (volume).
type Mount struct {
Type Type `json:",omitempty"`
Source string `json:",omitempty"`
Target string `json:",omitempty"`
ReadOnly bool `json:",omitempty"`
BindOptions *BindOptions `json:",omitempty"`
VolumeOptions *VolumeOptions `json:",omitempty"`
}
// Propagation represents the propagation of a mount.
type Propagation string
const (
// PropagationRPrivate RPRIVATE
PropagationRPrivate Propagation = "rprivate"
// PropagationPrivate PRIVATE
PropagationPrivate Propagation = "private"
// PropagationRShared RSHARED
PropagationRShared Propagation = "rshared"
// PropagationShared SHARED
PropagationShared Propagation = "shared"
// PropagationRSlave RSLAVE
PropagationRSlave Propagation = "rslave"
// PropagationSlave SLAVE
PropagationSlave Propagation = "slave"
)
// BindOptions defines options specific to mounts of type "bind".
type BindOptions struct {
Propagation Propagation `json:",omitempty"`
}
// VolumeOptions represents the options for a mount of type volume.
type VolumeOptions struct {
Populate bool `json:",omitempty"`
Labels map[string]string `json:",omitempty"`
DriverConfig *Driver `json:",omitempty"`
}
// Driver represents a volume driver.
type Driver struct {
Name string `json:",omitempty"`
Options map[string]string `json:",omitempty"`
}

Просмотреть файл

@ -1,6 +1,10 @@
package swarm
import "time"
import (
"time"
"github.com/docker/engine-api/types/mount"
)
// ContainerSpec represents the spec of a container.
type ContainerSpec struct {
@ -11,57 +15,6 @@ type ContainerSpec struct {
Env []string `json:",omitempty"`
Dir string `json:",omitempty"`
User string `json:",omitempty"`
Mounts []Mount `json:",omitempty"`
Mounts []mount.Mount `json:",omitempty"`
StopGracePeriod *time.Duration `json:",omitempty"`
}
// MountType represents the type of a mount.
type MountType string
const (
// MountTypeBind BIND
MountTypeBind MountType = "bind"
// MountTypeVolume VOLUME
MountTypeVolume MountType = "volume"
)
// Mount represents a mount (volume).
type Mount struct {
Type MountType `json:",omitempty"`
Source string `json:",omitempty"`
Target string `json:",omitempty"`
ReadOnly bool `json:",omitempty"`
BindOptions *BindOptions `json:",omitempty"`
VolumeOptions *VolumeOptions `json:",omitempty"`
}
// MountPropagation represents the propagation of a mount.
type MountPropagation string
const (
// MountPropagationRPrivate RPRIVATE
MountPropagationRPrivate MountPropagation = "rprivate"
// MountPropagationPrivate PRIVATE
MountPropagationPrivate MountPropagation = "private"
// MountPropagationRShared RSHARED
MountPropagationRShared MountPropagation = "rshared"
// MountPropagationShared SHARED
MountPropagationShared MountPropagation = "shared"
// MountPropagationRSlave RSLAVE
MountPropagationRSlave MountPropagation = "rslave"
// MountPropagationSlave SLAVE
MountPropagationSlave MountPropagation = "slave"
)
// BindOptions defines options specific to mounts of type "bind".
type BindOptions struct {
Propagation MountPropagation `json:",omitempty"`
}
// VolumeOptions represents the options for a mount of type volume.
type VolumeOptions struct {
NoCopy bool `json:",omitempty"`
Labels map[string]string `json:",omitempty"`
DriverConfig *Driver `json:",omitempty"`
}

Просмотреть файл

@ -92,7 +92,7 @@ type IPAMConfig struct {
Gateway string `json:",omitempty"`
}
// Driver represents a driver (network/volume).
// Driver represents a network driver.
type Driver struct {
Name string `json:",omitempty"`
Options map[string]string `json:",omitempty"`

Просмотреть файл

@ -5,6 +5,7 @@ import (
"time"
"github.com/docker/engine-api/types/container"
"github.com/docker/engine-api/types/mount"
"github.com/docker/engine-api/types/network"
"github.com/docker/engine-api/types/registry"
"github.com/docker/engine-api/types/swarm"
@ -409,14 +410,16 @@ type DefaultNetworkSettings struct {
}
// MountPoint represents a mount point configuration inside the container.
// This is used for reporting the mountpoints in use by a container.
type MountPoint struct {
Name string `json:",omitempty"`
Type mount.Type `json:",omitempty"`
Name string `json:",omitempty"`
Source string
Destination string
Driver string `json:",omitempty"`
Mode string
RW bool
Propagation string
Propagation mount.Propagation
}
// Volume represents the configuration of a volume for the remote API