mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-03 03:38:15 +00:00
Refactor to use k8s.io/utils/net/ package instead of kubernetes/pkg/util/net/sets
Signed-off-by: Ashish Ranjan <ashishranjan738@gmail.com>
This commit is contained in:
@@ -27,7 +27,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/client-go/tools/record"
|
||||
helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||
utilnet "k8s.io/kubernetes/pkg/util/net"
|
||||
utilnet "k8s.io/utils/net"
|
||||
|
||||
"k8s.io/klog"
|
||||
)
|
||||
@@ -192,3 +192,25 @@ func LogAndEmitIncorrectIPVersionEvent(recorder record.EventRecorder, fieldName,
|
||||
}, v1.EventTypeWarning, "KubeProxyIncorrectIPVersion", errMsg)
|
||||
}
|
||||
}
|
||||
|
||||
// FilterIncorrectIPVersion filters out the incorrect IP version case from a slice of IP strings.
|
||||
func FilterIncorrectIPVersion(ipStrings []string, isIPv6Mode bool) ([]string, []string) {
|
||||
return filterWithCondition(ipStrings, isIPv6Mode, utilnet.IsIPv6String)
|
||||
}
|
||||
|
||||
// FilterIncorrectCIDRVersion filters out the incorrect IP version case from a slice of CIDR strings.
|
||||
func FilterIncorrectCIDRVersion(ipStrings []string, isIPv6Mode bool) ([]string, []string) {
|
||||
return filterWithCondition(ipStrings, isIPv6Mode, utilnet.IsIPv6CIDRString)
|
||||
}
|
||||
|
||||
func filterWithCondition(strs []string, expectedCondition bool, conditionFunc func(string) bool) ([]string, []string) {
|
||||
var corrects, incorrects []string
|
||||
for _, str := range strs {
|
||||
if conditionFunc(str) != expectedCondition {
|
||||
incorrects = append(incorrects, str)
|
||||
} else {
|
||||
corrects = append(corrects, str)
|
||||
}
|
||||
}
|
||||
return corrects, incorrects
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user