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>
This commit is contained in:
Tim Hockin 2016-02-13 15:44:05 -08:00
parent 21e531014d
commit 53c5de2921
5 changed files with 7 additions and 33 deletions

View File

@ -44,15 +44,10 @@ type Container struct {
// Sets PATH, HOSTNAME and if container.Config.Tty is set: TERM.
// The defaults set here do not override the values in container.Config.Env
func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
// if a domain name was specified, append it to the hostname (see #7851)
fullHostname := container.Config.Hostname
if container.Config.Domainname != "" {
fullHostname = fmt.Sprintf("%s.%s", fullHostname, container.Config.Domainname)
}
// Setup environment
env := []string{
"PATH=" + system.DefaultPathEnv,
"HOSTNAME=" + fullHostname,
"HOSTNAME=" + container.Config.Hostname,
}
if container.Config.Tty {
env = append(env, "TERM=xterm")
@ -92,10 +87,6 @@ func (container *Container) BuildHostnameFile() error {
return err
}
container.HostnamePath = hostnamePath
if container.Config.Domainname != "" {
return ioutil.WriteFile(container.HostnamePath, []byte(fmt.Sprintf("%s.%s\n", container.Config.Hostname, container.Config.Domainname)), 0644)
}
return ioutil.WriteFile(container.HostnamePath, []byte(container.Config.Hostname+"\n"), 0644)
}

View File

@ -671,13 +671,6 @@ func (daemon *Daemon) initializeNetworking(container *container.Container) error
if err != nil {
return err
}
parts := strings.SplitN(container.Config.Hostname, ".", 2)
if len(parts) > 1 {
container.Config.Hostname = parts[0]
container.Config.Domainname = parts[1]
}
}
if err := daemon.allocateNetwork(container); err != nil {

View File

@ -127,6 +127,7 @@ This section lists each version from latest to oldest. Each listing includes a
* `GET /containers/(id or name)/stats` now returns `pids_stats`, if the kernel is >= 4.3 and the pids cgroup is supported.
* `POST /containers/create` now allows you to override usernamespaces remapping and use privileged options for the container.
* `POST /auth` now returns an `IdentityToken` when supported by a registry.
* `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`.
### v1.22 API changes

View File

@ -241,16 +241,6 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
entrypoint = strslice.StrSlice{*flEntrypoint}
}
var (
domainname string
hostname = *flHostname
parts = strings.SplitN(hostname, ".", 2)
)
if len(parts) > 1 {
hostname = parts[0]
domainname = parts[1]
}
ports, portBindings, err := nat.ParsePortSpecs(flPublish.GetAll())
if err != nil {
return nil, nil, nil, cmd, err
@ -362,8 +352,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
}
config := &container.Config{
Hostname: hostname,
Domainname: domainname,
Hostname: *flHostname,
ExposedPorts: ports,
User: *flUser,
Tty: *flTty,

View File

@ -391,11 +391,11 @@ func TestParseHostname(t *testing.T) {
if config, _ := mustParse(t, hostname); config.Hostname != "hostname" && config.Domainname != "" {
t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
}
if config, _ := mustParse(t, hostnameWithDomain); config.Hostname != "hostname" && config.Domainname != "domainname" {
t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
if config, _ := mustParse(t, hostnameWithDomain); config.Hostname != "hostname.domainname" && config.Domainname != "" {
t.Fatalf("Expected the config to have 'hostname' as hostname.domainname, got '%v'", config.Hostname)
}
if config, _ := mustParse(t, hostnameWithDomainTld); config.Hostname != "hostname" && config.Domainname != "domainname.tld" {
t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
if config, _ := mustParse(t, hostnameWithDomainTld); config.Hostname != "hostname.domainname.tld" && config.Domainname != "" {
t.Fatalf("Expected the config to have 'hostname' as hostname.domainname.tld, got '%v'", config.Hostname)
}
}