|
4 | 4 | "errors"
|
5 | 5 | "fmt"
|
6 | 6 | "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 |
7 | 10 | "strconv"
|
8 | 11 | "strings"
|
9 | 12 | "time"
|
@@ -131,7 +134,16 @@ func (c *containerConfig) name() string {
|
131 | 134 | }
|
132 | 135 |
|
133 | 136 | // 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 | + |
135 | 147 | }
|
136 | 148 |
|
137 | 149 | func (c *containerConfig) image() string {
|
@@ -208,6 +220,40 @@ func (c *containerConfig) config() *enginecontainer.Config {
|
208 | 220 | Healthcheck: c.healthcheck(),
|
209 | 221 | }
|
210 | 222 |
|
| 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 | + |
211 | 257 | if len(c.spec().Command) > 0 {
|
212 | 258 | // If Command is provided, we replace the whole invocation with Command
|
213 | 259 | // by replacing Entrypoint and specifying Cmd. Args is ignored in this
|
@@ -255,14 +301,51 @@ func (c *containerConfig) labels() map[string]string {
|
255 | 301 | return labels
|
256 | 302 | }
|
257 | 303 |
|
| 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 |
258 | 319 | func (c *containerConfig) mounts() []enginemount.Mount {
|
259 | 320 | var r []enginemount.Mount
|
| 321 | + nonWordRegex, _ := regexp.Compile("[^a-zA-Z0-9]+") |
260 | 322 | 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 | + |
262 | 343 | }
|
263 | 344 | return r
|
264 | 345 | }
|
265 | 346 |
|
| 347 | +// eyz END: support custom volume naming when using netapp volume driver |
| 348 | + |
266 | 349 | func convertMount(m api.Mount) enginemount.Mount {
|
267 | 350 | mount := enginemount.Mount{
|
268 | 351 | Source: m.Source,
|
@@ -363,6 +446,19 @@ func (c *containerConfig) hostConfig() *enginecontainer.HostConfig {
|
363 | 446 | hc.DNSOptions = c.spec().DNSConfig.Options
|
364 | 447 | }
|
365 | 448 |
|
| 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 | + |
366 | 462 | c.applyPrivileges(hc)
|
367 | 463 |
|
368 | 464 | // The format of extra hosts on swarmkit is specified in:
|
|
0 commit comments