Skip to content

Commit 4f00d3a

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#53519 from m1093782566/more-fakes
Automatic merge from submit-queue. 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>. implement fakeIPVS update virtual server **What this PR does / why we need it**: * Implement UpdateVirtualServer() for FakeIPVS because ipvs/proxier needs it. * Add UTs - Since there are some real logics in fakeIPVS interface, it's important to add some UTs which can help avoiding some mistakes. **Which issue this PR fixes**: fixes kubernetes#53518 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
2 parents fe5c628 + 8f6f382 commit 4f00d3a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pkg/util/ipvs/testing/fake.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ func (f *FakeIPVS) AddVirtualServer(serv *utilipvs.VirtualServer) error {
7777
return nil
7878
}
7979

80-
//UpdateVirtualServer is an empty implementation
80+
//UpdateVirtualServer is a fake implementation, it updates the VirtualServer in the cache store.
8181
func (f *FakeIPVS) UpdateVirtualServer(serv *utilipvs.VirtualServer) error {
8282
if serv == nil {
8383
return fmt.Errorf("Failed to update service, service can't be nil")
8484
}
85+
key := toServiceKey(serv)
86+
f.Services[key] = serv
8587
return nil
8688
}
8789

pkg/util/ipvs/testing/fake_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestVirtualServer(t *testing.T) {
3131
Address: net.ParseIP("1.2.3.4"),
3232
Port: uint16(80),
3333
Protocol: string("TCP"),
34+
Flags: utilipvs.FlagHashed,
3435
}
3536
err := fake.AddVirtualServer(vs1)
3637
if err != nil {
@@ -44,6 +45,22 @@ func TestVirtualServer(t *testing.T) {
4445
if !vs1.Equal(got1) {
4546
t.Errorf("Expect virtual server: %v, got: %v", vs1, got1)
4647
}
48+
// Update virtual server
49+
vs12 := &utilipvs.VirtualServer{
50+
Address: net.ParseIP("1.2.3.4"),
51+
Port: uint16(80),
52+
Protocol: string("TCP"),
53+
Flags: utilipvs.FlagPersistent,
54+
}
55+
err = fake.UpdateVirtualServer(vs12)
56+
if err != nil {
57+
t.Errorf("Fail to update virutal server, error: %v", err)
58+
}
59+
// Check the updated virtual server
60+
got12, err := fake.GetVirtualServer(vs1)
61+
if !got12.Equal(vs12) {
62+
t.Errorf("Expect virutal server: %v, got: %v", vs12, got12)
63+
}
4764
// Add another virtual server
4865
vs2 := &utilipvs.VirtualServer{
4966
Address: net.ParseIP("10::40"),

0 commit comments

Comments
 (0)