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 error logging #4473

Merged
merged 1 commit into from
Sep 5, 2024
Merged
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
14 changes: 8 additions & 6 deletions pkg/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func CIDRContainIP(cidrStr, ipStr string) bool {
if len(cidrs) == 1 {
for _, ip := range ips {
if CheckProtocol(cidrStr) != CheckProtocol(ip) {
klog.Errorf("ip %s and cidr %s should be the same protocol", ip, cidrStr)
klog.Warningf("ip %q and cidr %q should be the same protocol", ip, cidrStr)
return false
}
}
Expand All @@ -140,12 +140,10 @@ func CIDRContainIP(cidrStr, ipStr string) bool {
}
ipAddr := net.ParseIP(ip)
if ipAddr == nil {
klog.Errorf("invalid ip %s", ip)
klog.Errorf("invalid ip %q", ip)
return false
}

if !cidrNet.Contains(ipAddr) {
klog.Errorf("ip %s is not in cidr %s", ip, cidr)
return false
}
}
Expand All @@ -155,6 +153,10 @@ func CIDRContainIP(cidrStr, ipStr string) bool {
}

func CheckProtocol(address string) string {
if address == "" {
return ""
}

ips := strings.Split(address, ",")
if len(ips) == 2 {
IP1 := net.ParseIP(strings.Split(ips[0], "/")[0])
Expand All @@ -165,7 +167,7 @@ func CheckProtocol(address string) string {
if IP2.To4() != nil && IP1.To4() == nil && IP1.To16() != nil {
return kubeovnv1.ProtocolDual
}
err := fmt.Errorf("invalid address %s", address)
err := fmt.Errorf("invalid address %q", address)
klog.Error(err)
return ""
}
Expand All @@ -179,7 +181,7 @@ func CheckProtocol(address string) string {
}

// cidr format error
err := fmt.Errorf("invalid address %s", address)
err := fmt.Errorf("invalid address %q", address)
klog.Error(err)
return ""
}
Expand Down
Loading