diff options
Diffstat (limited to 'libpod/network')
-rw-r--r-- | libpod/network/cni/config.go | 6 | ||||
-rw-r--r-- | libpod/network/cni/config_test.go | 21 | ||||
-rw-r--r-- | libpod/network/cni/run.go | 3 | ||||
-rw-r--r-- | libpod/network/cni/run_test.go | 41 | ||||
-rw-r--r-- | libpod/network/types/network.go | 4 |
5 files changed, 49 insertions, 26 deletions
diff --git a/libpod/network/cni/config.go b/libpod/network/cni/config.go index 670ee0c65..3df155637 100644 --- a/libpod/network/cni/config.go +++ b/libpod/network/cni/config.go @@ -170,7 +170,11 @@ func (n *cniNetwork) NetworkRemove(nameOrID string) error { file := network.filename delete(n.networks, network.libpodNet.Name) - return os.Remove(file) + // make sure to not error for ErrNotExist + if err := os.Remove(file); err != nil && !errors.Is(err, os.ErrNotExist) { + return err + } + return nil } // NetworkList will return all known Networks. Optionally you can diff --git a/libpod/network/cni/config_test.go b/libpod/network/cni/config_test.go index a0a0ea1af..288cf4626 100644 --- a/libpod/network/cni/config_test.go +++ b/libpod/network/cni/config_test.go @@ -1021,6 +1021,27 @@ var _ = Describe("Config", func() { Expect(err.Error()).To(ContainSubstring("subnet 10.10.0.0/24 is already used on the host or by another config")) }) + It("remove network should not error when config file does not exists on disk", func() { + name := "mynet" + network := types.Network{Name: name} + _, err := libpodNet.NetworkCreate(network) + Expect(err).To(BeNil()) + + path := filepath.Join(cniConfDir, name+".conflist") + Expect(path).To(BeARegularFile()) + + err = os.Remove(path) + Expect(err).To(BeNil()) + Expect(path).ToNot(BeARegularFile()) + + err = libpodNet.NetworkRemove(name) + Expect(err).To(BeNil()) + + nets, err := libpodNet.NetworkList() + Expect(err).To(BeNil()) + Expect(nets).To(HaveLen(1)) + Expect(nets).ToNot(ContainElement(HaveNetworkName(name))) + }) }) Context("network load valid existing ones", func() { diff --git a/libpod/network/cni/run.go b/libpod/network/cni/run.go index 0f91a407c..bd873f89b 100644 --- a/libpod/network/cni/run.go +++ b/libpod/network/cni/run.go @@ -186,9 +186,6 @@ outer: } return errors.Errorf("requested static ip %s not in any subnet on network %s", ip.String(), network.libpodNet.Name) } - if len(netOpts.Aliases) > 0 && !network.libpodNet.DNSEnabled { - return errors.New("cannot set aliases on a network without dns enabled") - } return nil } diff --git a/libpod/network/cni/run_test.go b/libpod/network/cni/run_test.go index 0a2c090e1..965203c2a 100644 --- a/libpod/network/cni/run_test.go +++ b/libpod/network/cni/run_test.go @@ -966,6 +966,26 @@ var _ = Describe("run CNI", func() { }) }) + It("setup with aliases but dns disabled should work", func() { + runTest(func() { + defNet := types.DefaultNetworkName + intName := "eth0" + setupOpts := types.SetupOptions{ + NetworkOptions: types.NetworkOptions{ + ContainerID: stringid.GenerateNonCryptoID(), + Networks: map[string]types.PerNetworkOptions{ + defNet: { + InterfaceName: intName, + Aliases: []string{"somealias"}, + }, + }, + }, + } + _, err := libpodNet.Setup(netNSContainer.Path(), setupOpts) + Expect(err).ToNot(HaveOccurred()) + }) + }) + }) Context("invalid network setup test", func() { @@ -1052,27 +1072,6 @@ var _ = Describe("run CNI", func() { }) }) - It("setup with aliases but dns disabled", func() { - runTest(func() { - defNet := types.DefaultNetworkName - intName := "eth0" - setupOpts := types.SetupOptions{ - NetworkOptions: types.NetworkOptions{ - ContainerID: stringid.GenerateNonCryptoID(), - Networks: map[string]types.PerNetworkOptions{ - defNet: { - InterfaceName: intName, - Aliases: []string{"somealias"}, - }, - }, - }, - } - _, err := libpodNet.Setup(netNSContainer.Path(), setupOpts) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("cannot set aliases on a network without dns enabled")) - }) - }) - It("setup without networks", func() { runTest(func() { setupOpts := types.SetupOptions{ diff --git a/libpod/network/types/network.go b/libpod/network/types/network.go index 68a32d499..2fe4f3da2 100644 --- a/libpod/network/types/network.go +++ b/libpod/network/types/network.go @@ -151,7 +151,9 @@ type PerNetworkOptions struct { // StaticIPv4 for this container. Optional. StaticIPs []net.IP `json:"static_ips,omitempty"` // Aliases contains a list of names which the dns server should resolve - // to this container. Can only be set when DNSEnabled is true on the Network. + // to this container. Should only be set when DNSEnabled is true on the Network. + // If aliases are set but there is no dns support for this network the + // network interface implementation should ignore this and NOT error. // Optional. Aliases []string `json:"aliases,omitempty"` // StaticMac for this container. Optional. |