Skip to content

Commit

Permalink
fix: set dhcp gateway to U2OInterconnectionIP when enabling dhcp and …
Browse files Browse the repository at this point in the history
…u2o (#4228)

* fix: set dhcp gateway to U2OInterconnectionIP when enabling dhcp and u2o

Signed-off-by: zcq98 <[email protected]>

* add e2e for dhcp gateway check when enabling u2o

Signed-off-by: zcq98 <[email protected]>

* Update test/e2e/kube-ovn/underlay/underlay.go

Co-authored-by: 张祖建 <[email protected]>
Signed-off-by: zcq98 <[email protected]>

---------

Signed-off-by: zcq98 <[email protected]>
Co-authored-by: 张祖建 <[email protected]>
  • Loading branch information
zcq98 and zhangzujian authored Jul 10, 2024
1 parent 45a16a7 commit e5029d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/ovs/ovn-nb-dhcp_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func (c *OVNNbClient) UpdateDHCPOptions(subnet *kubeovnv1.Subnet, mtu int) (*DHC
lsName := subnet.Name
cidrBlock := subnet.Spec.CIDRBlock
gateway := subnet.Spec.Gateway
if subnet.Status.U2OInterconnectionIP != "" && subnet.Spec.U2OInterconnection {
gateway = subnet.Status.U2OInterconnectionIP
}
enableDHCP := subnet.Spec.EnableDHCP

/* delete dhcp options */
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/kube-ovn/underlay/underlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,10 @@ var _ = framework.SerialDescribe("[group:underlay]", func() {
ginkgo.By("Creating underlay subnet " + subnetName)
subnet := framework.MakeSubnet(subnetName, vlanName, strings.Join(underlayCidr, ","), strings.Join(gateway, ","), "", "", excludeIPs, nil, []string{namespaceName})
subnet.Spec.U2OInterconnection = true
// only ipv4 needs to verify that the gateway address is consistent with U2OInterconnectionIP when enabling DHCP and U2O
if f.HasIPv4() {
subnet.Spec.EnableDHCP = true
}
_ = subnetClient.CreateSync(subnet)

ginkgo.By("Creating underlay pod " + u2oPodNameUnderlay)
Expand Down Expand Up @@ -930,6 +934,17 @@ func checkU2OItems(f *framework.Framework, subnet *apiv1.Subnet, underlayPod, ov
framework.ExpectEqual(subnet.Spec.U2OInterconnectionIP, subnet.Status.U2OInterconnectionIP)
}
}
if f.HasIPv4() && subnet.Spec.EnableDHCP {
if !f.VersionPriorTo(1, 12) {
ginkgo.By("checking u2o dhcp gateway ip of underlay subnet " + subnet.Name)
v4Cidr, _ := util.SplitStringIP(subnet.Spec.CIDRBlock)
v4Gateway, _ := util.SplitStringIP(subnet.Status.U2OInterconnectionIP)
nbctlCmd := fmt.Sprintf("ovn-nbctl --bare --columns=options find Dhcp_Options cidr=%s", v4Cidr)
output, _, err := framework.NBExec(nbctlCmd)
framework.ExpectNoError(err)
framework.ExpectContainElement(strings.Fields(string(output)), "router="+v4Gateway)
}
}
} else {
framework.ExpectFalse(subnet.Spec.U2OInterconnection)
framework.ExpectEmpty(subnet.Status.U2OInterconnectionIP)
Expand Down

0 comments on commit e5029d5

Please sign in to comment.