From d6adccad3ac8127fc53ef2fd6271315d35ed5d84 Mon Sep 17 00:00:00 2001 From: wujixin <599230270@qq.com> Date: Thu, 16 Nov 2023 10:04:44 +0800 Subject: [PATCH] fix: lsp dhcp options set failed when subnet dhcp option is enabled (#3422) Signed-off-by: wujixin Co-authored-by: wujixin --- pkg/ovs/ovn-nb-dhcp_options.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/ovs/ovn-nb-dhcp_options.go b/pkg/ovs/ovn-nb-dhcp_options.go index d5fb27a5ea5..f0d847edd57 100644 --- a/pkg/ovs/ovn-nb-dhcp_options.go +++ b/pkg/ovs/ovn-nb-dhcp_options.go @@ -69,22 +69,26 @@ func (c *OVNNbClient) UpdateDHCPOptions(subnet *kubeovnv1.Subnet, mtu int) (*DHC v4Gateway = gateways[0] } - dhcpV4OptUUID, err := c.updateDHCPv4Options(lsName, v4CIDR, v4Gateway, subnet.Spec.DHCPv4Options, mtu) - if err != nil { - klog.Error(err) - return nil, fmt.Errorf("update IPv4 dhcp options for logical switch %s: %v", lsName, err) + dhcpOptionsUUIDs := &DHCPOptionsUUIDs{} + if len(v4CIDR) != 0 { + dhcpV4OptUUID, err := c.updateDHCPv4Options(lsName, v4CIDR, v4Gateway, subnet.Spec.DHCPv4Options, mtu) + if err != nil { + klog.Error(err) + return nil, fmt.Errorf("update IPv4 dhcp options for logical switch %s: %v", lsName, err) + } + dhcpOptionsUUIDs.DHCPv4OptionsUUID = dhcpV4OptUUID } - dhcpV6OptUUID, err := c.updateDHCPv6Options(lsName, v6CIDR, subnet.Spec.DHCPv6Options) - if err != nil { - klog.Error(err) - return nil, fmt.Errorf("update IPv6 dhcp options for logical switch %s: %v", lsName, err) + if len(v6CIDR) != 0 { + dhcpV6OptUUID, err := c.updateDHCPv6Options(lsName, v6CIDR, subnet.Spec.DHCPv6Options) + if err != nil { + klog.Error(err) + return nil, fmt.Errorf("update IPv6 dhcp options for logical switch %s: %v", lsName, err) + } + dhcpOptionsUUIDs.DHCPv6OptionsUUID = dhcpV6OptUUID } - return &DHCPOptionsUUIDs{ - dhcpV4OptUUID, - dhcpV6OptUUID, - }, nil + return dhcpOptionsUUIDs, nil } func (c *OVNNbClient) updateDHCPv4Options(lsName, cidr, gateway, options string, mtu int) (uuid string, err error) {