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

- Removed sandbox override option from the driver.

- Reworked the host network mode support by introducing
  a new JoinOption.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
Jana Radhakrishnan 2015-05-05 04:20:45 +00:00
parent a983569c0c
commit 55099e9656
5 changed files with 45 additions and 34 deletions

View file

@ -56,7 +56,5 @@ type Driver interface {
// JoinInfo represents a set of resources that the driver has the ability to provide during
// join time.
type JoinInfo struct {
SandboxKey string
NoSandboxCreate bool
HostsPath string
HostsPath string
}

View file

@ -42,9 +42,7 @@ func (d *driver) EndpointInfo(nid, eid types.UUID) (map[string]interface{}, erro
// Join method is invoked when a Sandbox is attached to an endpoint.
func (d *driver) Join(nid, eid types.UUID, sboxKey string, options map[string]interface{}) (*driverapi.JoinInfo, error) {
jInfo := &driverapi.JoinInfo{
SandboxKey: sandbox.GenerateKey("host"),
NoSandboxCreate: true,
HostsPath: "/etc/hosts",
HostsPath: "/etc/hosts",
}
return jInfo, nil

View file

@ -54,18 +54,29 @@ type ContainerData struct {
SandboxKey string
}
type containerConfig struct {
hostName string
domainName string
generic map[string]interface{}
hostsPath string
ExtraHosts []extraHost
parentUpdates []parentUpdate
// These are the container configs used to customize container /etc/hosts file.
type hostsPathConfig struct {
hostName string
domainName string
hostsPath string
extraHosts []extraHost
parentUpdates []parentUpdate
}
// These are the container configs used to customize container /etc/resolv.conf file.
type resolvConfPathConfig struct {
resolvConfPath string
dnsList []string
dnsSearchList []string
}
type containerConfig struct {
hostsPathConfig
resolvConfPathConfig
generic map[string]interface{}
useDefaultSandBox bool
}
type extraHost struct {
name string
IP string
@ -168,8 +179,10 @@ func (ep *endpoint) Join(containerID string, options ...EndpointOption) (*Contai
ep.container = &containerInfo{
config: containerConfig{
ExtraHosts: []extraHost{},
parentUpdates: []parentUpdate{},
hostsPathConfig: hostsPathConfig{
extraHosts: []extraHost{},
parentUpdates: []parentUpdate{},
},
}}
defer func() {
if err != nil {
@ -188,6 +201,9 @@ func (ep *endpoint) Join(containerID string, options ...EndpointOption) (*Contai
}
sboxKey := sandbox.GenerateKey(containerID)
if ep.container.config.useDefaultSandBox {
sboxKey = sandbox.GenerateKey("default")
}
joinInfo, err := ep.network.driver.Join(ep.network.id, ep.id,
sboxKey, ep.container.config.generic)
@ -211,18 +227,8 @@ func (ep *endpoint) Join(containerID string, options ...EndpointOption) (*Contai
return nil, err
}
create := true
if joinInfo != nil {
if joinInfo.SandboxKey != "" {
sboxKey = joinInfo.SandboxKey
}
if joinInfo.NoSandboxCreate {
create = false
}
}
sb, err := ep.network.ctrlr.sandboxAdd(sboxKey, create)
sb, err := ep.network.ctrlr.sandboxAdd(sboxKey,
!ep.container.config.useDefaultSandBox)
if err != nil {
return nil, err
}
@ -325,7 +331,7 @@ func (ep *endpoint) buildHostsFiles() error {
name = name + "." + ep.container.config.domainName
}
for _, extraHost := range ep.container.config.ExtraHosts {
for _, extraHost := range ep.container.config.extraHosts {
extraContent = append(extraContent,
etchosts.Record{Hosts: extraHost.name, IP: extraHost.IP})
}
@ -432,7 +438,7 @@ func JoinOptionHostsPath(path string) EndpointOption {
// which is a name and IP as strings.
func JoinOptionExtraHost(name string, IP string) EndpointOption {
return func(ep *endpoint) {
ep.container.config.ExtraHosts = append(ep.container.config.ExtraHosts, extraHost{name: name, IP: IP})
ep.container.config.extraHosts = append(ep.container.config.extraHosts, extraHost{name: name, IP: IP})
}
}
@ -468,6 +474,14 @@ func JoinOptionDNSSearch(search string) EndpointOption {
}
}
// JoinOptionUseDefaultSandbox function returns an option setter for using default sandbox to
// be passed to endpoint Join method.
func JoinOptionUseDefaultSandbox() EndpointOption {
return func(ep *endpoint) {
ep.container.config.useDefaultSandBox = true
}
}
// CreateOptionPortMapping function returns an option setter for the container exposed
// ports option to be passed to network.CreateEndpoint() method.
func CreateOptionPortMapping(portBindings []netutils.PortBinding) EndpointOption {

View file

@ -103,7 +103,8 @@ func TestHost(t *testing.T) {
_, err = ep.Join("host_container",
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
libnetwork.JoinOptionUseDefaultSandbox())
if err != nil {
t.Fatal(err)
}

View file

@ -44,8 +44,8 @@ func GenerateKey(containerID string) string {
// NewSandbox provides a new sandbox instance created in an os specific way
// provided a key which uniquely identifies the sandbox
func NewSandbox(key string, create bool) (Sandbox, error) {
info, err := createNetworkNamespace(key, create)
func NewSandbox(key string, osCreate bool) (Sandbox, error) {
info, err := createNetworkNamespace(key, osCreate)
if err != nil {
return nil, err
}
@ -53,7 +53,7 @@ func NewSandbox(key string, create bool) (Sandbox, error) {
return &networkNamespace{path: key, sinfo: info}, nil
}
func createNetworkNamespace(path string, create bool) (*Info, error) {
func createNetworkNamespace(path string, osCreate bool) (*Info, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
@ -67,7 +67,7 @@ func createNetworkNamespace(path string, create bool) (*Info, error) {
return nil, err
}
if create {
if osCreate {
defer netns.Set(origns)
newns, err := netns.New()
if err != nil {