From d16f9605d541258baffaad97d0723c08dc2cefb5 Mon Sep 17 00:00:00 2001 From: cuigh Date: Wed, 14 Mar 2018 20:16:23 +0800 Subject: [PATCH] Support customizing hostname & hosts --- biz/docker/service.go | 12 ++++++++++-- model/docker.go | 6 ++++++ views/_modules/service.jet | 16 ++++++++++++---- views/service/detail.jet | 16 +++++++++++++--- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/biz/docker/service.go b/biz/docker/service.go index ad88114..7067192 100644 --- a/biz/docker/service.go +++ b/biz/docker/service.go @@ -311,7 +311,11 @@ func ServiceUpdate(info *model.ServiceInfo) error { // nolint: gocyclo } } - // DNS + // Host & DNS + spec.TaskTemplate.ContainerSpec.Hostname = info.Hostname + if info.Hosts != "" { + spec.TaskTemplate.ContainerSpec.Hosts = strings.Split(info.Hosts, "\n") + } spec.TaskTemplate.ContainerSpec.DNSConfig = info.GetDNSConfig() options := types.ServiceUpdateOptions{ @@ -521,7 +525,11 @@ func ServiceCreate(info *model.ServiceInfo) error { // nolint: gocyclo } } - // DNS + // Host & DNS + service.TaskTemplate.ContainerSpec.Hostname = info.Hostname + if info.Hosts != "" { + service.TaskTemplate.ContainerSpec.Hosts = strings.Split(info.Hosts, "\n") + } service.TaskTemplate.ContainerSpec.DNSConfig = info.GetDNSConfig() opts := types.ServiceCreateOptions{EncodedRegistryAuth: info.RegistryAuth} diff --git a/model/docker.go b/model/docker.go index 375145e..dbdcb4b 100644 --- a/model/docker.go +++ b/model/docker.go @@ -236,6 +236,8 @@ type ServiceInfo struct { Search string `json:"search,omitempty"` Options string `json:"options,omitempty"` } `json:"dns"` + Hostname string `json:"hostname"` + Hosts string `json:"hosts"` } func NewServiceInfo(service swarm.Service) *ServiceInfo { @@ -347,6 +349,10 @@ func NewServiceInfo(service swarm.Service) *ServiceInfo { si.DNS.Search = strings.Join(dns.Search, ",") si.DNS.Options = strings.Join(dns.Options, ",") } + si.Hostname = spec.TaskTemplate.ContainerSpec.Hostname + if len(spec.TaskTemplate.ContainerSpec.Hosts) > 0 { + si.Hosts = strings.Join(spec.TaskTemplate.ContainerSpec.Hosts, "\n") + } return si } diff --git a/views/_modules/service.jet b/views/_modules/service.jet index 1f395db..50af073 100644 --- a/views/_modules/service.jet +++ b/views/_modules/service.jet @@ -100,7 +100,7 @@
  • - DNS + Host & DNS
  • @@ -533,17 +533,25 @@
    - + + +
    +
    + + +
    +
    +
    - +
    - +
    diff --git a/views/service/detail.jet b/views/service/detail.jet index 5586cb7..0abecba 100644 --- a/views/service/detail.jet +++ b/views/service/detail.jet @@ -186,7 +186,7 @@
  • - DNS + Host & DNS
  • @@ -421,8 +421,18 @@ {{end}}
    - {{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig }}
    + {{ if .Service.Spec.TaskTemplate.ContainerSpec.Hostname }} +
    Hostname
    +
    {{ .Service.Spec.TaskTemplate.ContainerSpec.Hostname }}
    + {{ end }} + {{ if .Service.Spec.TaskTemplate.ContainerSpec.Hosts }} +
    Hosts
    + {{ range .Service.Spec.TaskTemplate.ContainerSpec.Hosts }} +
    {{ . }}
    + {{ end }} + {{ end }} + {{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig }} {{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Nameservers }}
    Name servers
    {{ join(.Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Nameservers, ",") }}
    @@ -435,8 +445,8 @@
    Options
    {{ join(.Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Options, ",") }}
    {{ end }} + {{ end }}
    - {{ end }}