mirror of https://github.com/docker/cli.git
Merge pull request #28186 from yongtang/27567-follow-up-dns-options
Add `--dns-option` to `docker run` and hide `--dns-opt`
This commit is contained in:
commit
c5fbdc8572
|
@ -43,7 +43,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
flags.VarP(&opts.endpoint.ports, flagPublish, "p", "Publish a port as a node port")
|
||||
flags.Var(&opts.groups, flagGroup, "Set one or more supplementary user groups for the container")
|
||||
flags.Var(&opts.dns, flagDNS, "Set custom DNS servers")
|
||||
flags.Var(&opts.dnsOptions, flagDNSOptions, "Set DNS options")
|
||||
flags.Var(&opts.dnsOption, flagDNSOption, "Set DNS options")
|
||||
flags.Var(&opts.dnsSearch, flagDNSSearch, "Set custom DNS search domains")
|
||||
|
||||
flags.SetInterspersed(false)
|
||||
|
|
|
@ -413,7 +413,7 @@ type serviceOptions struct {
|
|||
mounts opts.MountOpt
|
||||
dns opts.ListOpts
|
||||
dnsSearch opts.ListOpts
|
||||
dnsOptions opts.ListOpts
|
||||
dnsOption opts.ListOpts
|
||||
|
||||
resources resourceOptions
|
||||
stopGrace DurationOpt
|
||||
|
@ -445,12 +445,12 @@ func newServiceOptions() *serviceOptions {
|
|||
endpoint: endpointOptions{
|
||||
ports: opts.NewListOpts(ValidatePort),
|
||||
},
|
||||
groups: opts.NewListOpts(nil),
|
||||
logDriver: newLogDriverOptions(),
|
||||
dns: opts.NewListOpts(opts.ValidateIPAddress),
|
||||
dnsOptions: opts.NewListOpts(nil),
|
||||
dnsSearch: opts.NewListOpts(opts.ValidateDNSSearch),
|
||||
networks: opts.NewListOpts(nil),
|
||||
groups: opts.NewListOpts(nil),
|
||||
logDriver: newLogDriverOptions(),
|
||||
dns: opts.NewListOpts(opts.ValidateIPAddress),
|
||||
dnsOption: opts.NewListOpts(nil),
|
||||
dnsSearch: opts.NewListOpts(opts.ValidateDNSSearch),
|
||||
networks: opts.NewListOpts(nil),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -496,7 +496,7 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
|
|||
DNSConfig: &swarm.DNSConfig{
|
||||
Nameservers: opts.dns.GetAll(),
|
||||
Search: opts.dnsSearch.GetAll(),
|
||||
Options: opts.dnsOptions.GetAll(),
|
||||
Options: opts.dnsOption.GetAll(),
|
||||
},
|
||||
StopGracePeriod: opts.stopGrace.Value(),
|
||||
Secrets: nil,
|
||||
|
@ -597,9 +597,9 @@ const (
|
|||
flagDNS = "dns"
|
||||
flagDNSRemove = "dns-rm"
|
||||
flagDNSAdd = "dns-add"
|
||||
flagDNSOptions = "dns-options"
|
||||
flagDNSOptionsRemove = "dns-options-rm"
|
||||
flagDNSOptionsAdd = "dns-options-add"
|
||||
flagDNSOption = "dns-option"
|
||||
flagDNSOptionRemove = "dns-option-rm"
|
||||
flagDNSOptionAdd = "dns-option-add"
|
||||
flagDNSSearch = "dns-search"
|
||||
flagDNSSearchRemove = "dns-search-rm"
|
||||
flagDNSSearchAdd = "dns-search-add"
|
||||
|
|
|
@ -49,9 +49,9 @@ func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
flags.Var(newListOptsVar(), flagMountRemove, "Remove a mount by its target path")
|
||||
flags.Var(newListOptsVar(), flagPublishRemove, "Remove a published port by its target port")
|
||||
flags.Var(newListOptsVar(), flagConstraintRemove, "Remove a constraint")
|
||||
flags.Var(newListOptsVar(), flagDNSRemove, "Remove custom DNS servers")
|
||||
flags.Var(newListOptsVar(), flagDNSOptionsRemove, "Remove DNS options")
|
||||
flags.Var(newListOptsVar(), flagDNSSearchRemove, "Remove DNS search domains")
|
||||
flags.Var(newListOptsVar(), flagDNSRemove, "Remove a custom DNS server")
|
||||
flags.Var(newListOptsVar(), flagDNSOptionRemove, "Remove a DNS option")
|
||||
flags.Var(newListOptsVar(), flagDNSSearchRemove, "Remove a DNS search domain")
|
||||
flags.Var(&opts.labels, flagLabelAdd, "Add or update a service label")
|
||||
flags.Var(&opts.containerLabels, flagContainerLabelAdd, "Add or update a container label")
|
||||
flags.Var(&opts.env, flagEnvAdd, "Add or update an environment variable")
|
||||
|
@ -61,9 +61,9 @@ func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
flags.Var(&opts.constraints, flagConstraintAdd, "Add or update a placement constraint")
|
||||
flags.Var(&opts.endpoint.ports, flagPublishAdd, "Add or update a published port")
|
||||
flags.Var(&opts.groups, flagGroupAdd, "Add an additional supplementary user group to the container")
|
||||
flags.Var(&opts.dns, flagDNSAdd, "Add or update custom DNS servers")
|
||||
flags.Var(&opts.dnsOptions, flagDNSOptionsAdd, "Add or update DNS options")
|
||||
flags.Var(&opts.dnsSearch, flagDNSSearchAdd, "Add or update custom DNS search domains")
|
||||
flags.Var(&opts.dns, flagDNSAdd, "Add or update a custom DNS server")
|
||||
flags.Var(&opts.dnsOption, flagDNSOptionAdd, "Add or update a DNS option")
|
||||
flags.Var(&opts.dnsSearch, flagDNSSearchAdd, "Add or update a custom DNS search domain")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|||
}
|
||||
}
|
||||
|
||||
if anyChanged(flags, flagDNSAdd, flagDNSRemove, flagDNSOptionsAdd, flagDNSOptionsRemove, flagDNSSearchAdd, flagDNSSearchRemove) {
|
||||
if anyChanged(flags, flagDNSAdd, flagDNSRemove, flagDNSOptionAdd, flagDNSOptionRemove, flagDNSSearchAdd, flagDNSSearchRemove) {
|
||||
if cspec.DNSConfig == nil {
|
||||
cspec.DNSConfig = &swarm.DNSConfig{}
|
||||
}
|
||||
|
@ -586,12 +586,12 @@ func updateDNSConfig(flags *pflag.FlagSet, config **swarm.DNSConfig) error {
|
|||
sort.Strings(newConfig.Search)
|
||||
|
||||
options := (*config).Options
|
||||
if flags.Changed(flagDNSOptionsAdd) {
|
||||
values := flags.Lookup(flagDNSOptionsAdd).Value.(*opts.ListOpts).GetAll()
|
||||
if flags.Changed(flagDNSOptionAdd) {
|
||||
values := flags.Lookup(flagDNSOptionAdd).Value.(*opts.ListOpts).GetAll()
|
||||
options = append(options, values...)
|
||||
}
|
||||
options = removeDuplicates(options)
|
||||
toRemove = buildToRemoveSet(flags, flagDNSOptionsRemove)
|
||||
toRemove = buildToRemoveSet(flags, flagDNSOptionRemove)
|
||||
for _, option := range options {
|
||||
if _, exists := toRemove[option]; !exists {
|
||||
newConfig.Options = append(newConfig.Options, option)
|
||||
|
|
|
@ -142,8 +142,8 @@ func TestUpdateDNSConfig(t *testing.T) {
|
|||
// Invalid dns search domain
|
||||
assert.Error(t, flags.Set("dns-search-add", "example$com"), "example$com is not a valid domain")
|
||||
|
||||
flags.Set("dns-options-add", "ndots:9")
|
||||
flags.Set("dns-options-rm", "timeout:3")
|
||||
flags.Set("dns-option-add", "ndots:9")
|
||||
flags.Set("dns-option-rm", "timeout:3")
|
||||
|
||||
config := &swarm.DNSConfig{
|
||||
Nameservers: []string{"3.3.3.3", "5.5.5.5"},
|
||||
|
|
Loading…
Reference in New Issue