Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libnetwork: ipam driver none disable dns #989

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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