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
55e6eb2c
Commit
55e6eb2c
authored
May 02, 2016
by
Dan Williams
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow using netns path instead of container PID to change hairpin mode
parent
952e8302
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
12 deletions
+24
-12
manager.go
pkg/kubelet/dockertools/manager.go
+1
-1
hairpin.go
pkg/kubelet/network/hairpin/hairpin.go
+21
-10
hairpin_test.go
pkg/kubelet/network/hairpin/hairpin_test.go
+2
-1
No files found.
pkg/kubelet/dockertools/manager.go
View file @
55e6eb2c
...
@@ -1957,7 +1957,7 @@ func (dm *DockerManager) SyncPod(pod *api.Pod, _ api.PodStatus, podStatus *kubec
...
@@ -1957,7 +1957,7 @@ func (dm *DockerManager) SyncPod(pod *api.Pod, _ api.PodStatus, podStatus *kubec
}
}
if
dm
.
configureHairpinMode
{
if
dm
.
configureHairpinMode
{
if
err
=
hairpin
.
SetUpContainer
(
podInfraContainer
.
State
.
Pid
,
network
.
DefaultInterfaceName
);
err
!=
nil
{
if
err
=
hairpin
.
SetUpContainer
Pid
(
podInfraContainer
.
State
.
Pid
,
network
.
DefaultInterfaceName
);
err
!=
nil
{
glog
.
Warningf
(
"Hairpin setup failed for pod %q: %v"
,
format
.
Pod
(
pod
),
err
)
glog
.
Warningf
(
"Hairpin setup failed for pod %q: %v"
,
format
.
Pod
(
pod
),
err
)
}
}
}
}
...
...
pkg/kubelet/network/hairpin/hairpin.go
View file @
55e6eb2c
...
@@ -40,13 +40,23 @@ var (
...
@@ -40,13 +40,23 @@ var (
ethtoolOutputRegex
=
regexp
.
MustCompile
(
"peer_ifindex: (
\\
d+)"
)
ethtoolOutputRegex
=
regexp
.
MustCompile
(
"peer_ifindex: (
\\
d+)"
)
)
)
func
SetUpContainer
(
containerPid
int
,
containerInterfaceName
string
)
error
{
func
SetUpContainerPid
(
containerPid
int
,
containerInterfaceName
string
)
error
{
e
:=
exec
.
New
()
pidStr
:=
fmt
.
Sprintf
(
"%d"
,
containerPid
)
return
setUpContainerInternal
(
e
,
containerPid
,
containerInterfaceName
)
nsenterArgs
:=
[]
string
{
"-t"
,
pidStr
,
"-n"
}
return
setUpContainerInternal
(
containerInterfaceName
,
pidStr
,
nsenterArgs
)
}
func
SetUpContainerPath
(
netnsPath
string
,
containerInterfaceName
string
)
error
{
if
netnsPath
[
0
]
!=
'/'
{
return
fmt
.
Errorf
(
"netnsPath path '%s' was invalid"
,
netnsPath
)
}
nsenterArgs
:=
[]
string
{
"-n"
,
netnsPath
}
return
setUpContainerInternal
(
containerInterfaceName
,
netnsPath
,
nsenterArgs
)
}
}
func
setUpContainerInternal
(
e
exec
.
Interface
,
containerPid
int
,
containerInterfaceName
string
)
error
{
func
setUpContainerInternal
(
containerInterfaceName
,
containerDesc
string
,
nsenterArgs
[]
string
)
error
{
hostIfName
,
err
:=
findPairInterfaceOfContainerInterface
(
e
,
containerPid
,
containerInterfaceName
)
e
:=
exec
.
New
()
hostIfName
,
err
:=
findPairInterfaceOfContainerInterface
(
e
,
containerInterfaceName
,
containerDesc
,
nsenterArgs
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Infof
(
"Unable to find pair interface, setting up all interfaces: %v"
,
err
)
glog
.
Infof
(
"Unable to find pair interface, setting up all interfaces: %v"
,
err
)
return
setUpAllInterfaces
()
return
setUpAllInterfaces
()
...
@@ -54,7 +64,7 @@ func setUpContainerInternal(e exec.Interface, containerPid int, containerInterfa
...
@@ -54,7 +64,7 @@ func setUpContainerInternal(e exec.Interface, containerPid int, containerInterfa
return
setUpInterface
(
hostIfName
)
return
setUpInterface
(
hostIfName
)
}
}
func
findPairInterfaceOfContainerInterface
(
e
exec
.
Interface
,
container
Pid
int
,
containerInterfaceName
string
)
(
string
,
error
)
{
func
findPairInterfaceOfContainerInterface
(
e
exec
.
Interface
,
container
InterfaceName
,
containerDesc
string
,
nsenterArgs
[]
string
)
(
string
,
error
)
{
nsenterPath
,
err
:=
e
.
LookPath
(
"nsenter"
)
nsenterPath
,
err
:=
e
.
LookPath
(
"nsenter"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
@@ -63,15 +73,16 @@ func findPairInterfaceOfContainerInterface(e exec.Interface, containerPid int, c
...
@@ -63,15 +73,16 @@ func findPairInterfaceOfContainerInterface(e exec.Interface, containerPid int, c
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
// Get container's interface index
output
,
err
:=
e
.
Command
(
nsenterPath
,
"-t"
,
fmt
.
Sprintf
(
"%d"
,
containerPid
),
"-n"
,
"-F"
,
"--"
,
ethtoolPath
,
"--statistics"
,
containerInterfaceName
)
.
CombinedOutput
()
nsenterArgs
=
append
(
nsenterArgs
,
"-F"
,
"--"
,
ethtoolPath
,
"--statistics"
,
containerInterfaceName
)
output
,
err
:=
e
.
Command
(
nsenterPath
,
nsenterArgs
...
)
.
CombinedOutput
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Unable to query interface %s of container %
d: %v: %s"
,
containerInterfaceName
,
containerPid
,
err
,
string
(
output
))
return
""
,
fmt
.
Errorf
(
"Unable to query interface %s of container %
s: %v: %s"
,
containerInterfaceName
,
containerDesc
,
err
,
string
(
output
))
}
}
// look for peer_ifindex
// look for peer_ifindex
match
:=
ethtoolOutputRegex
.
FindSubmatch
(
output
)
match
:=
ethtoolOutputRegex
.
FindSubmatch
(
output
)
if
match
==
nil
{
if
match
==
nil
{
return
""
,
fmt
.
Errorf
(
"No peer_ifindex in interface statistics for %s of container %
d"
,
containerInterfaceName
,
containerPid
)
return
""
,
fmt
.
Errorf
(
"No peer_ifindex in interface statistics for %s of container %
s"
,
containerInterfaceName
,
containerDesc
)
}
}
peerIfIndex
,
err
:=
strconv
.
Atoi
(
string
(
match
[
1
]))
peerIfIndex
,
err
:=
strconv
.
Atoi
(
string
(
match
[
1
]))
if
err
!=
nil
{
// seems impossible (\d+ not numeric)
if
err
!=
nil
{
// seems impossible (\d+ not numeric)
...
...
pkg/kubelet/network/hairpin/hairpin_test.go
View file @
55e6eb2c
...
@@ -69,7 +69,8 @@ func TestFindPairInterfaceOfContainerInterface(t *testing.T) {
...
@@ -69,7 +69,8 @@ func TestFindPairInterfaceOfContainerInterface(t *testing.T) {
return
fmt
.
Sprintf
(
"/fake-bin/%s"
,
file
),
nil
return
fmt
.
Sprintf
(
"/fake-bin/%s"
,
file
),
nil
},
},
}
}
name
,
err
:=
findPairInterfaceOfContainerInterface
(
&
fexec
,
123
,
"eth0"
)
nsenterArgs
:=
[]
string
{
"-t"
,
"123"
,
"-n"
}
name
,
err
:=
findPairInterfaceOfContainerInterface
(
&
fexec
,
"eth0"
,
"123"
,
nsenterArgs
)
if
test
.
expectErr
{
if
test
.
expectErr
{
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"unexpected non-error"
)
t
.
Errorf
(
"unexpected non-error"
)
...
...
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