Merge pull request #5073 from baude/sepnetoptions

seperate container create network options
This commit is contained in:
OpenShift Merge Robot
2020-02-04 01:51:09 -08:00
committed by GitHub
4 changed files with 55 additions and 37 deletions

View File

@ -16,6 +16,7 @@ import (
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag"
) )
var ( var (
@ -116,14 +117,49 @@ func getDefaultNetwork() string {
return "bridge" return "bridge"
} }
func getCreateFlags(c *cliconfig.PodmanCommand) { func getNetFlags() *pflag.FlagSet {
netFlags := pflag.FlagSet{}
createFlags := c.Flags() netFlags.StringSlice(
createFlags.StringSlice(
"add-host", []string{}, "add-host", []string{},
"Add a custom host-to-IP mapping (host:ip) (default [])", "Add a custom host-to-IP mapping (host:ip) (default [])",
) )
netFlags.StringSlice(
"dns", []string{},
"Set custom DNS servers",
)
netFlags.StringSlice(
"dns-opt", []string{},
"Set custom DNS options",
)
netFlags.StringSlice(
"dns-search", []string{},
"Set custom DNS search domains",
)
netFlags.String(
"ip", "",
"Specify a static IPv4 address for the container",
)
netFlags.String(
"mac-address", "",
"Container MAC address (e.g. 92:d0:c6:0a:29:33)",
)
netFlags.String(
"network", getDefaultNetwork(),
"Connect a container to a network",
)
netFlags.StringSliceP(
"publish", "p", []string{},
"Publish a container's port, or a range of ports, to the host (default [])",
)
netFlags.Bool(
"no-hosts", false,
"Do not create /etc/hosts within the container, instead use the version from the image",
)
return &netFlags
}
func getCreateFlags(c *cliconfig.PodmanCommand) {
createFlags := c.Flags()
createFlags.StringSlice( createFlags.StringSlice(
"annotation", []string{}, "annotation", []string{},
"Add annotations to container (key:value) (default [])", "Add annotations to container (key:value) (default [])",
@ -236,18 +272,6 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"device-write-iops", []string{}, "device-write-iops", []string{},
"Limit write rate (IO per second) to a device (e.g. --device-write-iops=/dev/sda:1000)", "Limit write rate (IO per second) to a device (e.g. --device-write-iops=/dev/sda:1000)",
) )
createFlags.StringSlice(
"dns", []string{},
"Set custom DNS servers",
)
createFlags.StringSlice(
"dns-opt", []string{},
"Set custom DNS options",
)
createFlags.StringSlice(
"dns-search", []string{},
"Set custom DNS search domains",
)
createFlags.String( createFlags.String(
"entrypoint", "", "entrypoint", "",
"Overwrite the default ENTRYPOINT of the image", "Overwrite the default ENTRYPOINT of the image",
@ -323,10 +347,6 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"interactive", "i", false, "interactive", "i", false,
"Keep STDIN open even if not attached", "Keep STDIN open even if not attached",
) )
createFlags.String(
"ip", "",
"Specify a static IPv4 address for the container",
)
createFlags.String( createFlags.String(
"ipc", "", "ipc", "",
"IPC namespace to use", "IPC namespace to use",
@ -351,10 +371,6 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"log-opt", []string{}, "log-opt", []string{},
"Logging driver options (default [])", "Logging driver options (default [])",
) )
createFlags.String(
"mac-address", "",
"Container MAC address (e.g. 92:d0:c6:0a:29:33)",
)
createFlags.StringP( createFlags.StringP(
"memory", "m", "", "memory", "m", "",
"Memory limit "+sizeWithUnitFormat, "Memory limit "+sizeWithUnitFormat,
@ -375,14 +391,6 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"name", "", "name", "",
"Assign a name to the container", "Assign a name to the container",
) )
createFlags.String(
"network", getDefaultNetwork(),
"Connect a container to a network",
)
createFlags.Bool(
"no-hosts", false,
"Do not create /etc/hosts within the container, instead use the version from the image",
)
createFlags.Bool( createFlags.Bool(
"oom-kill-disable", false, "oom-kill-disable", false,
"Disable OOM Killer", "Disable OOM Killer",
@ -417,10 +425,6 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"privileged", false, "privileged", false,
"Give extended privileges to container", "Give extended privileges to container",
) )
createFlags.StringSliceP(
"publish", "p", []string{},
"Publish a container's port, or a range of ports, to the host (default [])",
)
createFlags.BoolP( createFlags.BoolP(
"publish-all", "P", false, "publish-all", "P", false,
"Publish all exposed ports to random ports on the host interface", "Publish all exposed ports to random ports on the host interface",

View File

@ -41,6 +41,7 @@ func init() {
getCreateFlags(&createCommand.PodmanCommand) getCreateFlags(&createCommand.PodmanCommand)
flags := createCommand.Flags() flags := createCommand.Flags()
flags.AddFlagSet(getNetFlags())
flags.SetInterspersed(false) flags.SetInterspersed(false)
flags.SetNormalizeFunc(aliasFlags) flags.SetNormalizeFunc(aliasFlags)
} }

View File

@ -44,6 +44,18 @@ func init() {
podCreateCommand.SetUsageTemplate(UsageTemplate()) podCreateCommand.SetUsageTemplate(UsageTemplate())
flags := podCreateCommand.Flags() flags := podCreateCommand.Flags()
flags.SetInterspersed(false) flags.SetInterspersed(false)
// When we are ready to add the network options to the create commmand, we need to uncomment
// the following
//flags.AddFlagSet(getNetFlags())
// Once this is uncommented, then the publish option below needs to be removed because it
// conflicts with the publish in getNetFlags. Upon removal, the c.Publish will not work
// anymore and needs to be cleaned up. I suggest starting with removing the Publish attribute
// from PodCreateValues structure. Running make should then expose all areas that need to be
// addressed. To get the value of publish (and other flags in getNetFlags, use the syntax:
// c.<type>("<flag_name") or c.Bool("publish")
// Remember to do this safely by checking len, etc.
flags.StringVar(&podCreateCommand.CgroupParent, "cgroup-parent", "", "Set parent cgroup for the pod") flags.StringVar(&podCreateCommand.CgroupParent, "cgroup-parent", "", "Set parent cgroup for the pod")
flags.BoolVar(&podCreateCommand.Infra, "infra", true, "Create an infra container associated with the pod to share namespaces with") flags.BoolVar(&podCreateCommand.Infra, "infra", true, "Create an infra container associated with the pod to share namespaces with")

View File

@ -38,6 +38,7 @@ func init() {
flags.SetInterspersed(false) flags.SetInterspersed(false)
flags.SetNormalizeFunc(aliasFlags) flags.SetNormalizeFunc(aliasFlags)
flags.Bool("sig-proxy", true, "Proxy received signals to the process") flags.Bool("sig-proxy", true, "Proxy received signals to the process")
flags.AddFlagSet(getNetFlags())
getCreateFlags(&runCommand.PodmanCommand) getCreateFlags(&runCommand.PodmanCommand)
markFlagHiddenForRemoteClient("authfile", flags) markFlagHiddenForRemoteClient("authfile", flags)
} }