mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #52976 from sakeven/fix/netsh_checkIPExists
Automatic merge from submit-queue (batch tested with PRs 55114, 52976, 54871, 55122, 55140). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix netsh checkIPExists in Chinese Signed-off-by: sakeven <jc5930@sina.cn> **What this PR does / why we need it**: On Windows in Chinese language, kube-proxy ip dump outputs like this: ``` 接口 "vEthernet (KubeProxySwitch)" 的配置 DHCP 已启用: 否 IP 地址: 10.96.0.2 子网前缀: 10.0.0.0/8 (掩码 255.0.0.0) IP 地址: 10.99.233.195 子网前缀: 10.0.0.0/8 (掩码 255.0.0.0) IP 地址: 10.109.68.207 子网前缀: 10.0.0.0/8 (掩码 255.0.0.0) IP 地址: 10.110.60.68 子网前缀: 10.0.0.0/8 (掩码 255.0.0.0) IP 地址: 10.110.252.225 子网前缀: 10.0.0.0/8 (掩码 255.0.0.0) InterfaceMetric: 15 ``` And here we used ''IP Address:" in English to search IP, so it would never succeed even if ip address was right here. ''IP Address:" in Chinese is "IP 地址: "。 **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ``` NONE ```
This commit is contained in:
commit
b4b851cb0e
@ -190,9 +190,8 @@ func checkIPExists(ipToCheck string, args []string, runner *runner) (bool, error
|
||||
glog.V(3).Infof("Searching for IP: %v in IP dump: %v", ipToCheck, ipAddressString)
|
||||
showAddressArray := strings.Split(ipAddressString, "\n")
|
||||
for _, showAddress := range showAddressArray {
|
||||
if strings.Contains(showAddress, "IP Address:") {
|
||||
ipFromNetsh := strings.TrimLeft(showAddress, "IP Address:")
|
||||
ipFromNetsh = strings.TrimSpace(ipFromNetsh)
|
||||
if strings.Contains(showAddress, "IP") {
|
||||
ipFromNetsh := getIP(showAddress)
|
||||
if ipFromNetsh == ipToCheck {
|
||||
return true, nil
|
||||
}
|
||||
@ -201,3 +200,12 @@ func checkIPExists(ipToCheck string, args []string, runner *runner) (bool, error
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// getIP gets ip from showAddress (e.g. "IP Address: 10.96.0.4").
|
||||
func getIP(showAddress string) string {
|
||||
list := strings.SplitN(showAddress, ":", 2)
|
||||
if len(list) != 2 {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(list[1])
|
||||
}
|
||||
|
@ -438,3 +438,30 @@ func TestCheckIPExists(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetIP(t *testing.T) {
|
||||
testcases := []struct {
|
||||
showAddress string
|
||||
expectAddress string
|
||||
}{
|
||||
{
|
||||
showAddress: "IP 地址: 10.96.0.2",
|
||||
expectAddress: "10.96.0.2",
|
||||
},
|
||||
{
|
||||
showAddress: "IP Address: 10.96.0.3",
|
||||
expectAddress: "10.96.0.3",
|
||||
},
|
||||
{
|
||||
showAddress: "IP Address:10.96.0.4",
|
||||
expectAddress: "10.96.0.4",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
address := getIP(tc.showAddress)
|
||||
if address != tc.expectAddress {
|
||||
t.Errorf("expected address=%q, got %q", tc.expectAddress, address)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user