Skip to content

Commit

Permalink
libnetwork: ipam driver none disable dns
Browse files Browse the repository at this point in the history
When we create a network with the ipam driver none we should disabled
dns automatically. Since we mange no ips we cannot provide name
resolution anyway.

This fixes a problem I spotted when adding test to the podman CI.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Mar 31, 2022
1 parent 310f063 commit 5f14ec7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libnetwork/cni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func (n *cniNetwork) networkCreate(newNetwork *types.Network, defaultNet bool) (
// generate the network ID
newNetwork.ID = getNetworkIDFromName(newNetwork.Name)

// when we do not have ipam we must disable dns
internalutil.IpamNoneDisableDns(newNetwork)

// FIXME: Should this be a hard error?
if newNetwork.DNSEnabled && newNetwork.Internal && hasDNSNamePlugin(n.cniPluginDirs) {
logrus.Warnf("dnsname and internal networks are incompatible. dnsname plugin not configured for network %s", newNetwork.Name)
Expand Down
2 changes: 2 additions & 0 deletions libnetwork/cni/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,12 @@ var _ = Describe("Config", func() {
IPAMOptions: map[string]string{
"driver": "none",
},
DNSEnabled: true,
}
network1, err := libpodNet.NetworkCreate(network)
Expect(err).To(BeNil())
Expect(network1.Driver).To(Equal("bridge"))
Expect(network1.DNSEnabled).To(BeFalse())
Expect(network1.IPAMOptions).ToNot(BeEmpty())
Expect(network1.IPAMOptions).To(HaveKeyWithValue("driver", "none"))
Expect(network1.Subnets).To(HaveLen(0))
Expand Down
1 change: 1 addition & 0 deletions libnetwork/cni/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ var _ = Describe("run CNI", func() {
IPAMOptions: map[string]string{
types.Driver: types.NoneIPAMDriver,
},
DNSEnabled: true,
}
network1, err := libpodNet.NetworkCreate(network)
Expect(err).To(BeNil())
Expand Down
8 changes: 8 additions & 0 deletions libnetwork/internal/util/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package util
import (
"github.com/containers/common/libnetwork/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

func CommonNetworkCreate(n NetUtil, network *types.Network) error {
Expand Down Expand Up @@ -39,3 +40,10 @@ func CommonNetworkCreate(n NetUtil, network *types.Network) error {
}
return nil
}

func IpamNoneDisableDns(network *types.Network) {
if network.IPAMOptions[types.Driver] == types.NoneIPAMDriver {
logrus.Debugf("dns disabled for network %q because ipam driver is set to none", network.Name)
network.DNSEnabled = false
}
}
3 changes: 3 additions & 0 deletions libnetwork/netavark/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo
return nil, errors.Wrapf(types.ErrInvalidArg, "unsupported driver %s", newNetwork.Driver)
}

// when we do not have ipam we must disable dns
internalutil.IpamNoneDisableDns(newNetwork)

// add gateway when not internal or dns enabled
addGateway := !newNetwork.Internal || newNetwork.DNSEnabled
err = internalutil.ValidateSubnets(newNetwork, addGateway, usedNetworks)
Expand Down
2 changes: 2 additions & 0 deletions libnetwork/netavark/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,12 @@ var _ = Describe("Config", func() {
IPAMOptions: map[string]string{
"driver": "none",
},
DNSEnabled: true,
}
network1, err := libpodNet.NetworkCreate(network)
Expect(err).To(BeNil())
Expect(network1.Driver).To(Equal("macvlan"))
Expect(network1.DNSEnabled).To(BeFalse())
Expect(network1.IPAMOptions).ToNot(BeEmpty())
Expect(network1.IPAMOptions).To(HaveKeyWithValue("driver", "none"))
Expect(network1.Subnets).To(HaveLen(0))
Expand Down
1 change: 1 addition & 0 deletions libnetwork/netavark/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ var _ = Describe("run netavark", func() {
IPAMOptions: map[string]string{
types.Driver: types.NoneIPAMDriver,
},
DNSEnabled: true,
}
network1, err := libpodNet.NetworkCreate(network)
Expect(err).To(BeNil())
Expand Down

0 comments on commit 5f14ec7

Please sign in to comment.