Merge pull request #15823 from rhatdan/dns-opt

Default to --dns-option to match Docker and Buildah
This commit is contained in:
OpenShift Merge Robot
2022-09-16 17:24:34 +02:00
committed by GitHub
11 changed files with 19 additions and 38 deletions

View File

@ -33,18 +33,12 @@ func DefineNetFlags(cmd *cobra.Command) {
) )
_ = cmd.RegisterFlagCompletionFunc(dnsFlagName, completion.AutocompleteNone) _ = cmd.RegisterFlagCompletionFunc(dnsFlagName, completion.AutocompleteNone)
dnsOptFlagName := "dns-opt" dnsOptFlagName := "dns-option"
netFlags.StringSlice( netFlags.StringSlice(
dnsOptFlagName, containerConfig.DNSOptions(), dnsOptFlagName, containerConfig.DNSOptions(),
"Set custom DNS options", "Set custom DNS options",
) )
_ = cmd.RegisterFlagCompletionFunc(dnsOptFlagName, completion.AutocompleteNone) _ = cmd.RegisterFlagCompletionFunc(dnsOptFlagName, completion.AutocompleteNone)
netFlags.StringSlice(
"dns-option", containerConfig.DNSOptions(),
"Docker compatibility option== --dns-opt",
)
_ = netFlags.MarkHidden("dns-option")
dnsSearchFlagName := "dns-search" dnsSearchFlagName := "dns-search"
netFlags.StringSlice( netFlags.StringSlice(
dnsSearchFlagName, containerConfig.DNSSearches(), dnsSearchFlagName, containerConfig.DNSSearches(),
@ -143,20 +137,12 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
} }
} }
if flags.Changed("dns-opt") {
options, err := flags.GetStringSlice("dns-opt")
if err != nil {
return nil, err
}
opts.DNSOptions = options
}
if flags.Changed("dns-option") { if flags.Changed("dns-option") {
options, err := flags.GetStringSlice("dns-option") options, err := flags.GetStringSlice("dns-option")
if err != nil { if err != nil {
return nil, err return nil, err
} }
opts.DNSOptions = append(opts.DNSOptions, options...) opts.DNSOptions = options
} }
if flags.Changed("dns-search") { if flags.Changed("dns-search") {

View File

@ -280,7 +280,7 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra
if c.Flag("shm-size").Changed { if c.Flag("shm-size").Changed {
vals.ShmSize = c.Flag("shm-size").Value.String() vals.ShmSize = c.Flag("shm-size").Value.String()
} }
if (c.Flag("dns").Changed || c.Flag("dns-opt").Changed || c.Flag("dns-search").Changed) && vals.Net != nil && (vals.Net.Network.NSMode == specgen.NoNetwork || vals.Net.Network.IsContainer()) { if (c.Flag("dns").Changed || c.Flag("dns-option").Changed || c.Flag("dns-search").Changed) && vals.Net != nil && (vals.Net.Network.NSMode == specgen.NoNetwork || vals.Net.Network.IsContainer()) {
return vals, fmt.Errorf("conflicting options: dns and the network mode: " + string(vals.Net.Network.NSMode)) return vals, fmt.Errorf("conflicting options: dns and the network mode: " + string(vals.Net.Network.NSMode))
} }
noHosts, err := c.Flags().GetBool("no-hosts") noHosts, err := c.Flags().GetBool("no-hosts")

View File

@ -17,6 +17,7 @@ import (
"github.com/containers/podman/v4/cmd/podman/containers" "github.com/containers/podman/v4/cmd/podman/containers"
"github.com/containers/podman/v4/cmd/podman/parse" "github.com/containers/podman/v4/cmd/podman/parse"
"github.com/containers/podman/v4/cmd/podman/registry" "github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/cmd/podman/utils"
"github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/errorhandling" "github.com/containers/podman/v4/pkg/errorhandling"
@ -26,7 +27,6 @@ import (
"github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag"
) )
var ( var (
@ -99,14 +99,7 @@ func init() {
shareParentFlagName := "share-parent" shareParentFlagName := "share-parent"
flags.BoolVar(&shareParent, shareParentFlagName, true, "Set the pod's cgroup as the cgroup parent for all containers joining the pod") flags.BoolVar(&shareParent, shareParentFlagName, true, "Set the pod's cgroup as the cgroup parent for all containers joining the pod")
flags.SetNormalizeFunc(aliasNetworkFlag) flags.SetNormalizeFunc(utils.AliasFlags)
}
func aliasNetworkFlag(_ *pflag.FlagSet, name string) pflag.NormalizedName {
if name == "net" {
name = "network"
}
return pflag.NormalizedName(name)
} }
func create(cmd *cobra.Command, args []string) error { func create(cmd *cobra.Command, args []string) error {

View File

@ -5,6 +5,8 @@ import "github.com/spf13/pflag"
// AliasFlags is a function to handle backwards compatibility with old flags // AliasFlags is a function to handle backwards compatibility with old flags
func AliasFlags(f *pflag.FlagSet, name string) pflag.NormalizedName { func AliasFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
switch name { switch name {
case "dns-opt":
name = "dns-option"
case "healthcheck-command": case "healthcheck-command":
name = "health-cmd" name = "health-cmd"
case "healthcheck-interval": case "healthcheck-interval":

View File

@ -1,3 +0,0 @@
#### **--dns-opt**=*option*
Set custom DNS options. Invalid if using **--dns-opt** with **--network** that is set to **none** or **container:**_id_.

View File

@ -0,0 +1,3 @@
#### **--dns-option**=*option*
Set custom DNS options. Invalid if using **--dns-option** with **--network** that is set to **none** or **container:**_id_.

View File

@ -145,7 +145,7 @@ flag to pass the user's supplementary group access into the container.
This option cannot be combined with **--network** that is set to **none** or **container:**_id_. This option cannot be combined with **--network** that is set to **none** or **container:**_id_.
@@option dns-opt.container @@option dns-option.container
@@option dns-search.container @@option dns-search.container
@ -265,7 +265,7 @@ This option is currently supported only by the **journald** log driver.
#### **--network**=*mode*, **--net** #### **--network**=*mode*, **--net**
Set the network mode for the container. Invalid if using **--dns**, **--dns-opt**, or **--dns-search** with **--network** set to **none** or **container:**_id_. If used together with **--pod**, the container will not join the pod's network namespace. Set the network mode for the container. Invalid if using **--dns**, **--dns-option**, or **--dns-search** with **--network** set to **none** or **container:**_id_. If used together with **--pod**, the container will not join the pod's network namespace.
Valid _mode_ values are: Valid _mode_ values are:

View File

@ -60,7 +60,7 @@ Note: the pod implements devices by storing the initial configuration passed by
Set custom DNS servers in the /etc/resolv.conf file that will be shared between all containers in the pod. A special option, "none" is allowed which disables creation of /etc/resolv.conf for the pod. Set custom DNS servers in the /etc/resolv.conf file that will be shared between all containers in the pod. A special option, "none" is allowed which disables creation of /etc/resolv.conf for the pod.
#### **--dns-opt**=*option* #### **--dns-option**=*option*
Set custom DNS options in the /etc/resolv.conf file that will be shared between all containers in the pod. Set custom DNS options in the /etc/resolv.conf file that will be shared between all containers in the pod.
@ -119,7 +119,7 @@ Assign a name to the pod.
#### **--network**=*mode*, **--net** #### **--network**=*mode*, **--net**
Set the network mode for the pod. Invalid if using **--dns**, **--dns-opt**, or **--dns-search** with **--network** that is set to **none** or **container:**_id_. Set the network mode for the pod. Invalid if using **--dns**, **--dns-option**, or **--dns-search** with **--network** that is set to **none** or **container:**_id_.
Valid _mode_ values are: Valid _mode_ values are:

View File

@ -181,7 +181,7 @@ flag to pass the user's supplementary group access into the container.
This option cannot be combined with **--network** that is set to **none** or **container:**_id_. This option cannot be combined with **--network** that is set to **none** or **container:**_id_.
@@option dns-opt.container @@option dns-option.container
@@option dns-search.container @@option dns-search.container
@ -286,7 +286,7 @@ This option is currently supported only by the **journald** log driver.
#### **--network**=*mode*, **--net** #### **--network**=*mode*, **--net**
Set the network mode for the container. Invalid if using **--dns**, **--dns-opt**, or **--dns-search** with **--network** set to **none** or **container:**_id_. If used together with **--pod**, the container will not join the pod's network namespace. Set the network mode for the container. Invalid if using **--dns**, **--dns-option**, or **--dns-search** with **--network** set to **none** or **container:**_id_. If used together with **--pod**, the container will not join the pod's network namespace.
Valid _mode_ values are: Valid _mode_ values are:

View File

@ -912,7 +912,7 @@ var _ = Describe("Podman generate kube", func() {
}) })
It("podman generate kube on a container with dns options", func() { It("podman generate kube on a container with dns options", func() {
top := podmanTest.Podman([]string{"run", "-dt", "--name", "top", "--dns", "8.8.8.8", "--dns-search", "foobar.com", "--dns-opt", "color:blue", ALPINE, "top"}) top := podmanTest.Podman([]string{"run", "-dt", "--name", "top", "--dns", "8.8.8.8", "--dns-search", "foobar.com", "--dns-option", "color:blue", ALPINE, "top"})
top.WaitWithDefaultTimeout() top.WaitWithDefaultTimeout()
Expect(top).Should(Exit(0)) Expect(top).Should(Exit(0))

View File

@ -221,7 +221,7 @@ EOF
--add-host "$add_host_n:$add_host_ip" \ --add-host "$add_host_n:$add_host_ip" \
--dns "$dns_server" \ --dns "$dns_server" \
--dns-search "$dns_search" \ --dns-search "$dns_search" \
--dns-opt "$dns_opt" \ --dns-option "$dns_opt" \
--publish "$port_out:$port_in" \ --publish "$port_out:$port_in" \
--label "${labelname}=${labelvalue}" \ --label "${labelname}=${labelvalue}" \
--infra-image "$infra_image" \ --infra-image "$infra_image" \
@ -262,7 +262,7 @@ EOF
run_podman run --rm --pod mypod $IMAGE cat /etc/resolv.conf run_podman run --rm --pod mypod $IMAGE cat /etc/resolv.conf
is "$output" ".*nameserver $dns_server" "--dns [server] was added" is "$output" ".*nameserver $dns_server" "--dns [server] was added"
is "$output" ".*search $dns_search" "--dns-search was added" is "$output" ".*search $dns_search" "--dns-search was added"
is "$output" ".*options $dns_opt" "--dns-opt was added" is "$output" ".*options $dns_opt" "--dns-option was added"
# pod inspect # pod inspect
run_podman pod inspect --format '{{.Name}}: {{.ID}} : {{.NumContainers}} : {{.Labels}}' mypod run_podman pod inspect --format '{{.Name}}: {{.ID}} : {{.NumContainers}} : {{.Labels}}' mypod