Support customizing hostname & hosts

This commit is contained in:
cuigh 2018-03-14 20:16:23 +08:00
parent 5fa31d9afe
commit d16f9605d5
4 changed files with 41 additions and 9 deletions

View File

@ -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() spec.TaskTemplate.ContainerSpec.DNSConfig = info.GetDNSConfig()
options := types.ServiceUpdateOptions{ 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() service.TaskTemplate.ContainerSpec.DNSConfig = info.GetDNSConfig()
opts := types.ServiceCreateOptions{EncodedRegistryAuth: info.RegistryAuth} opts := types.ServiceCreateOptions{EncodedRegistryAuth: info.RegistryAuth}

View File

@ -236,6 +236,8 @@ type ServiceInfo struct {
Search string `json:"search,omitempty"` Search string `json:"search,omitempty"`
Options string `json:"options,omitempty"` Options string `json:"options,omitempty"`
} `json:"dns"` } `json:"dns"`
Hostname string `json:"hostname"`
Hosts string `json:"hosts"`
} }
func NewServiceInfo(service swarm.Service) *ServiceInfo { 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.Search = strings.Join(dns.Search, ",")
si.DNS.Options = strings.Join(dns.Options, ",") 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 return si
} }

View File

@ -100,7 +100,7 @@
</li> </li>
<li> <li>
<a> <a>
<span>DNS</span> <span>Host & DNS</span>
</a> </a>
</li> </li>
</ul> </ul>
@ -533,17 +533,25 @@
</div> </div>
<div style="display: none"> <div style="display: none">
<div class="field"> <div class="field">
<label class="label">Name servers</label> <label class="label">Hostname</label>
<input name="hostname" class="input" value="{{ .Service.Hostname }}" placeholder="">
</div>
<div class="field">
<label class="label">Hosts</label>
<textarea name="hosts" class="textarea" placeholder="IP_address canonical_hostname [aliases...]">{{ .Service.Hosts }}</textarea>
</div>
<div class="field">
<label class="label">DNS name servers</label>
<div class="control"> <div class="control">
<input name="dns.nameservers" class="input" value="{{ .Service.DNS.Nameservers }}" placeholder="e.g. 10.10.10.200,10.10.10.201"> <input name="dns.nameservers" class="input" value="{{ .Service.DNS.Nameservers }}" placeholder="e.g. 10.10.10.200,10.10.10.201">
</div> </div>
</div> </div>
<div class="field"> <div class="field">
<label class="label">Search</label> <label class="label">DNS search</label>
<input name="dns.search" class="input" value="{{ .Service.DNS.Search }}" placeholder="e.g. xxx.com,yyy.net"> <input name="dns.search" class="input" value="{{ .Service.DNS.Search }}" placeholder="e.g. xxx.com,yyy.net">
</div> </div>
<div class="field"> <div class="field">
<label class="label">Options</label> <label class="label">DNS options</label>
<input name="dns.options" class="input" value="{{ .Service.DNS.Options }}" placeholder=""> <input name="dns.options" class="input" value="{{ .Service.DNS.Options }}" placeholder="">
</div> </div>
</div> </div>

View File

@ -186,7 +186,7 @@
</li> </li>
<li> <li>
<a> <a>
<span>DNS</span> <span>Host & DNS</span>
</a> </a>
</li> </li>
</ul> </ul>
@ -421,8 +421,18 @@
{{end}} {{end}}
</div> </div>
<div style="display: none"> <div style="display: none">
{{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig }}
<dl class="is-horizontal is-marginless"> <dl class="is-horizontal is-marginless">
{{ if .Service.Spec.TaskTemplate.ContainerSpec.Hostname }}
<dt class="has-text-left">Hostname</dt>
<dd>{{ .Service.Spec.TaskTemplate.ContainerSpec.Hostname }}</dd>
{{ end }}
{{ if .Service.Spec.TaskTemplate.ContainerSpec.Hosts }}
<dt class="has-text-left">Hosts</dt>
{{ range .Service.Spec.TaskTemplate.ContainerSpec.Hosts }}
<dd>{{ . }}</dd>
{{ end }}
{{ end }}
{{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig }}
{{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Nameservers }} {{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Nameservers }}
<dt class="has-text-left">Name servers</dt> <dt class="has-text-left">Name servers</dt>
<dd>{{ join(.Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Nameservers, ",") }}</dd> <dd>{{ join(.Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Nameservers, ",") }}</dd>
@ -435,8 +445,8 @@
<dt class="has-text-left">Options</dt> <dt class="has-text-left">Options</dt>
<dd>{{ join(.Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Options, ",") }}</dd> <dd>{{ join(.Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Options, ",") }}</dd>
{{ end }} {{ end }}
{{ end }}
</dl> </dl>
{{ end }}
</div> </div>
</div> </div>