diff --git a/pkg/util/validator.go b/pkg/util/validator.go index f0eb18a342ab..0e4321fb0267 100644 --- a/pkg/util/validator.go +++ b/pkg/util/validator.go @@ -13,9 +13,12 @@ import ( ) func ValidateSubnet(subnet kubeovnv1.Subnet) error { - if subnet.Spec.Gateway != "" && (!CIDRContainIP(subnet.Spec.CIDRBlock, subnet.Spec.Gateway) || ValidateNetworkBroadcast(subnet.Spec.CIDRBlock, subnet.Spec.Gateway) != nil) { + if subnet.Spec.Gateway != "" && !CIDRContainIP(subnet.Spec.CIDRBlock, subnet.Spec.Gateway) { return fmt.Errorf("gateway %s is not in cidr %s", subnet.Spec.Gateway, subnet.Spec.CIDRBlock) } + if err := ValidateNetworkBroadcast(subnet.Spec.CIDRBlock, subnet.Spec.Gateway); err != nil { + return fmt.Errorf("validate gateway %s for cidr %s failed: %v", subnet.Spec.Gateway, subnet.Spec.CIDRBlock, err) + } if err := CIDRGlobalUnicast(subnet.Spec.CIDRBlock); err != nil { return err }