Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1bcba7d

Browse files
author
Jitendra Bhurat
committed
Fixing test failure
1 parent 93945b5 commit 1bcba7d

3 files changed

Lines changed: 102 additions & 15 deletions

File tree

pkg/proxy/userspace/proxier_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"k8s.io/kubernetes/pkg/proxy"
3434
"k8s.io/kubernetes/pkg/types"
3535
ipttest "k8s.io/kubernetes/pkg/util/iptables/testing"
36+
netshtest "k8s.io/kubernetes/pkg/util/netsh/testing"
3637
"k8s.io/kubernetes/pkg/util/runtime"
3738
)
3839

@@ -210,7 +211,7 @@ func TestTCPProxy(t *testing.T) {
210211
},
211212
})
212213

213-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
214+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
214215
if err != nil {
215216
t.Fatal(err)
216217
}
@@ -237,7 +238,7 @@ func TestUDPProxy(t *testing.T) {
237238
},
238239
})
239240

240-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
241+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
241242
if err != nil {
242243
t.Fatal(err)
243244
}
@@ -264,7 +265,7 @@ func TestUDPProxyTimeout(t *testing.T) {
264265
},
265266
})
266267

267-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
268+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
268269
if err != nil {
269270
t.Fatal(err)
270271
}
@@ -300,7 +301,7 @@ func TestMultiPortProxy(t *testing.T) {
300301
}},
301302
}})
302303

303-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
304+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
304305
if err != nil {
305306
t.Fatal(err)
306307
}
@@ -327,7 +328,7 @@ func TestMultiPortOnServiceUpdate(t *testing.T) {
327328
serviceQ := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "q"}
328329
serviceX := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "x"}
329330

330-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
331+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
331332
if err != nil {
332333
t.Fatal(err)
333334
}
@@ -390,7 +391,7 @@ func TestTCPProxyStop(t *testing.T) {
390391
},
391392
})
392393

393-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
394+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
394395
if err != nil {
395396
t.Fatal(err)
396397
}
@@ -434,7 +435,7 @@ func TestUDPProxyStop(t *testing.T) {
434435
},
435436
})
436437

437-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
438+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
438439
if err != nil {
439440
t.Fatal(err)
440441
}
@@ -472,7 +473,7 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
472473
},
473474
})
474475

475-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
476+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
476477
if err != nil {
477478
t.Fatal(err)
478479
}
@@ -509,7 +510,7 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
509510
},
510511
})
511512

512-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
513+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
513514
if err != nil {
514515
t.Fatal(err)
515516
}
@@ -545,7 +546,7 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
545546
}
546547
lb.OnEndpointsUpdate([]api.Endpoints{endpoint})
547548

548-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
549+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
549550
if err != nil {
550551
t.Fatal(err)
551552
}
@@ -598,7 +599,7 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
598599
}
599600
lb.OnEndpointsUpdate([]api.Endpoints{endpoint})
600601

601-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
602+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
602603
if err != nil {
603604
t.Fatal(err)
604605
}
@@ -652,7 +653,7 @@ func TestTCPProxyUpdatePort(t *testing.T) {
652653
},
653654
})
654655

655-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
656+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
656657
if err != nil {
657658
t.Fatal(err)
658659
}
@@ -700,7 +701,7 @@ func TestUDPProxyUpdatePort(t *testing.T) {
700701
},
701702
})
702703

703-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
704+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
704705
if err != nil {
705706
t.Fatal(err)
706707
}
@@ -745,7 +746,7 @@ func TestProxyUpdatePublicIPs(t *testing.T) {
745746
},
746747
})
747748

748-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
749+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
749750
if err != nil {
750751
t.Fatal(err)
751752
}
@@ -796,7 +797,7 @@ func TestProxyUpdatePortal(t *testing.T) {
796797
}
797798
lb.OnEndpointsUpdate([]api.Endpoints{endpoint})
798799

799-
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
800+
p, err := createProxier(lb, net.ParseIP("0.0.0.0"), ipttest.NewFake(), netshtest.NewFake(), net.ParseIP("127.0.0.1"), nil, time.Minute, udpIdleTimeoutForTest)
800801
if err != nil {
801802
t.Fatal(err)
802803
}

pkg/util/netsh/testing/BUILD

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
licenses(["notice"])
4+
5+
load(
6+
"@io_bazel_rules_go//go:def.bzl",
7+
"go_binary",
8+
"go_library",
9+
"go_test",
10+
"cgo_library",
11+
)
12+
13+
go_library(
14+
name = "go_default_library",
15+
srcs = ["fake.go"],
16+
tags = ["automanaged"],
17+
deps = ["//pkg/util/netsh:go_default_library"],
18+
)

pkg/util/netsh/testing/fake.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright 2015 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package testing
18+
19+
import (
20+
"net"
21+
22+
"k8s.io/kubernetes/pkg/util/netsh"
23+
)
24+
25+
// no-op implementation of netsh Interface
26+
type FakeNetsh struct {
27+
}
28+
29+
func NewFake() *FakeNetsh {
30+
return &FakeNetsh{}
31+
}
32+
33+
func (*FakeNetsh) EnsurePortProxyRule(args []string) (bool, error) {
34+
return true, nil
35+
}
36+
37+
// DeletePortProxyRule deletes the specified portproxy rule. If the rule did not exist, return error.
38+
func (*FakeNetsh) DeletePortProxyRule(args []string) error {
39+
// Do Nothing
40+
return nil
41+
}
42+
43+
// EnsureIPAddress checks if the specified IP Address is added to vEthernet (HNSTransparent) interface, if not, add it. If the address existed, return true.
44+
func (*FakeNetsh) EnsureIPAddress(args []string, ip net.IP) (bool, error) {
45+
return true, nil
46+
}
47+
48+
// DeleteIPAddress checks if the specified IP address is present and, if so, deletes it.
49+
func (*FakeNetsh) DeleteIPAddress(args []string) error {
50+
// Do Nothing
51+
return nil
52+
}
53+
54+
// Restore runs `netsh exec` to restore portproxy or addresses using a file.
55+
// TODO Check if this is required, most likely not
56+
func (*FakeNetsh) Restore(args []string) error {
57+
// Do Nothing
58+
return nil
59+
}
60+
61+
// GetInterfaceToAddIP returns the interface name where Service IP needs to be added
62+
// IP Address needs to be added for netsh portproxy to redirect traffic
63+
// Reads Environment variable INTERFACE_TO_ADD_SERVICE_IP, if it is not defined then "vEthernet (HNSTransparent)" is returned
64+
func (*FakeNetsh) GetInterfaceToAddIP() string {
65+
return "Interface 1"
66+
}
67+
68+
var _ = netsh.Interface(&FakeNetsh{})

0 commit comments

Comments
 (0)