diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-11-10 19:10:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 19:10:59 +0100 |
commit | ce2ac7d2d2413074f9855acbaa7be0b4d5d726e4 (patch) | |
tree | 687c943d5ed8e7548f6c7f3888b701f99a33cde1 /cmd | |
parent | da01191aa3526e3a77d9a055e23c318c26720785 (diff) | |
parent | b7b5b6f8e3072530f4c3fc07e5960e54c90729b5 (diff) | |
download | podman-ce2ac7d2d2413074f9855acbaa7be0b4d5d726e4.tar.gz podman-ce2ac7d2d2413074f9855acbaa7be0b4d5d726e4.tar.bz2 podman-ce2ac7d2d2413074f9855acbaa7be0b4d5d726e4.zip |
Merge pull request #8251 from baude/networkaliases
network aliases for container creation
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/common/create_opts.go | 7 | ||||
-rw-r--r-- | cmd/podman/common/netflags.go | 14 | ||||
-rw-r--r-- | cmd/podman/common/specgen.go | 11 |
3 files changed, 31 insertions, 1 deletions
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go index 8b2efc988..4b52663c3 100644 --- a/cmd/podman/common/create_opts.go +++ b/cmd/podman/common/create_opts.go @@ -133,6 +133,7 @@ func stringMaptoArray(m map[string]string) []string { // a specgen spec. func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroupsManager string) (*ContainerCLIOpts, []string, error) { var ( + aliases []string capAdd []string cappDrop []string entrypoint string @@ -242,8 +243,11 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup // network names endpointsConfig := cc.NetworkingConfig.EndpointsConfig cniNetworks := make([]string, 0, len(endpointsConfig)) - for netName := range endpointsConfig { + for netName, endpoint := range endpointsConfig { cniNetworks = append(cniNetworks, netName) + if len(endpoint.Aliases) > 0 { + aliases = append(aliases, endpoint.Aliases...) + } } // netMode @@ -262,6 +266,7 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup // defined when there is only one network. netInfo := entities.NetOptions{ AddHosts: cc.HostConfig.ExtraHosts, + Aliases: aliases, CNINetworks: cniNetworks, DNSOptions: cc.HostConfig.DNSOptions, DNSSearch: cc.HostConfig.DNSSearch, diff --git a/cmd/podman/common/netflags.go b/cmd/podman/common/netflags.go index 1b8297c36..935a5f7b9 100644 --- a/cmd/podman/common/netflags.go +++ b/cmd/podman/common/netflags.go @@ -43,6 +43,10 @@ func GetNetFlags() *pflag.FlagSet { "network", containerConfig.NetNS(), "Connect a container to a network", ) + netFlags.StringSlice( + "network-alias", []string{}, + "Add network-scoped alias for the container", + ) netFlags.StringSliceP( "publish", "p", []string{}, "Publish a container's port, or a range of ports, to the host (default [])", @@ -158,6 +162,9 @@ func NetFlagsToNetOptions(cmd *cobra.Command) (*entities.NetOptions, error) { } opts.NoHosts, err = cmd.Flags().GetBool("no-hosts") + if err != nil { + return nil, err + } if cmd.Flags().Changed("network") { network, err := cmd.Flags().GetString("network") @@ -181,5 +188,12 @@ func NetFlagsToNetOptions(cmd *cobra.Command) (*entities.NetOptions, error) { opts.CNINetworks = cniNets } + aliases, err := cmd.Flags().GetStringSlice("network-alias") + if err != nil { + return nil, err + } + if len(aliases) > 0 { + opts.Aliases = aliases + } return &opts, err } diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go index ca1e25be1..39ff02857 100644 --- a/cmd/podman/common/specgen.go +++ b/cmd/podman/common/specgen.go @@ -396,6 +396,17 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string s.ShmSize = &shmSize } s.CNINetworks = c.Net.CNINetworks + + // Network aliases + if len(c.Net.Aliases) > 0 { + // build a map of aliases where key=cniName + aliases := make(map[string][]string, len(s.CNINetworks)) + for _, cniNetwork := range s.CNINetworks { + aliases[cniNetwork] = c.Net.Aliases + } + s.Aliases = aliases + } + s.HostAdd = c.Net.AddHosts s.UseImageResolvConf = c.Net.UseImageResolvConf s.DNSServers = c.Net.DNSServers |