Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b842f008
Commit
b842f008
authored
Dec 28, 2017
by
Lion-Wei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify ipvs real server equal
parent
18758f50
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
6 deletions
+25
-6
fake.go
pkg/util/ipvs/testing/fake.go
+25
-6
No files found.
pkg/util/ipvs/testing/fake.go
View file @
b842f008
...
@@ -18,6 +18,8 @@ package testing
...
@@ -18,6 +18,8 @@ package testing
import
(
import
(
"fmt"
"fmt"
"net"
"strconv"
utilipvs
"k8s.io/kubernetes/pkg/util/ipvs"
utilipvs
"k8s.io/kubernetes/pkg/util/ipvs"
)
)
...
@@ -39,6 +41,15 @@ func (s *serviceKey) String() string {
...
@@ -39,6 +41,15 @@ func (s *serviceKey) String() string {
return
fmt
.
Sprintf
(
"%s:%d/%s"
,
s
.
IP
,
s
.
Port
,
s
.
Protocol
)
return
fmt
.
Sprintf
(
"%s:%d/%s"
,
s
.
IP
,
s
.
Port
,
s
.
Protocol
)
}
}
type
realServerKey
struct
{
Address
net
.
IP
Port
uint16
}
func
(
r
*
realServerKey
)
String
()
string
{
return
net
.
JoinHostPort
(
r
.
Address
.
String
(),
strconv
.
Itoa
(
int
(
r
.
Port
)))
}
//NewFake creates a fake ipvs implementation - a cache store.
//NewFake creates a fake ipvs implementation - a cache store.
func
NewFake
()
*
FakeIPVS
{
func
NewFake
()
*
FakeIPVS
{
return
&
FakeIPVS
{
return
&
FakeIPVS
{
...
@@ -55,6 +66,13 @@ func toServiceKey(serv *utilipvs.VirtualServer) serviceKey {
...
@@ -55,6 +66,13 @@ func toServiceKey(serv *utilipvs.VirtualServer) serviceKey {
}
}
}
}
func
toRealServerKey
(
rs
*
utilipvs
.
RealServer
)
*
realServerKey
{
return
&
realServerKey
{
Address
:
rs
.
Address
,
Port
:
rs
.
Port
,
}
}
//AddVirtualServer is a fake implementation, it simply adds the VirtualServer into the cache store.
//AddVirtualServer is a fake implementation, it simply adds the VirtualServer into the cache store.
func
(
f
*
FakeIPVS
)
AddVirtualServer
(
serv
*
utilipvs
.
VirtualServer
)
error
{
func
(
f
*
FakeIPVS
)
AddVirtualServer
(
serv
*
utilipvs
.
VirtualServer
)
error
{
if
serv
==
nil
{
if
serv
==
nil
{
...
@@ -159,18 +177,19 @@ func (f *FakeIPVS) DeleteRealServer(serv *utilipvs.VirtualServer, dest *utilipvs
...
@@ -159,18 +177,19 @@ func (f *FakeIPVS) DeleteRealServer(serv *utilipvs.VirtualServer, dest *utilipvs
return
fmt
.
Errorf
(
"Failed to delete destination for service %v, service not found"
,
key
.
String
())
return
fmt
.
Errorf
(
"Failed to delete destination for service %v, service not found"
,
key
.
String
())
}
}
dests
:=
f
.
Destinations
[
key
]
dests
:=
f
.
Destinations
[
key
]
var
i
int
exist
:=
false
for
i
=
range
dests
{
for
i
:=
range
dests
{
if
dests
[
i
]
.
Equal
(
dest
)
{
if
toRealServerKey
(
dests
[
i
])
.
String
()
==
toRealServerKey
(
dest
)
.
String
()
{
// Delete one element
f
.
Destinations
[
key
]
=
append
(
f
.
Destinations
[
key
][
:
i
],
f
.
Destinations
[
key
][
i
+
1
:
]
...
)
exist
=
true
break
break
}
}
}
}
// Not Found
// Not Found
if
i
>=
len
(
f
.
Destinations
[
key
])
{
if
!
exist
{
return
fmt
.
Errorf
(
"Failed to delete real server for service %v, real server not found"
,
key
.
String
())
return
fmt
.
Errorf
(
"Failed to delete real server for service %v, real server not found"
,
key
.
String
())
}
}
// Delete one element
f
.
Destinations
[
key
]
=
append
(
f
.
Destinations
[
key
][
:
i
],
f
.
Destinations
[
key
][
i
+
1
:
]
...
)
return
nil
return
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment