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

fix bugs and enhance unit test coverage for all functions in pkg/util/validator.go #4505

Merged
merged 3 commits into from
Sep 18, 2024
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
11 changes: 6 additions & 5 deletions pkg/util/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ValidateSubnet(subnet kubeovnv1.Subnet) error {
for _, cidr := range strings.Split(subnet.Spec.CIDRBlock, ",") {
// v6 ip address can not use upper case
if ContainsUppercase(subnet.Spec.CIDRBlock) {
err := fmt.Errorf("subnet cidr block %s v6 ip address can not contain upper case", subnet.Spec.Gateway)
err := fmt.Errorf("subnet cidr block %s v6 ip address can not contain upper case", subnet.Spec.CIDRBlock)
klog.Error(err)
return err
}
Expand All @@ -86,7 +86,7 @@ func ValidateSubnet(subnet kubeovnv1.Subnet) error {
allow := subnet.Spec.AllowSubnets
for _, cidr := range allow {
// v6 ip address can not use upper case
if ContainsUppercase(subnet.Spec.CIDRBlock) {
if ContainsUppercase(cidr) {
err := fmt.Errorf("subnet %s allow subnet %s v6 ip address can not contain upper case", subnet.Name, cidr)
klog.Error(err)
return err
Expand Down Expand Up @@ -205,10 +205,11 @@ func validateNatOutgoingPolicyRules(subnet kubeovnv1.Subnet) error {
}

func validateNatOutGoingPolicyRuleIPs(matchIPStr string) (string, error) {
ipItems := strings.Split(matchIPStr, ",")
if len(ipItems) == 0 {
return "", errors.New("MatchIPStr format error")
if matchIPStr = strings.TrimSpace(matchIPStr); matchIPStr == "" {
return "", errors.New("IPStr should not be empty")
}

ipItems := strings.Split(matchIPStr, ",")
lastProtocol := ""
checkProtocolConsistent := func(ipCidr string) bool {
currentProtocol := CheckProtocol(ipCidr)
Expand Down
Loading
Loading