Skip to content

Commit 2f97e75

Browse files
committed
cleanup (and go fmt) of old debug logging since 17.06-ce and re-labeled all changes as follows -
- support sending hostname and domainname in IPAM - support custom volume naming when using netapp volume driver - use dashes as seperators for container names - work in-progress DNS domainname changes - de-duplicate DNS search domains - add container "host" /etc/hosts entry equal to value of DOCKER_HOST_EXPORT_IP environment variable if defined - cleanup duplicate ipvlan and macvlan network IDs during createNetwork (moby/libnetwork#2055) - support optional skip of IPAM pool conflict checking - set Swarm tasks to orphaned state if node becomes unavailable - allow orphaned Swarm tasks assigned to a deleted node to start elseware - Swarm tasks in an orphaned state should not be allowed to restart - allow Swarm tasks in a remove state to be transitioned - prevent oldTaskTimer from allowing the slot to be prematurely updated - allow Swarm tasks to be cleaned up if they are in a pending state and are marked for removal - support service level anti-affinity via label h3o-limitActiveServiceSlotsPerNode
1 parent ad7d1ef commit 2f97e75

File tree

13 files changed

+409
-32
lines changed

13 files changed

+409
-32
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18.01.0-ce
1+
18.01.0-eyz

components/engine/api/types/network/network.go

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ type EndpointIPAMConfig struct {
2626
IPv4Address string `json:",omitempty"`
2727
IPv6Address string `json:",omitempty"`
2828
LinkLocalIPs []string `json:",omitempty"`
29+
// eyz START: support sending hostname and domainname in IPAM
30+
Hostname string `json:",omitempty"`
31+
Domainname string `json:",omitempty"`
32+
// eyz END: support sending hostname and domainname in IPAM
2933
}
3034

3135
// Copy makes a copy of the endpoint ipam config

components/engine/container/container.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,11 @@ func (container *Container) BuildJoinOptions(n named) ([]libnetwork.EndpointOpti
709709
return nil, err
710710
}
711711
joinOptions = append(joinOptions, libnetwork.CreateOptionAlias(name, alias))
712+
// eyz START: add network alias which includes the container FQDN (Hostname + Domainname)
713+
if container.Config.Domainname != "" {
714+
joinOptions = append(joinOptions, libnetwork.CreateOptionAlias(name, container.Config.Hostname+"."+container.Config.Domainname))
715+
}
716+
// eyz STOP: add network alias which includes the container FQDN (Hostname + Domainname)
712717
}
713718
for k, v := range epConfig.DriverOpts {
714719
joinOptions = append(joinOptions, libnetwork.EndpointOptionGeneric(options.Generic{k: v}))
@@ -759,8 +764,10 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epC
759764
return nil, errors.Errorf("Invalid IPv6 address: %s)", ipam.IPv6Address)
760765
}
761766

767+
// eyz START: support sending hostname and domainname in IPAM
762768
createOptions = append(createOptions,
763-
libnetwork.CreateOptionIpam(ip, ip6, ipList, nil))
769+
libnetwork.CreateOptionIpam(ip, ip6, ipList, ipam.Hostname, ipam.Domainname, nil))
770+
// eyz END: support sending hostname and domainname in IPAM
764771

765772
}
766773

components/engine/daemon/cluster/executor/container/adapter.go

+7
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ func (c *containerAdapter) createVolumes(ctx context.Context) error {
382382
continue
383383
}
384384

385+
// eyz START: support custom volume naming when using netapp volume driver
386+
// Isaac (20171022): do not create netapp volumes here; we currently let them get created by the container.go code instead
387+
if mount.VolumeOptions.DriverConfig.Name == "netapp" {
388+
continue
389+
}
390+
// eyz END: support custom volume naming when using netapp volume driver
391+
385392
req := c.container.volumeCreateRequest(&mount)
386393

387394
// Check if this volume exists on the engine

components/engine/daemon/cluster/executor/container/container.go

+98-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"errors"
55
"fmt"
66
"net"
7+
// eyz START: support custom volume naming when using netapp volume driver
8+
"regexp"
9+
// eyz STOP: support custom volume naming when using netapp volume driver
710
"strconv"
811
"strings"
912
"time"
@@ -131,7 +134,16 @@ func (c *containerConfig) name() string {
131134
}
132135

133136
// fallback to service.slot.id.
134-
return fmt.Sprintf("%s.%s.%s", c.task.ServiceAnnotations.Name, slot, c.task.ID)
137+
// eyz START: support custom volume naming when using netapp volume driver, use dashes as seperators for container names
138+
//return fmt.Sprintf("%s.%s.%s", c.task.ServiceAnnotations.Name, slot, c.task.ID)
139+
// only override container name if we are using a netapp mount volume driver
140+
if c.hasMountDriverName("netapp") {
141+
return fmt.Sprintf("%s-%s", c.task.ServiceAnnotations.Name, slot)
142+
} else {
143+
return fmt.Sprintf("%s-%s-%s", c.task.ServiceAnnotations.Name, slot, c.task.ID)
144+
}
145+
// eyz END: support custom volume naming when using netapp volume driver, use dashes as seperators for container names
146+
135147
}
136148

137149
func (c *containerConfig) image() string {
@@ -208,6 +220,40 @@ func (c *containerConfig) config() *enginecontainer.Config {
208220
Healthcheck: c.healthcheck(),
209221
}
210222

223+
// eyz START: support custom volume naming when using netapp volume driver, use dashes as seperators for container names, work in-progress DNS domainname changes
224+
// If we have a defined service name and slot ...
225+
if c.task != nil && c.task.ServiceAnnotations.Name != "" && c.task.Slot > 0 {
226+
227+
slot := fmt.Sprint(c.task.Slot)
228+
if slot == "" || c.task.Slot == 0 {
229+
slot = c.task.NodeID
230+
}
231+
232+
if c.hasMountDriverName("netapp") {
233+
// ... and we're using a netapp mount volume driver, then set the Hostname to "SERVICENAME-SLOT"
234+
config.Hostname = fmt.Sprintf("%s-%s", c.task.ServiceAnnotations.Name, slot)
235+
} else {
236+
// ... otherwise, set the Hostname "SERVICENAME-SLOT-TASKID"
237+
config.Hostname = fmt.Sprintf("%s-%s-%s", c.task.ServiceAnnotations.Name, slot, c.task.ID)
238+
}
239+
240+
///// testing START
241+
stackNamespace, stackNamespaceExists := c.task.ServiceAnnotations.Labels["com.docker.stack.namespace"]
242+
if stackNamespaceExists {
243+
//config.Domainname = fmt.Sprintf("%s.swarm.DOMAIN.COM", stackNamespace)
244+
// doesn't work
245+
// config.Domainname = stackNamespace + "-test"
246+
// config.Domainname = stackNamespace + ".swarm"
247+
// works -
248+
config.Domainname = stackNamespace
249+
} else {
250+
config.Domainname = "nostack"
251+
}
252+
logrus.Debugf("* engine/daemon/cluster/executor/container config() set config.Domainname to: %s", config.Domainname)
253+
///// testing STOP
254+
}
255+
// eyz STOP: support custom volume naming when using netapp volume driver, use dashes as seperators for container names, work in-progress DNS domainname changes
256+
211257
if len(c.spec().Command) > 0 {
212258
// If Command is provided, we replace the whole invocation with Command
213259
// by replacing Entrypoint and specifying Cmd. Args is ignored in this
@@ -255,14 +301,51 @@ func (c *containerConfig) labels() map[string]string {
255301
return labels
256302
}
257303

304+
// eyz START: support custom volume naming when using netapp volume driver
305+
// helper function to find if a mount volume driver name was found
306+
func (c *containerConfig) hasMountDriverName(mountDriverName string) bool {
307+
for _, mount := range c.spec().Mounts {
308+
m := convertMount(mount)
309+
if m.VolumeOptions != nil && m.VolumeOptions.DriverConfig != nil && m.VolumeOptions.DriverConfig.Name == mountDriverName {
310+
return true
311+
}
312+
}
313+
return false
314+
}
315+
316+
// eyz END: support custom volume naming when using netapp volume driver
317+
318+
// eyz START: support custom volume naming when using netapp volume driver
258319
func (c *containerConfig) mounts() []enginemount.Mount {
259320
var r []enginemount.Mount
321+
nonWordRegex, _ := regexp.Compile("[^a-zA-Z0-9]+")
260322
for _, mount := range c.spec().Mounts {
261-
r = append(r, convertMount(mount))
323+
m := convertMount(mount)
324+
if m.VolumeOptions != nil && m.VolumeOptions.DriverConfig != nil && m.VolumeOptions.DriverConfig.Name == "netapp" && c.task != nil && c.task.ServiceAnnotations.Name != "" && c.task.Slot > 0 {
325+
slot := fmt.Sprint(c.task.Slot)
326+
if slot == "" || c.task.Slot == 0 {
327+
slot = c.task.NodeID
328+
}
329+
330+
var newSourceRaw string
331+
// if m.Source starts with c.task.ServiceAnnotations.Name, then don't include the c.task.ServiceAnnotations.Name prepend in the new volume Source; only the m.Source and slot, as c.task.ServiceAnnotations.Name would be redundant in this case
332+
if strings.HasPrefix(m.Source, c.task.ServiceAnnotations.Name) {
333+
newSourceRaw = fmt.Sprintf("%s_%s", m.Source, slot)
334+
} else {
335+
newSourceRaw = fmt.Sprintf("%s_%s_%s", c.task.ServiceAnnotations.Name, m.Source, slot)
336+
}
337+
// for compatibility with the NetApp Docker Volume Plugin, ensure all contiguous non-word characters are replaced with underscores
338+
m.Source = nonWordRegex.ReplaceAllString(newSourceRaw, "_")
339+
}
340+
r = append(r, m)
341+
//r = append(r, convertMount(mount))
342+
262343
}
263344
return r
264345
}
265346

347+
// eyz END: support custom volume naming when using netapp volume driver
348+
266349
func convertMount(m api.Mount) enginemount.Mount {
267350
mount := enginemount.Mount{
268351
Source: m.Source,
@@ -363,6 +446,19 @@ func (c *containerConfig) hostConfig() *enginecontainer.HostConfig {
363446
hc.DNSOptions = c.spec().DNSConfig.Options
364447
}
365448

449+
// eyz START: work in-progress DNS domainname changes
450+
stackNamespace, stackNamespaceExists := c.task.ServiceAnnotations.Labels["com.docker.stack.namespace"]
451+
if stackNamespaceExists {
452+
//stackNamespaceSearchDomainPrepend := []string{fmt.Sprintf("%s.swarm.DOMAIN.COM", stackNamespace)}
453+
stackNamespaceSearchDomainPrepend := []string{stackNamespace}
454+
if len(hc.DNSSearch) > 0 {
455+
hc.DNSSearch = append(stackNamespaceSearchDomainPrepend, hc.DNSSearch...)
456+
} else {
457+
hc.DNSSearch = stackNamespaceSearchDomainPrepend
458+
}
459+
}
460+
// eyz STOP: work in-progress DNS domainname changes
461+
366462
c.applyPrivileges(hc)
367463

368464
// The format of extra hosts on swarmkit is specified in:

components/engine/daemon/container_operations.go

+77-5
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,43 @@ var (
3232
getPortMapInfo = container.GetSandboxPortMapInfo
3333
)
3434

35-
func (daemon *Daemon) getDNSSearchSettings(container *container.Container) []string {
36-
if len(container.HostConfig.DNSSearch) > 0 {
37-
return container.HostConfig.DNSSearch
35+
// eyz START: de-duplicate DNS search domains
36+
func removeDuplicates(elements []string) []string {
37+
seen := map[string]bool{}
38+
result := []string{}
39+
40+
for _, element := range elements {
41+
if !seen[element] {
42+
seen[element] = true
43+
result = append(result, element)
44+
}
3845
}
46+
return result
47+
}
48+
49+
// eyz STOP: de-duplicate DNS search domains
50+
51+
// eyz START: de-duplicate DNS search domains
52+
func (daemon *Daemon) getDNSSearchSettings(container *container.Container) []string {
53+
/*
54+
if len(container.HostConfig.DNSSearch) > 0 {
55+
return container.HostConfig.DNSSearch
56+
}
57+
58+
if len(daemon.configStore.DNSSearch) > 0 {
59+
return daemon.configStore.DNSSearch
60+
}
61+
*/
3962

40-
if len(daemon.configStore.DNSSearch) > 0 {
41-
return daemon.configStore.DNSSearch
63+
if len(container.HostConfig.DNSSearch) > 0 || len(daemon.configStore.DNSSearch) > 0 {
64+
return removeDuplicates(append(container.HostConfig.DNSSearch, daemon.configStore.DNSSearch...))
4265
}
4366

4467
return nil
4568
}
4669

70+
// eyz STOP: de-duplicate DNS search domains
71+
4772
func (daemon *Daemon) buildSandboxOptions(container *container.Container) ([]libnetwork.SandboxOption, error) {
4873
var (
4974
sboxOptions []libnetwork.SandboxOption
@@ -116,15 +141,51 @@ func (daemon *Daemon) buildSandboxOptions(container *container.Container) ([]lib
116141
}
117142
}
118143

144+
// eyz START: add container "host" /etc/hosts entry equal to value of DOCKER_HOST_EXPORT_IP environment variable if defined
145+
// NOTE: if env var DOCKER_HOST_EXPORT_IP is set on the host, then
146+
// 1) we intend to create a hosts entry of "host" with the value of DOCKER_HOST_EXPORT_IP -- dockerHostExportIpAppendHost will be set: true
147+
// 2) we intend to persist this environment variable into each launched container
148+
dockerHostExportIpVal, dockerHostExportIpEnvExported := os.LookupEnv("DOCKER_HOST_EXPORT_IP")
149+
// dockerHostExportIpAppendHost defaults to true if dockerHostExportIpEnvExported
150+
dockerHostExportIpAppendHost := dockerHostExportIpEnvExported
151+
// eyz STOP: add container "host" /etc/hosts entry equal to value of DOCKER_HOST_EXPORT_IP environment variable if defined
152+
119153
for _, extraHost := range container.HostConfig.ExtraHosts {
120154
// allow IPv6 addresses in extra hosts; only split on first ":"
121155
if _, err := opts.ValidateExtraHost(extraHost); err != nil {
122156
return nil, err
123157
}
124158
parts := strings.SplitN(extraHost, ":", 2)
159+
160+
// eyz START: add container "host" /etc/hosts entry equal to value of DOCKER_HOST_EXPORT_IP environment variable if defined
161+
// NOTE: if an extraHost entry for "host" (case-insensitive) has been specified, then we will not append the DOCKER_HOST_EXPORT_IP -- letting this extraHost of "host" override DOCKER_HOST_EXPORT_IP even if it is set
162+
if strings.ToLower(parts[0]) == "host" {
163+
dockerHostExportIpAppendHost = false
164+
}
165+
// eyz STOP: add container "host" /etc/hosts entry equal to value of DOCKER_HOST_EXPORT_IP environment variable if defined
166+
125167
sboxOptions = append(sboxOptions, libnetwork.OptionExtraHost(parts[0], parts[1]))
126168
}
127169

170+
// eyz START: add container "host" /etc/hosts entry equal to value of DOCKER_HOST_EXPORT_IP environment variable if defined
171+
// NOTE: if env var DOCKER_HOST_EXPORT_IP is set on the host, then create a hosts entry of "host" with the value of DOCKER_HOST_EXPORT_IP
172+
if dockerHostExportIpAppendHost {
173+
sboxOptions = append(sboxOptions, libnetwork.OptionExtraHost("host", dockerHostExportIpVal))
174+
}
175+
176+
if dockerHostExportIpEnvExported {
177+
dockerHostExportIpEnvInConfig := false
178+
for _, envValue := range container.Config.Env {
179+
if strings.HasPrefix(strings.ToUpper(envValue), "DOCKER_HOST_EXPORT_IP=") {
180+
dockerHostExportIpEnvInConfig = true
181+
}
182+
}
183+
if !dockerHostExportIpEnvInConfig {
184+
container.Config.Env = append(container.Config.Env, fmt.Sprintf("DOCKER_HOST_EXPORT_IP=%s", dockerHostExportIpVal))
185+
}
186+
}
187+
// eyz STOP: add container "host" /etc/hosts entry equal to value of DOCKER_HOST_EXPORT_IP environment variable if defined
188+
128189
if container.HostConfig.PortBindings != nil {
129190
for p, b := range container.HostConfig.PortBindings {
130191
bindings[p] = []nat.PortBinding{}
@@ -719,6 +780,17 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName
719780
}
720781
}
721782

783+
// eyz START: support sending hostname and domainname in IPAM
784+
if endpointConfig.IPAMConfig != nil {
785+
if container.Config.Hostname != "" {
786+
endpointConfig.IPAMConfig.Hostname = container.Config.Hostname
787+
}
788+
if container.Config.Domainname != "" {
789+
endpointConfig.IPAMConfig.Domainname = container.Config.Domainname
790+
}
791+
}
792+
// eyz END: support sending hostname and domainname in IPAM
793+
722794
err = daemon.updateNetworkConfig(container, n, endpointConfig, updateSettings)
723795
if err != nil {
724796
return err

components/engine/vendor/github.com/docker/libnetwork/drivers/ipvlan/ipvlan_network.go

+19-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/engine/vendor/github.com/docker/libnetwork/endpoint.go

+17-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)