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
12058c6a
Commit
12058c6a
authored
May 02, 2017
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete unused code
parent
699606cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
46 deletions
+17
-46
proxier.go
pkg/proxy/userspace/proxier.go
+2
-16
proxier_test.go
pkg/proxy/userspace/proxier_test.go
+15
-30
No files found.
pkg/proxy/userspace/proxier.go
View file @
12058c6a
...
...
@@ -52,8 +52,6 @@ type ServiceInfo struct {
Timeout
time
.
Duration
// ActiveClients is the cache of active UDP clients being proxied by this proxy for this service
ActiveClients
*
ClientCache
// ServiceRef is a full object reference to the the service described by this ServiceInfo
ServiceRef
api
.
ObjectReference
isAliveAtomic
int32
// Only access this with atomic ops
portal
portal
...
...
@@ -358,7 +356,7 @@ func (proxier *Proxier) setServiceInfo(service proxy.ServicePortName, info *Serv
// addServiceOnPort starts listening for a new service, returning the ServiceInfo.
// Pass proxyPort=0 to allocate a random port. The timeout only applies to UDP
// connections, for now.
func
(
proxier
*
Proxier
)
addServiceOnPort
(
service
proxy
.
ServicePortName
,
serviceRef
api
.
ObjectReference
,
protocol
api
.
Protocol
,
proxyPort
int
,
timeout
time
.
Duration
)
(
*
ServiceInfo
,
error
)
{
func
(
proxier
*
Proxier
)
addServiceOnPort
(
service
proxy
.
ServicePortName
,
protocol
api
.
Protocol
,
proxyPort
int
,
timeout
time
.
Duration
)
(
*
ServiceInfo
,
error
)
{
sock
,
err
:=
proxier
.
makeProxySocket
(
protocol
,
proxier
.
listenIP
,
proxyPort
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -376,7 +374,6 @@ func (proxier *Proxier) addServiceOnPort(service proxy.ServicePortName, serviceR
si
:=
&
ServiceInfo
{
Timeout
:
timeout
,
ActiveClients
:
newClientCache
(),
ServiceRef
:
serviceRef
,
isAliveAtomic
:
1
,
proxyPort
:
portNum
,
...
...
@@ -411,17 +408,6 @@ func (proxier *Proxier) OnServiceUpdate(services []*api.Service) {
continue
}
// TODO: should this just be ref.GetReference?
svcGVK
:=
service
.
GetObjectKind
()
.
GroupVersionKind
()
svcRef
:=
api
.
ObjectReference
{
Kind
:
svcGVK
.
Kind
,
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
,
UID
:
service
.
UID
,
APIVersion
:
svcGVK
.
GroupVersion
()
.
String
(),
ResourceVersion
:
service
.
ResourceVersion
,
}
for
i
:=
range
service
.
Spec
.
Ports
{
servicePort
:=
&
service
.
Spec
.
Ports
[
i
]
serviceName
:=
proxy
.
ServicePortName
{
NamespacedName
:
types
.
NamespacedName
{
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
},
Port
:
servicePort
.
Name
}
...
...
@@ -452,7 +438,7 @@ func (proxier *Proxier) OnServiceUpdate(services []*api.Service) {
}
glog
.
V
(
1
)
.
Infof
(
"Adding new service %q at %s:%d/%s"
,
serviceName
,
serviceIP
,
servicePort
.
Port
,
servicePort
.
Protocol
)
info
,
err
=
proxier
.
addServiceOnPort
(
serviceName
,
s
vcRef
,
s
ervicePort
.
Protocol
,
proxyPort
,
proxier
.
udpIdleTimeout
)
info
,
err
=
proxier
.
addServiceOnPort
(
serviceName
,
servicePort
.
Protocol
,
proxyPort
,
proxier
.
udpIdleTimeout
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to start proxy for %q: %v"
,
serviceName
,
err
)
continue
...
...
pkg/proxy/userspace/proxier_test.go
View file @
12058c6a
...
...
@@ -218,8 +218,7 @@ func TestTCPProxy(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"TCP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"TCP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -246,8 +245,7 @@ func TestUDPProxy(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"UDP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"UDP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -274,8 +272,7 @@ func TestUDPProxyTimeout(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"UDP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"UDP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -314,16 +311,14 @@ func TestMultiPortProxy(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRefP
:=
api
.
ObjectReference
{
Name
:
serviceP
.
Name
,
Namespace
:
serviceP
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfoP
,
err
:=
p
.
addServiceOnPort
(
serviceP
,
serviceRefP
,
"TCP"
,
0
,
time
.
Second
)
svcInfoP
,
err
:=
p
.
addServiceOnPort
(
serviceP
,
"TCP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
testEchoTCP
(
t
,
"127.0.0.1"
,
svcInfoP
.
proxyPort
)
waitForNumProxyLoops
(
t
,
p
,
1
)
serviceRefQ
:=
api
.
ObjectReference
{
Name
:
serviceQ
.
Name
,
Namespace
:
serviceQ
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfoQ
,
err
:=
p
.
addServiceOnPort
(
serviceQ
,
serviceRefQ
,
"UDP"
,
0
,
time
.
Second
)
svcInfoQ
,
err
:=
p
.
addServiceOnPort
(
serviceQ
,
"UDP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -408,8 +403,7 @@ func TestTCPProxyStop(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"TCP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"TCP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -453,8 +447,7 @@ func TestUDPProxyStop(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"UDP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"UDP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -492,8 +485,7 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"TCP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"TCP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -530,8 +522,7 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"UDP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"UDP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -569,8 +560,7 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"TCP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"TCP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -625,8 +615,7 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"UDP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"UDP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -680,8 +669,7 @@ func TestTCPProxyUpdatePort(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"TCP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"TCP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -729,8 +717,7 @@ func TestUDPProxyUpdatePort(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"UDP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"UDP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -775,8 +762,7 @@ func TestProxyUpdatePublicIPs(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"TCP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"TCP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
@@ -829,8 +815,7 @@ func TestProxyUpdatePortal(t *testing.T) {
}
waitForNumProxyLoops
(
t
,
p
,
0
)
serviceRef
:=
api
.
ObjectReference
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
Kind
:
"Service"
,
APIVersion
:
"v1"
}
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
serviceRef
,
"TCP"
,
0
,
time
.
Second
)
svcInfo
,
err
:=
p
.
addServiceOnPort
(
service
,
"TCP"
,
0
,
time
.
Second
)
if
err
!=
nil
{
t
.
Fatalf
(
"error adding new service: %#v"
,
err
)
}
...
...
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