Browse code

Don't smoosh hostname and domainname in API

This allows users to provide a FQDN as hostname or to use distinct hostname and
domainname parts. Depends on https://github.com/docker/libnetwork/pull/950

Signed-off-by: Tim Hockin <thockin@google.com>

Tim Hockin authored on 2016/02/14 08:44:05
Showing 5 changed files
... ...
@@ -44,15 +44,10 @@ type Container struct {
44 44
 // Sets PATH, HOSTNAME and if container.Config.Tty is set: TERM.
45 45
 // The defaults set here do not override the values in container.Config.Env
46 46
 func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
47
-	// if a domain name was specified, append it to the hostname (see #7851)
48
-	fullHostname := container.Config.Hostname
49
-	if container.Config.Domainname != "" {
50
-		fullHostname = fmt.Sprintf("%s.%s", fullHostname, container.Config.Domainname)
51
-	}
52 47
 	// Setup environment
53 48
 	env := []string{
54 49
 		"PATH=" + system.DefaultPathEnv,
55
-		"HOSTNAME=" + fullHostname,
50
+		"HOSTNAME=" + container.Config.Hostname,
56 51
 	}
57 52
 	if container.Config.Tty {
58 53
 		env = append(env, "TERM=xterm")
... ...
@@ -92,10 +87,6 @@ func (container *Container) BuildHostnameFile() error {
92 92
 		return err
93 93
 	}
94 94
 	container.HostnamePath = hostnamePath
95
-
96
-	if container.Config.Domainname != "" {
97
-		return ioutil.WriteFile(container.HostnamePath, []byte(fmt.Sprintf("%s.%s\n", container.Config.Hostname, container.Config.Domainname)), 0644)
98
-	}
99 95
 	return ioutil.WriteFile(container.HostnamePath, []byte(container.Config.Hostname+"\n"), 0644)
100 96
 }
101 97
 
... ...
@@ -671,13 +671,6 @@ func (daemon *Daemon) initializeNetworking(container *container.Container) error
671 671
 		if err != nil {
672 672
 			return err
673 673
 		}
674
-
675
-		parts := strings.SplitN(container.Config.Hostname, ".", 2)
676
-		if len(parts) > 1 {
677
-			container.Config.Hostname = parts[0]
678
-			container.Config.Domainname = parts[1]
679
-		}
680
-
681 674
 	}
682 675
 
683 676
 	if err := daemon.allocateNetwork(container); err != nil {
... ...
@@ -127,6 +127,7 @@ This section lists each version from latest to oldest.  Each listing includes a
127 127
 * `GET /containers/(id or name)/stats` now returns `pids_stats`, if the kernel is >= 4.3 and the pids cgroup is supported.
128 128
 * `POST /containers/create` now allows you to override usernamespaces remapping and use privileged options for the container.
129 129
 * `POST /auth` now returns an `IdentityToken` when supported by a registry.
130
+* `POST /containers/create` with both `Hostname` and `Domainname` fields specified will result in the container's hostname being set to `Hostname`, rather than `Hostname.Domainname`.
130 131
 
131 132
 ### v1.22 API changes
132 133
 
... ...
@@ -241,16 +241,6 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
241 241
 		entrypoint = strslice.StrSlice{*flEntrypoint}
242 242
 	}
243 243
 
244
-	var (
245
-		domainname string
246
-		hostname   = *flHostname
247
-		parts      = strings.SplitN(hostname, ".", 2)
248
-	)
249
-	if len(parts) > 1 {
250
-		hostname = parts[0]
251
-		domainname = parts[1]
252
-	}
253
-
254 244
 	ports, portBindings, err := nat.ParsePortSpecs(flPublish.GetAll())
255 245
 	if err != nil {
256 246
 		return nil, nil, nil, cmd, err
... ...
@@ -362,8 +352,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
362 362
 	}
363 363
 
364 364
 	config := &container.Config{
365
-		Hostname:     hostname,
366
-		Domainname:   domainname,
365
+		Hostname:     *flHostname,
367 366
 		ExposedPorts: ports,
368 367
 		User:         *flUser,
369 368
 		Tty:          *flTty,
... ...
@@ -391,11 +391,11 @@ func TestParseHostname(t *testing.T) {
391 391
 	if config, _ := mustParse(t, hostname); config.Hostname != "hostname" && config.Domainname != "" {
392 392
 		t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
393 393
 	}
394
-	if config, _ := mustParse(t, hostnameWithDomain); config.Hostname != "hostname" && config.Domainname != "domainname" {
395
-		t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
394
+	if config, _ := mustParse(t, hostnameWithDomain); config.Hostname != "hostname.domainname" && config.Domainname != "" {
395
+		t.Fatalf("Expected the config to have 'hostname' as hostname.domainname, got '%v'", config.Hostname)
396 396
 	}
397
-	if config, _ := mustParse(t, hostnameWithDomainTld); config.Hostname != "hostname" && config.Domainname != "domainname.tld" {
398
-		t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
397
+	if config, _ := mustParse(t, hostnameWithDomainTld); config.Hostname != "hostname.domainname.tld" && config.Domainname != "" {
398
+		t.Fatalf("Expected the config to have 'hostname' as hostname.domainname.tld, got '%v'", config.Hostname)
399 399
 	}
400 400
 }
401 401