Skip to content

Commit

Permalink
Merge pull request #919 from Luap99/netavark-internal-dns
Browse files Browse the repository at this point in the history
netavark: add support for dns with internal
  • Loading branch information
openshift-merge-robot authored Feb 4, 2022
2 parents ea34809 + e030a76 commit cba555c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion libnetwork/cni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (n *cniNetwork) networkCreate(newNetwork *types.Network, defaultNet bool) (
return nil, errors.Wrapf(types.ErrInvalidArg, "unsupported driver %s", newNetwork.Driver)
}

err = internalutil.ValidateSubnets(newNetwork, usedNetworks)
err = internalutil.ValidateSubnets(newNetwork, !newNetwork.Internal, usedNetworks)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions libnetwork/internal/util/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func ValidateSubnet(s *types.Subnet, addGateway bool, usedNetworks []*net.IPNet)
}

// ValidateSubnets will validate the subnets for this network.
// It also sets the gateway if the gateway is empty and it sets
// It also sets the gateway if the gateway is empty and addGateway is set to true
// IPv6Enabled to true if at least one subnet is ipv6.
func ValidateSubnets(network *types.Network, usedNetworks []*net.IPNet) error {
func ValidateSubnets(network *types.Network, addGateway bool, usedNetworks []*net.IPNet) error {
for i := range network.Subnets {
err := ValidateSubnet(&network.Subnets[i], !network.Internal, usedNetworks)
err := ValidateSubnet(&network.Subnets[i], addGateway, usedNetworks)
if err != nil {
return err
}
Expand Down
9 changes: 3 additions & 6 deletions libnetwork/netavark/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,13 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo
return nil, errors.Wrapf(types.ErrInvalidArg, "unsupported driver %s", newNetwork.Driver)
}

err = internalutil.ValidateSubnets(newNetwork, usedNetworks)
// add gatway when not internal or dns enabled
addGateway := !newNetwork.Internal || newNetwork.DNSEnabled
err = internalutil.ValidateSubnets(newNetwork, addGateway, usedNetworks)
if err != nil {
return nil, err
}

// FIXME: If we have a working solution for internal networks with dns this check should be removed.
if newNetwork.DNSEnabled && newNetwork.Internal {
return nil, errors.New("cannot set internal and dns enabled")
}

newNetwork.Created = time.Now()

if !defaultNet {
Expand Down
10 changes: 6 additions & 4 deletions libnetwork/netavark/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ var _ = Describe("Config", func() {
Expect(network1.Driver).To(Equal("bridge"))
Expect(network1.Subnets).To(HaveLen(1))
Expect(network1.Subnets[0].Subnet.String()).ToNot(BeEmpty())
Expect(network1.Subnets[0].Gateway).To(BeNil())
Expect(network1.Subnets[0].Gateway.String()).ToNot(BeEmpty())
Expect(network1.Internal).To(BeTrue())
})

Expand Down Expand Up @@ -729,9 +729,11 @@ var _ = Describe("Config", func() {
Internal: true,
DNSEnabled: true,
}
_, err := libpodNet.NetworkCreate(network)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("cannot set internal and dns enabled"))
network1, err := libpodNet.NetworkCreate(network)
Expect(err).ToNot(HaveOccurred())
Expect(network1.Driver).To(Equal("bridge"))
Expect(network1.Internal).To(Equal(true))
Expect(network1.DNSEnabled).To(Equal(true))
})

It("network inspect partial ID", func() {
Expand Down
4 changes: 3 additions & 1 deletion libnetwork/netavark/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ func parseNetwork(network *types.Network) error {
return errors.Errorf("invalid network ID %q", network.ID)
}

return util.ValidateSubnets(network, nil)
// add gatway when not internal or dns enabled
addGateway := !network.Internal || network.DNSEnabled
return util.ValidateSubnets(network, addGateway, nil)
}

func (n *netavarkNetwork) createDefaultNetwork() (*types.Network, error) {
Expand Down

0 comments on commit cba555c

Please sign in to comment.