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
48647fb9
Commit
48647fb9
authored
Feb 03, 2017
by
Anthony Howe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tcp or udp proxy for service addresses
parent
fcb234e5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
13 deletions
+32
-13
server.go
cmd/kube-proxy/app/server.go
+10
-5
types.go
pkg/proxy/types.go
+12
-0
proxier.go
pkg/proxy/winuserspace/proxier.go
+0
-0
proxysocket.go
pkg/proxy/winuserspace/proxysocket.go
+8
-6
netsh.go
pkg/util/netsh/netsh.go
+2
-2
No files found.
cmd/kube-proxy/app/server.go
View file @
48647fb9
...
@@ -249,15 +249,15 @@ func NewProxyServerDefault(config *options.ProxyServerConfig) (*ProxyServer, err
...
@@ -249,15 +249,15 @@ func NewProxyServerDefault(config *options.ProxyServerConfig) (*ProxyServer, err
userspace
.
CleanupLeftovers
(
iptInterface
)
userspace
.
CleanupLeftovers
(
iptInterface
)
}
else
{
}
else
{
glog
.
V
(
0
)
.
Info
(
"Using userspace Proxier."
)
glog
.
V
(
0
)
.
Info
(
"Using userspace Proxier."
)
// This is a proxy.LoadBalancer which NewProxier needs but has methods we don't need for
// our config.EndpointsConfigHandler.
loadBalancer
:=
userspace
.
NewLoadBalancerRR
()
// set EndpointsConfigHandler to our loadBalancer
endpointsHandler
=
loadBalancer
var
proxierUserspace
proxy
.
ProxyProvider
var
proxierUserspace
proxy
.
ProxyProvider
if
runtime
.
GOOS
==
"windows"
{
if
runtime
.
GOOS
==
"windows"
{
// This is a proxy.LoadBalancer which NewProxier needs but has methods we don't need for
// our config.EndpointsConfigHandler.
loadBalancer
:=
winuserspace
.
NewLoadBalancerRR
()
// set EndpointsConfigHandler to our loadBalancer
endpointsHandler
=
loadBalancer
proxierUserspace
,
err
=
winuserspace
.
NewProxier
(
proxierUserspace
,
err
=
winuserspace
.
NewProxier
(
loadBalancer
,
loadBalancer
,
net
.
ParseIP
(
config
.
BindAddress
),
net
.
ParseIP
(
config
.
BindAddress
),
...
@@ -268,6 +268,11 @@ func NewProxyServerDefault(config *options.ProxyServerConfig) (*ProxyServer, err
...
@@ -268,6 +268,11 @@ func NewProxyServerDefault(config *options.ProxyServerConfig) (*ProxyServer, err
config
.
UDPIdleTimeout
.
Duration
,
config
.
UDPIdleTimeout
.
Duration
,
)
)
}
else
{
}
else
{
// This is a proxy.LoadBalancer which NewProxier needs but has methods we don't need for
// our config.EndpointsConfigHandler.
loadBalancer
:=
userspace
.
NewLoadBalancerRR
()
// set EndpointsConfigHandler to our loadBalancer
endpointsHandler
=
loadBalancer
proxierUserspace
,
err
=
userspace
.
NewProxier
(
proxierUserspace
,
err
=
userspace
.
NewProxier
(
loadBalancer
,
loadBalancer
,
net
.
ParseIP
(
config
.
BindAddress
),
net
.
ParseIP
(
config
.
BindAddress
),
...
...
pkg/proxy/types.go
View file @
48647fb9
...
@@ -47,3 +47,15 @@ type ServicePortName struct {
...
@@ -47,3 +47,15 @@ type ServicePortName struct {
func
(
spn
ServicePortName
)
String
()
string
{
func
(
spn
ServicePortName
)
String
()
string
{
return
fmt
.
Sprintf
(
"%s:%s"
,
spn
.
NamespacedName
.
String
(),
spn
.
Port
)
return
fmt
.
Sprintf
(
"%s:%s"
,
spn
.
NamespacedName
.
String
(),
spn
.
Port
)
}
}
// ServicePortPortalName carries a namespace + name + portname + portalip. This is the unique
// identfier for a load-balanced service.
type
ServicePortPortalName
struct
{
types
.
NamespacedName
Port
string
PortalIPName
string
}
func
(
spn
ServicePortPortalName
)
String
()
string
{
return
fmt
.
Sprintf
(
"%s:%s:%s"
,
spn
.
NamespacedName
.
String
(),
spn
.
Port
,
spn
.
PortalIPName
)
}
pkg/proxy/winuserspace/proxier.go
View file @
48647fb9
This diff is collapsed.
Click to expand it.
pkg/proxy/winuserspace/proxysocket.go
View file @
48647fb9
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"time"
"time"
"github.com/golang/glog"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/proxy"
"k8s.io/kubernetes/pkg/proxy"
...
@@ -40,7 +41,7 @@ type proxySocket interface {
...
@@ -40,7 +41,7 @@ type proxySocket interface {
// while sessions are active.
// while sessions are active.
Close
()
error
Close
()
error
// ProxyLoop proxies incoming connections for the specified service to the service endpoints.
// ProxyLoop proxies incoming connections for the specified service to the service endpoints.
ProxyLoop
(
service
proxy
.
ServicePortName
,
info
*
serviceInfo
,
proxier
*
Proxier
)
ProxyLoop
(
service
proxy
.
ServicePort
Portal
Name
,
info
*
serviceInfo
,
proxier
*
Proxier
)
// ListenPort returns the host port that the proxySocket is listening on
// ListenPort returns the host port that the proxySocket is listening on
ListenPort
()
int
ListenPort
()
int
}
}
...
@@ -86,10 +87,11 @@ func (tcp *tcpProxySocket) ListenPort() int {
...
@@ -86,10 +87,11 @@ func (tcp *tcpProxySocket) ListenPort() int {
return
tcp
.
port
return
tcp
.
port
}
}
func
tryConnect
(
service
proxy
.
ServicePortName
,
srcAddr
net
.
Addr
,
protocol
string
,
proxier
*
Proxier
)
(
out
net
.
Conn
,
err
error
)
{
func
tryConnect
(
service
proxy
.
ServicePort
Portal
Name
,
srcAddr
net
.
Addr
,
protocol
string
,
proxier
*
Proxier
)
(
out
net
.
Conn
,
err
error
)
{
sessionAffinityReset
:=
false
sessionAffinityReset
:=
false
for
_
,
dialTimeout
:=
range
endpointDialTimeout
{
for
_
,
dialTimeout
:=
range
endpointDialTimeout
{
endpoint
,
err
:=
proxier
.
loadBalancer
.
NextEndpoint
(
service
,
srcAddr
,
sessionAffinityReset
)
servicePortName
:=
proxy
.
ServicePortName
{
NamespacedName
:
types
.
NamespacedName
{
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
},
Port
:
service
.
Port
}
endpoint
,
err
:=
proxier
.
loadBalancer
.
NextEndpoint
(
servicePortName
,
srcAddr
,
sessionAffinityReset
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Couldn't find an endpoint for %s: %v"
,
service
,
err
)
glog
.
Errorf
(
"Couldn't find an endpoint for %s: %v"
,
service
,
err
)
return
nil
,
err
return
nil
,
err
...
@@ -111,7 +113,7 @@ func tryConnect(service proxy.ServicePortName, srcAddr net.Addr, protocol string
...
@@ -111,7 +113,7 @@ func tryConnect(service proxy.ServicePortName, srcAddr net.Addr, protocol string
return
nil
,
fmt
.
Errorf
(
"failed to connect to an endpoint."
)
return
nil
,
fmt
.
Errorf
(
"failed to connect to an endpoint."
)
}
}
func
(
tcp
*
tcpProxySocket
)
ProxyLoop
(
service
proxy
.
ServicePortName
,
myInfo
*
serviceInfo
,
proxier
*
Proxier
)
{
func
(
tcp
*
tcpProxySocket
)
ProxyLoop
(
service
proxy
.
ServicePort
Portal
Name
,
myInfo
*
serviceInfo
,
proxier
*
Proxier
)
{
for
{
for
{
if
!
myInfo
.
isAlive
()
{
if
!
myInfo
.
isAlive
()
{
// The service port was closed or replaced.
// The service port was closed or replaced.
...
@@ -197,7 +199,7 @@ func newClientCache() *clientCache {
...
@@ -197,7 +199,7 @@ func newClientCache() *clientCache {
return
&
clientCache
{
clients
:
map
[
string
]
net
.
Conn
{}}
return
&
clientCache
{
clients
:
map
[
string
]
net
.
Conn
{}}
}
}
func
(
udp
*
udpProxySocket
)
ProxyLoop
(
service
proxy
.
ServicePortName
,
myInfo
*
serviceInfo
,
proxier
*
Proxier
)
{
func
(
udp
*
udpProxySocket
)
ProxyLoop
(
service
proxy
.
ServicePort
Portal
Name
,
myInfo
*
serviceInfo
,
proxier
*
Proxier
)
{
var
buffer
[
4096
]
byte
// 4KiB should be enough for most whole-packets
var
buffer
[
4096
]
byte
// 4KiB should be enough for most whole-packets
for
{
for
{
if
!
myInfo
.
isAlive
()
{
if
!
myInfo
.
isAlive
()
{
...
@@ -241,7 +243,7 @@ func (udp *udpProxySocket) ProxyLoop(service proxy.ServicePortName, myInfo *serv
...
@@ -241,7 +243,7 @@ func (udp *udpProxySocket) ProxyLoop(service proxy.ServicePortName, myInfo *serv
}
}
}
}
func
(
udp
*
udpProxySocket
)
getBackendConn
(
activeClients
*
clientCache
,
cliAddr
net
.
Addr
,
proxier
*
Proxier
,
service
proxy
.
ServicePortName
,
timeout
time
.
Duration
)
(
net
.
Conn
,
error
)
{
func
(
udp
*
udpProxySocket
)
getBackendConn
(
activeClients
*
clientCache
,
cliAddr
net
.
Addr
,
proxier
*
Proxier
,
service
proxy
.
ServicePort
Portal
Name
,
timeout
time
.
Duration
)
(
net
.
Conn
,
error
)
{
activeClients
.
mu
.
Lock
()
activeClients
.
mu
.
Lock
()
defer
activeClients
.
mu
.
Unlock
()
defer
activeClients
.
mu
.
Unlock
()
...
...
pkg/util/netsh/netsh.go
View file @
48647fb9
...
@@ -167,12 +167,12 @@ func (runner *runner) DeleteIPAddress(args []string) error {
...
@@ -167,12 +167,12 @@ func (runner *runner) DeleteIPAddress(args []string) error {
// GetInterfaceToAddIP returns the interface name where Service IP needs to be added
// GetInterfaceToAddIP returns the interface name where Service IP needs to be added
// IP Address needs to be added for netsh portproxy to redirect traffic
// IP Address needs to be added for netsh portproxy to redirect traffic
// Reads Environment variable INTERFACE_TO_ADD_SERVICE_IP, if it is not defined then "vEthernet (
HNS Internal NIC
)" is returned
// Reads Environment variable INTERFACE_TO_ADD_SERVICE_IP, if it is not defined then "vEthernet (
forwarder
)" is returned
func
(
runner
*
runner
)
GetInterfaceToAddIP
()
string
{
func
(
runner
*
runner
)
GetInterfaceToAddIP
()
string
{
if
iface
:=
os
.
Getenv
(
"INTERFACE_TO_ADD_SERVICE_IP"
);
len
(
iface
)
>
0
{
if
iface
:=
os
.
Getenv
(
"INTERFACE_TO_ADD_SERVICE_IP"
);
len
(
iface
)
>
0
{
return
iface
return
iface
}
}
return
"vEthernet (
HNS Internal NIC
)"
return
"vEthernet (
forwarder
)"
}
}
// Restore is part of Interface.
// Restore is part of Interface.
...
...
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