mirror of
https://github.com/cuigh/swirl
synced 2024-12-28 23:02:02 +00:00
Add ability to set DNS for service
This commit is contained in:
parent
0ff76725bb
commit
415d92fede
@ -301,6 +301,9 @@ func ServiceUpdate(info *model.ServiceInfo) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DNS
|
||||||
|
spec.TaskTemplate.ContainerSpec.DNSConfig = info.GetDNSConfig()
|
||||||
|
|
||||||
options := types.ServiceUpdateOptions{
|
options := types.ServiceUpdateOptions{
|
||||||
RegistryAuthFrom: types.RegistryAuthFromSpec,
|
RegistryAuthFrom: types.RegistryAuthFromSpec,
|
||||||
QueryRegistry: false,
|
QueryRegistry: false,
|
||||||
@ -504,6 +507,9 @@ func ServiceCreate(info *model.ServiceInfo) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DNS
|
||||||
|
service.TaskTemplate.ContainerSpec.DNSConfig = info.GetDNSConfig()
|
||||||
|
|
||||||
opts := types.ServiceCreateOptions{EncodedRegistryAuth: info.RegistryAuth}
|
opts := types.ServiceCreateOptions{EncodedRegistryAuth: info.RegistryAuth}
|
||||||
var resp types.ServiceCreateResponse
|
var resp types.ServiceCreateResponse
|
||||||
resp, err = cli.ServiceCreate(ctx, service, opts)
|
resp, err = cli.ServiceCreate(ctx, service, opts)
|
||||||
|
@ -15,6 +15,7 @@ var Funcs = map[string]interface{}{
|
|||||||
//"time": func(t time.Time) string {
|
//"time": func(t time.Time) string {
|
||||||
// return t.Local().Format("2006-01-02 15:04:05")
|
// return t.Local().Format("2006-01-02 15:04:05")
|
||||||
//},
|
//},
|
||||||
|
"join": strings.Join,
|
||||||
"eq": func(v1, v2 interface{}) bool {
|
"eq": func(v1, v2 interface{}) bool {
|
||||||
return fmt.Sprint(v1) == fmt.Sprint(v2)
|
return fmt.Sprint(v1) == fmt.Sprint(v2)
|
||||||
},
|
},
|
||||||
|
@ -213,6 +213,11 @@ type ServiceInfo struct {
|
|||||||
Limit ResourceInfo `json:"limit"`
|
Limit ResourceInfo `json:"limit"`
|
||||||
Reserve ResourceInfo `json:"reserve"`
|
Reserve ResourceInfo `json:"reserve"`
|
||||||
} `json:"resource"`
|
} `json:"resource"`
|
||||||
|
DNS struct {
|
||||||
|
Nameservers string `json:"nameservers,omitempty"`
|
||||||
|
Search string `json:"search,omitempty"`
|
||||||
|
Options string `json:"options,omitempty"`
|
||||||
|
} `json:"dns"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceInfo(service swarm.Service) *ServiceInfo {
|
func NewServiceInfo(service swarm.Service) *ServiceInfo {
|
||||||
@ -318,13 +323,37 @@ func NewServiceInfo(service swarm.Service) *ServiceInfo {
|
|||||||
config := NewConfigInfo(c)
|
config := NewConfigInfo(c)
|
||||||
si.Configs = append(si.Configs, config)
|
si.Configs = append(si.Configs, config)
|
||||||
}
|
}
|
||||||
|
if dns := spec.TaskTemplate.ContainerSpec.DNSConfig; dns != nil {
|
||||||
|
si.DNS.Nameservers = strings.Join(dns.Nameservers, ",")
|
||||||
|
si.DNS.Search = strings.Join(dns.Search, ",")
|
||||||
|
si.DNS.Options = strings.Join(dns.Options, ",")
|
||||||
|
}
|
||||||
return si
|
return si
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: finish this method
|
||||||
func (si *ServiceInfo) ToServiceSpec() swarm.ServiceSpec {
|
func (si *ServiceInfo) ToServiceSpec() swarm.ServiceSpec {
|
||||||
return swarm.ServiceSpec{}
|
return swarm.ServiceSpec{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (si *ServiceInfo) GetDNSConfig() *swarm.DNSConfig {
|
||||||
|
if si.DNS.Nameservers == "" && si.DNS.Search == "" && si.DNS.Options == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
c := &swarm.DNSConfig{}
|
||||||
|
if si.DNS.Nameservers != "" {
|
||||||
|
c.Nameservers = strings.Split(si.DNS.Nameservers, ",")
|
||||||
|
}
|
||||||
|
if si.DNS.Search != "" {
|
||||||
|
c.Search = strings.Split(si.DNS.Search, ",")
|
||||||
|
}
|
||||||
|
if si.DNS.Options != "" {
|
||||||
|
c.Options = strings.Split(si.DNS.Options, ",")
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
type EndpointPort struct {
|
type EndpointPort struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Protocol swarm.PortConfigProtocol `json:"protocol"`
|
Protocol swarm.PortConfigProtocol `json:"protocol"`
|
||||||
|
@ -98,6 +98,11 @@
|
|||||||
<span>Log driver</span>
|
<span>Log driver</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a>
|
||||||
|
<span>DNS</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="tab-content" class="tabs-content has-no-top-border">
|
<div id="tab-content" class="tabs-content has-no-top-border">
|
||||||
@ -526,6 +531,22 @@
|
|||||||
{{ yield options_table(name="log_driver.option", items=.Service.LogDriver.Options) }}
|
{{ yield options_table(name="log_driver.option", items=.Service.LogDriver.Options) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div style="display: none">
|
||||||
|
<div class="field">
|
||||||
|
<label class="label">Name servers</label>
|
||||||
|
<div class="control">
|
||||||
|
<input name="dns.nameservers" class="input" value="{{ .Service.DNS.Nameservers }}" placeholder="e.g. 10.10.10.200,10.10.10.201">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label">Search</label>
|
||||||
|
<input name="dns.search" class="input" value="{{ .Service.DNS.Search }}" placeholder="e.g. xxx.com,yyy.net">
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label">Options</label>
|
||||||
|
<input name="dns.options" class="input" value="{{ .Service.DNS.Options }}" placeholder="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
@ -178,6 +178,11 @@
|
|||||||
<span>Log driver</span>
|
<span>Log driver</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a>
|
||||||
|
<span>DNS</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="tab-content" class="tabs-content has-no-top-border">
|
<div id="tab-content" class="tabs-content has-no-top-border">
|
||||||
@ -409,6 +414,24 @@
|
|||||||
</dl>
|
</dl>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
<div style="display: none">
|
||||||
|
{{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig }}
|
||||||
|
<dl class="is-horizontal is-marginless">
|
||||||
|
{{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Nameservers }}
|
||||||
|
<dt class="has-text-left">Name servers</dt>
|
||||||
|
<dd>{{ join(.Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Nameservers, ",") }}</dd>
|
||||||
|
{{ end }}
|
||||||
|
{{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Search }}
|
||||||
|
<dt class="has-text-left">Search</dt>
|
||||||
|
<dd>{{ join(.Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Search, ",") }}</dd>
|
||||||
|
{{ end }}
|
||||||
|
{{ if .Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Options }}
|
||||||
|
<dt class="has-text-left">Options</dt>
|
||||||
|
<dd>{{ join(.Service.Spec.TaskTemplate.ContainerSpec.DNSConfig.Options, ",") }}</dd>
|
||||||
|
{{ end }}
|
||||||
|
</dl>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{if .Tasks}}
|
{{if .Tasks}}
|
||||||
|
Loading…
Reference in New Issue
Block a user