summaryrefslogtreecommitdiff
path: root/pkg/specgen/generate/namespaces.go
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2021-12-09 15:59:54 +0100
committerPaul Holzinger <pholzing@redhat.com>2021-12-14 15:23:39 +0100
commitd072167fe2f75db9648bf1be4181b42e9b7db9a4 (patch)
tree26af147a70f41a9a0d80f1208f073313039dbd19 /pkg/specgen/generate/namespaces.go
parent46938bbf889de590b00c9be8ea5b4fb86f363519 (diff)
downloadpodman-d072167fe2f75db9648bf1be4181b42e9b7db9a4.tar.gz
podman-d072167fe2f75db9648bf1be4181b42e9b7db9a4.tar.bz2
podman-d072167fe2f75db9648bf1be4181b42e9b7db9a4.zip
Add new networks format to spegecen
Add the new networks format to specgen. For api users cni_networks is still supported to make migration easier however the static ip and mac fields are removed. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'pkg/specgen/generate/namespaces.go')
-rw-r--r--pkg/specgen/generate/namespaces.go38
1 files changed, 17 insertions, 21 deletions
diff --git a/pkg/specgen/generate/namespaces.go b/pkg/specgen/generate/namespaces.go
index ebdd2abd0..782156663 100644
--- a/pkg/specgen/generate/namespaces.go
+++ b/pkg/specgen/generate/namespaces.go
@@ -259,32 +259,28 @@ func namespaceOptions(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.
if err != nil {
return nil, err
}
- if len(s.CNINetworks) == 0 {
- rtConfig, err := rt.GetConfigNoCopy()
- if err != nil {
- return nil, err
- }
- s.CNINetworks = append(s.CNINetworks, rtConfig.Network.DefaultNetwork)
- }
- networks := make(map[string]types.PerNetworkOptions, len(s.CNINetworks))
- for i, netName := range s.CNINetworks {
- opts := types.PerNetworkOptions{}
- opts.Aliases = s.Aliases[netName]
- if i == 0 {
- if s.StaticIP != nil {
- opts.StaticIPs = append(opts.StaticIPs, *s.StaticIP)
+ // if no network was specified use add the default
+ if len(s.Networks) == 0 {
+ // backwards config still allow the old cni networks list and convert to new format
+ if len(s.CNINetworks) > 0 {
+ logrus.Warn(`specgen "cni_networks" option is deprecated use the "networks" map instead`)
+ networks := make(map[string]types.PerNetworkOptions, len(s.CNINetworks))
+ for _, net := range s.CNINetworks {
+ networks[net] = types.PerNetworkOptions{}
}
- if s.StaticIPv6 != nil {
- opts.StaticIPs = append(opts.StaticIPs, *s.StaticIPv6)
+ s.Networks = networks
+ } else {
+ // no networks given but bridge is set so use default network
+ rtConfig, err := rt.GetConfigNoCopy()
+ if err != nil {
+ return nil, err
}
- if s.StaticMAC != nil {
- opts.StaticMAC = *s.StaticMAC
+ s.Networks = map[string]types.PerNetworkOptions{
+ rtConfig.Network.DefaultNetwork: {},
}
}
- networks[netName] = opts
}
-
- toReturn = append(toReturn, libpod.WithNetNS(portMappings, expose, postConfigureNetNS, "bridge", networks))
+ toReturn = append(toReturn, libpod.WithNetNS(portMappings, expose, postConfigureNetNS, "bridge", s.Networks))
}
if s.UseImageHosts {