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
a57fbaf6
Unverified
Commit
a57fbaf6
authored
May 28, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 28, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #78088 from andrewsykim/ipvs-unit-test-graceful-termination
ipvs: add graceful termination unit tests
parents
2f7eaa1e
6677d796
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
353 additions
and
12 deletions
+353
-12
BUILD
pkg/proxy/ipvs/BUILD
+1
-0
graceful_termination_test.go
pkg/proxy/ipvs/graceful_termination_test.go
+338
-0
fake.go
pkg/util/ipvs/testing/fake.go
+14
-12
No files found.
pkg/proxy/ipvs/BUILD
View file @
a57fbaf6
...
...
@@ -9,6 +9,7 @@ load(
go_test(
name = "go_default_test",
srcs = [
"graceful_termination_test.go",
"ipset_test.go",
"proxier_test.go",
],
...
...
pkg/proxy/ipvs/graceful_termination_test.go
0 → 100644
View file @
a57fbaf6
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
ipvs
import
(
"net"
"reflect"
"testing"
utilipvs
"k8s.io/kubernetes/pkg/util/ipvs"
utilipvstest
"k8s.io/kubernetes/pkg/util/ipvs/testing"
)
func
Test_GracefulDeleteRS
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
vs
*
utilipvs
.
VirtualServer
rs
*
utilipvs
.
RealServer
existingIPVS
*
utilipvstest
.
FakeIPVS
expectedIPVS
*
utilipvstest
.
FakeIPVS
err
error
}{
{
name
:
"graceful delete, no connections results in deleting the real server immediatetly"
,
vs
:
&
utilipvs
.
VirtualServer
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
rs
:
&
utilipvs
.
RealServer
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
80
),
Weight
:
100
,
ActiveConn
:
0
,
InactiveConn
:
0
,
},
existingIPVS
:
&
utilipvstest
.
FakeIPVS
{
Services
:
map
[
utilipvstest
.
ServiceKey
]
*
utilipvs
.
VirtualServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
},
Destinations
:
map
[
utilipvstest
.
ServiceKey
][]
*
utilipvs
.
RealServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
80
),
Weight
:
100
,
ActiveConn
:
0
,
InactiveConn
:
0
,
},
},
},
},
expectedIPVS
:
&
utilipvstest
.
FakeIPVS
{
Services
:
map
[
utilipvstest
.
ServiceKey
]
*
utilipvs
.
VirtualServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
},
Destinations
:
map
[
utilipvstest
.
ServiceKey
][]
*
utilipvs
.
RealServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{},
},
},
err
:
nil
,
},
{
name
:
"graceful delete, real server has active connections, weight should be 0 but don't delete"
,
vs
:
&
utilipvs
.
VirtualServer
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
rs
:
&
utilipvs
.
RealServer
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
80
),
Weight
:
100
,
ActiveConn
:
10
,
InactiveConn
:
0
,
},
existingIPVS
:
&
utilipvstest
.
FakeIPVS
{
Services
:
map
[
utilipvstest
.
ServiceKey
]
*
utilipvs
.
VirtualServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
},
Destinations
:
map
[
utilipvstest
.
ServiceKey
][]
*
utilipvs
.
RealServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
80
),
Weight
:
100
,
ActiveConn
:
10
,
InactiveConn
:
0
,
},
},
},
},
expectedIPVS
:
&
utilipvstest
.
FakeIPVS
{
Services
:
map
[
utilipvstest
.
ServiceKey
]
*
utilipvs
.
VirtualServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
},
Destinations
:
map
[
utilipvstest
.
ServiceKey
][]
*
utilipvs
.
RealServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
80
),
Weight
:
0
,
ActiveConn
:
10
,
InactiveConn
:
0
,
},
},
},
},
err
:
nil
,
},
{
name
:
"graceful delete, real server has in-active connections, weight should be 0 but don't delete"
,
vs
:
&
utilipvs
.
VirtualServer
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
rs
:
&
utilipvs
.
RealServer
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
80
),
Weight
:
100
,
ActiveConn
:
0
,
InactiveConn
:
10
,
},
existingIPVS
:
&
utilipvstest
.
FakeIPVS
{
Services
:
map
[
utilipvstest
.
ServiceKey
]
*
utilipvs
.
VirtualServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
},
Destinations
:
map
[
utilipvstest
.
ServiceKey
][]
*
utilipvs
.
RealServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
80
),
Weight
:
100
,
ActiveConn
:
0
,
InactiveConn
:
10
,
},
},
},
},
expectedIPVS
:
&
utilipvstest
.
FakeIPVS
{
Services
:
map
[
utilipvstest
.
ServiceKey
]
*
utilipvs
.
VirtualServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
},
Destinations
:
map
[
utilipvstest
.
ServiceKey
][]
*
utilipvs
.
RealServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
80
),
Weight
:
0
,
ActiveConn
:
0
,
InactiveConn
:
10
,
},
},
},
},
err
:
nil
,
},
{
name
:
"graceful delete, real server mismatch should be no-op"
,
vs
:
&
utilipvs
.
VirtualServer
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
rs
:
&
utilipvs
.
RealServer
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
81
),
// port mismatched
Weight
:
100
,
ActiveConn
:
0
,
InactiveConn
:
10
,
},
existingIPVS
:
&
utilipvstest
.
FakeIPVS
{
Services
:
map
[
utilipvstest
.
ServiceKey
]
*
utilipvs
.
VirtualServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
},
Destinations
:
map
[
utilipvstest
.
ServiceKey
][]
*
utilipvs
.
RealServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
80
),
Weight
:
100
,
ActiveConn
:
0
,
InactiveConn
:
10
,
},
},
},
},
expectedIPVS
:
&
utilipvstest
.
FakeIPVS
{
Services
:
map
[
utilipvstest
.
ServiceKey
]
*
utilipvs
.
VirtualServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
Address
:
net
.
ParseIP
(
"1.1.1.1"
),
Protocol
:
"tcp"
,
Port
:
uint16
(
80
),
},
},
Destinations
:
map
[
utilipvstest
.
ServiceKey
][]
*
utilipvs
.
RealServer
{
{
IP
:
"1.1.1.1"
,
Port
:
80
,
Protocol
:
"tcp"
,
}
:
{
{
Address
:
net
.
ParseIP
(
"10.0.0.1"
),
Port
:
uint16
(
80
),
Weight
:
100
,
ActiveConn
:
0
,
InactiveConn
:
10
,
},
},
},
},
err
:
nil
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
ipvs
:=
test
.
existingIPVS
gracefulTerminationManager
:=
NewGracefulTerminationManager
(
ipvs
)
err
:=
gracefulTerminationManager
.
GracefulDeleteRS
(
test
.
vs
,
test
.
rs
)
if
err
!=
test
.
err
{
t
.
Logf
(
"actual err: %v"
,
err
)
t
.
Logf
(
"expected err: %v"
,
test
.
err
)
t
.
Errorf
(
"unexpected error"
)
}
if
!
reflect
.
DeepEqual
(
ipvs
,
test
.
expectedIPVS
)
{
t
.
Logf
(
"actual: %+v"
,
ipvs
)
t
.
Logf
(
"expected : %+v"
,
test
.
expectedIPVS
)
t
.
Errorf
(
"unexpected IPVS servers"
)
}
})
}
}
pkg/util/ipvs/testing/fake.go
View file @
a57fbaf6
...
...
@@ -27,47 +27,49 @@ import (
//FakeIPVS no-op implementation of ipvs Interface
type
FakeIPVS
struct
{
Scheduler
string
Services
map
[
s
erviceKey
]
*
utilipvs
.
VirtualServer
Destinations
map
[
s
erviceKey
][]
*
utilipvs
.
RealServer
Services
map
[
S
erviceKey
]
*
utilipvs
.
VirtualServer
Destinations
map
[
S
erviceKey
][]
*
utilipvs
.
RealServer
}
type
serviceKey
struct
{
// ServiceKey uniquely identifies a Service for an IPVS virtual server
type
ServiceKey
struct
{
IP
string
Port
uint16
Protocol
string
}
func
(
s
*
s
erviceKey
)
String
()
string
{
func
(
s
*
S
erviceKey
)
String
()
string
{
return
fmt
.
Sprintf
(
"%s:%d/%s"
,
s
.
IP
,
s
.
Port
,
s
.
Protocol
)
}
type
realServerKey
struct
{
// RealServerKey uniquely identifies an Endpoint for an IPVS real server
type
RealServerKey
struct
{
Address
net
.
IP
Port
uint16
}
func
(
r
*
r
ealServerKey
)
String
()
string
{
func
(
r
*
R
ealServerKey
)
String
()
string
{
return
net
.
JoinHostPort
(
r
.
Address
.
String
(),
strconv
.
Itoa
(
int
(
r
.
Port
)))
}
//NewFake creates a fake ipvs implementation - a cache store.
func
NewFake
()
*
FakeIPVS
{
return
&
FakeIPVS
{
Services
:
make
(
map
[
s
erviceKey
]
*
utilipvs
.
VirtualServer
),
Destinations
:
make
(
map
[
s
erviceKey
][]
*
utilipvs
.
RealServer
),
Services
:
make
(
map
[
S
erviceKey
]
*
utilipvs
.
VirtualServer
),
Destinations
:
make
(
map
[
S
erviceKey
][]
*
utilipvs
.
RealServer
),
}
}
func
toServiceKey
(
serv
*
utilipvs
.
VirtualServer
)
s
erviceKey
{
return
s
erviceKey
{
func
toServiceKey
(
serv
*
utilipvs
.
VirtualServer
)
S
erviceKey
{
return
S
erviceKey
{
IP
:
serv
.
Address
.
String
(),
Port
:
serv
.
Port
,
Protocol
:
serv
.
Protocol
,
}
}
func
toRealServerKey
(
rs
*
utilipvs
.
RealServer
)
*
r
ealServerKey
{
return
&
r
ealServerKey
{
func
toRealServerKey
(
rs
*
utilipvs
.
RealServer
)
*
R
ealServerKey
{
return
&
R
ealServerKey
{
Address
:
rs
.
Address
,
Port
:
rs
.
Port
,
}
...
...
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