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
e54ebe5e
Commit
e54ebe5e
authored
Jun 09, 2016
by
k8s-merge-robot
Committed by
GitHub
Jun 09, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #27132 from freehan/kubenetmasq
Automatic merge from submit-queue turn off cni masqurade and manage it in kubenet fixes #27110
parents
64b49677
1276a916
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
63 additions
and
34 deletions
+63
-34
docker_test.go
pkg/kubelet/dockertools/docker_test.go
+1
-1
manager_test.go
pkg/kubelet/dockertools/manager_test.go
+1
-1
kubelet.go
pkg/kubelet/kubelet.go
+1
-1
kubelet_test.go
pkg/kubelet/kubelet_test.go
+1
-1
cni.go
pkg/kubelet/network/cni/cni.go
+1
-1
cni_test.go
pkg/kubelet/network/cni/cni_test.go
+2
-2
exec.go
pkg/kubelet/network/exec/exec.go
+1
-1
exec_test.go
pkg/kubelet/network/exec/exec_test.go
+8
-8
kubenet_linux.go
pkg/kubelet/network/kubenet/kubenet_linux.go
+38
-9
kubenet_unsupported.go
pkg/kubelet/network/kubenet/kubenet_unsupported.go
+1
-1
network_plugins.go
pkg/kubelet/network/mock_network/network_plugins.go
+1
-1
plugins.go
pkg/kubelet/network/plugins.go
+5
-5
plugins_test.go
pkg/kubelet/network/plugins_test.go
+1
-1
runonce_test.go
pkg/kubelet/runonce_test.go
+1
-1
No files found.
pkg/kubelet/dockertools/docker_test.go
View file @
e54ebe5e
...
@@ -651,7 +651,7 @@ func TestFindContainersByPod(t *testing.T) {
...
@@ -651,7 +651,7 @@ func TestFindContainersByPod(t *testing.T) {
},
},
}
}
fakeClient
:=
NewFakeDockerClient
()
fakeClient
:=
NewFakeDockerClient
()
np
,
_
:=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
np
,
_
:=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
// image back-off is set to nil, this test should not pull images
// image back-off is set to nil, this test should not pull images
containerManager
:=
NewFakeDockerManager
(
fakeClient
,
&
record
.
FakeRecorder
{},
nil
,
nil
,
&
cadvisorapi
.
MachineInfo
{},
options
.
GetDefaultPodInfraContainerImage
(),
0
,
0
,
""
,
&
containertest
.
FakeOS
{},
np
,
nil
,
nil
,
nil
)
containerManager
:=
NewFakeDockerManager
(
fakeClient
,
&
record
.
FakeRecorder
{},
nil
,
nil
,
&
cadvisorapi
.
MachineInfo
{},
options
.
GetDefaultPodInfraContainerImage
(),
0
,
0
,
""
,
&
containertest
.
FakeOS
{},
np
,
nil
,
nil
,
nil
)
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
...
...
pkg/kubelet/dockertools/manager_test.go
View file @
e54ebe5e
...
@@ -107,7 +107,7 @@ func createTestDockerManager(fakeHTTPClient *fakeHTTP, fakeDocker *FakeDockerCli
...
@@ -107,7 +107,7 @@ func createTestDockerManager(fakeHTTPClient *fakeHTTP, fakeDocker *FakeDockerCli
}
}
fakeRecorder
:=
&
record
.
FakeRecorder
{}
fakeRecorder
:=
&
record
.
FakeRecorder
{}
containerRefManager
:=
kubecontainer
.
NewRefManager
()
containerRefManager
:=
kubecontainer
.
NewRefManager
()
networkPlugin
,
_
:=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
networkPlugin
,
_
:=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
dockerManager
:=
NewFakeDockerManager
(
dockerManager
:=
NewFakeDockerManager
(
fakeDocker
,
fakeDocker
,
fakeRecorder
,
fakeRecorder
,
...
...
pkg/kubelet/kubelet.go
View file @
e54ebe5e
...
@@ -385,7 +385,7 @@ func NewMainKubelet(
...
@@ -385,7 +385,7 @@ func NewMainKubelet(
}
}
glog
.
Infof
(
"Hairpin mode set to %q"
,
klet
.
hairpinMode
)
glog
.
Infof
(
"Hairpin mode set to %q"
,
klet
.
hairpinMode
)
if
plug
,
err
:=
network
.
InitNetworkPlugin
(
networkPlugins
,
networkPluginName
,
&
networkHost
{
klet
},
klet
.
hairpinMode
);
err
!=
nil
{
if
plug
,
err
:=
network
.
InitNetworkPlugin
(
networkPlugins
,
networkPluginName
,
&
networkHost
{
klet
},
klet
.
hairpinMode
,
klet
.
nonMasqueradeCIDR
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
else
{
}
else
{
klet
.
networkPlugin
=
plug
klet
.
networkPlugin
=
plug
...
...
pkg/kubelet/kubelet_test.go
View file @
e54ebe5e
...
@@ -188,7 +188,7 @@ func newTestKubeletWithImageList(t *testing.T, imageList []kubecontainer.Image)
...
@@ -188,7 +188,7 @@ func newTestKubeletWithImageList(t *testing.T, imageList []kubecontainer.Image)
kubelet
.
nodeName
=
testKubeletHostname
kubelet
.
nodeName
=
testKubeletHostname
kubelet
.
runtimeState
=
newRuntimeState
(
maxWaitForContainerRuntime
)
kubelet
.
runtimeState
=
newRuntimeState
(
maxWaitForContainerRuntime
)
kubelet
.
runtimeState
.
setNetworkState
(
nil
)
kubelet
.
runtimeState
.
setNetworkState
(
nil
)
kubelet
.
networkPlugin
,
_
=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
kubelet
.
networkPlugin
,
_
=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
kubelet
.
nonMasqueradeCIDR
)
if
tempDir
,
err
:=
ioutil
.
TempDir
(
"/tmp"
,
"kubelet_test."
);
err
!=
nil
{
if
tempDir
,
err
:=
ioutil
.
TempDir
(
"/tmp"
,
"kubelet_test."
);
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp rootdir: %v"
,
err
)
t
.
Fatalf
(
"can't make a temp rootdir: %v"
,
err
)
}
else
{
}
else
{
...
...
pkg/kubelet/network/cni/cni.go
View file @
e54ebe5e
...
@@ -94,7 +94,7 @@ func getDefaultCNINetwork(pluginDir, vendorCNIDirPrefix string) (*cniNetwork, er
...
@@ -94,7 +94,7 @@ func getDefaultCNINetwork(pluginDir, vendorCNIDirPrefix string) (*cniNetwork, er
return
nil
,
fmt
.
Errorf
(
"No valid networks found in %s"
,
pluginDir
)
return
nil
,
fmt
.
Errorf
(
"No valid networks found in %s"
,
pluginDir
)
}
}
func
(
plugin
*
cniNetworkPlugin
)
Init
(
host
network
.
Host
,
hairpinMode
componentconfig
.
HairpinMode
)
error
{
func
(
plugin
*
cniNetworkPlugin
)
Init
(
host
network
.
Host
,
hairpinMode
componentconfig
.
HairpinMode
,
nonMasqueradeCIDR
string
)
error
{
plugin
.
host
=
host
plugin
.
host
=
host
return
nil
return
nil
}
}
...
...
pkg/kubelet/network/cni/cni_test.go
View file @
e54ebe5e
...
@@ -145,7 +145,7 @@ func newTestDockerManager() (*dockertools.DockerManager, *dockertools.FakeDocker
...
@@ -145,7 +145,7 @@ func newTestDockerManager() (*dockertools.DockerManager, *dockertools.FakeDocker
fakeDocker
:=
dockertools
.
NewFakeDockerClient
()
fakeDocker
:=
dockertools
.
NewFakeDockerClient
()
fakeRecorder
:=
&
record
.
FakeRecorder
{}
fakeRecorder
:=
&
record
.
FakeRecorder
{}
containerRefManager
:=
kubecontainer
.
NewRefManager
()
containerRefManager
:=
kubecontainer
.
NewRefManager
()
networkPlugin
,
_
:=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
networkPlugin
,
_
:=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
dockerManager
:=
dockertools
.
NewFakeDockerManager
(
dockerManager
:=
dockertools
.
NewFakeDockerManager
(
fakeDocker
,
fakeDocker
,
fakeRecorder
,
fakeRecorder
,
...
@@ -175,7 +175,7 @@ func TestCNIPlugin(t *testing.T) {
...
@@ -175,7 +175,7 @@ func TestCNIPlugin(t *testing.T) {
installPluginUnderTest
(
t
,
testVendorCNIDirPrefix
,
testNetworkConfigPath
,
vendorName
,
pluginName
)
installPluginUnderTest
(
t
,
testVendorCNIDirPrefix
,
testNetworkConfigPath
,
vendorName
,
pluginName
)
np
:=
probeNetworkPluginsWithVendorCNIDirPrefix
(
path
.
Join
(
testNetworkConfigPath
,
pluginName
),
testVendorCNIDirPrefix
)
np
:=
probeNetworkPluginsWithVendorCNIDirPrefix
(
path
.
Join
(
testNetworkConfigPath
,
pluginName
),
testVendorCNIDirPrefix
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
np
,
"cni"
,
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
np
,
"cni"
,
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to select the desired plugin: %v"
,
err
)
t
.
Fatalf
(
"Failed to select the desired plugin: %v"
,
err
)
}
}
...
...
pkg/kubelet/network/exec/exec.go
View file @
e54ebe5e
...
@@ -105,7 +105,7 @@ func ProbeNetworkPlugins(pluginDir string) []network.NetworkPlugin {
...
@@ -105,7 +105,7 @@ func ProbeNetworkPlugins(pluginDir string) []network.NetworkPlugin {
return
execPlugins
return
execPlugins
}
}
func
(
plugin
*
execNetworkPlugin
)
Init
(
host
network
.
Host
,
hairpinMode
componentconfig
.
HairpinMode
)
error
{
func
(
plugin
*
execNetworkPlugin
)
Init
(
host
network
.
Host
,
hairpinMode
componentconfig
.
HairpinMode
,
nonMasqueradeCIDR
string
)
error
{
err
:=
plugin
.
validate
()
err
:=
plugin
.
validate
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/kubelet/network/exec/exec_test.go
View file @
e54ebe5e
...
@@ -135,7 +135,7 @@ func TestSelectPlugin(t *testing.T) {
...
@@ -135,7 +135,7 @@ func TestSelectPlugin(t *testing.T) {
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to select the desired plugin: %v"
,
err
)
t
.
Errorf
(
"Failed to select the desired plugin: %v"
,
err
)
}
}
...
@@ -157,7 +157,7 @@ func TestSelectVendoredPlugin(t *testing.T) {
...
@@ -157,7 +157,7 @@ func TestSelectVendoredPlugin(t *testing.T) {
installPluginUnderTest
(
t
,
vendor
,
testPluginPath
,
pluginName
,
nil
)
installPluginUnderTest
(
t
,
vendor
,
testPluginPath
,
pluginName
,
nil
)
vendoredPluginName
:=
fmt
.
Sprintf
(
"%s/%s"
,
vendor
,
pluginName
)
vendoredPluginName
:=
fmt
.
Sprintf
(
"%s/%s"
,
vendor
,
pluginName
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
vendoredPluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
vendoredPluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to select the desired plugin: %v"
,
err
)
t
.
Errorf
(
"Failed to select the desired plugin: %v"
,
err
)
}
}
...
@@ -178,7 +178,7 @@ func TestSelectWrongPlugin(t *testing.T) {
...
@@ -178,7 +178,7 @@ func TestSelectWrongPlugin(t *testing.T) {
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
wrongPlugin
:=
"abcd"
wrongPlugin
:=
"abcd"
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
wrongPlugin
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
wrongPlugin
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
if
plug
!=
nil
||
err
==
nil
{
if
plug
!=
nil
||
err
==
nil
{
t
.
Errorf
(
"Expected to see an error. Wrong plugin selected."
)
t
.
Errorf
(
"Expected to see an error. Wrong plugin selected."
)
}
}
...
@@ -206,7 +206,7 @@ func TestPluginValidation(t *testing.T) {
...
@@ -206,7 +206,7 @@ func TestPluginValidation(t *testing.T) {
}
}
f
.
Close
()
f
.
Close
()
_
,
err
=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
_
,
err
=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
if
err
==
nil
{
if
err
==
nil
{
// we expected an error here because validation would have failed
// we expected an error here because validation would have failed
t
.
Errorf
(
"Expected non-nil value."
)
t
.
Errorf
(
"Expected non-nil value."
)
...
@@ -224,7 +224,7 @@ func TestPluginSetupHook(t *testing.T) {
...
@@ -224,7 +224,7 @@ func TestPluginSetupHook(t *testing.T) {
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
err
=
plug
.
SetUpPod
(
"podNamespace"
,
"podName"
,
kubecontainer
.
ContainerID
{
Type
:
"docker"
,
ID
:
"dockerid2345"
})
err
=
plug
.
SetUpPod
(
"podNamespace"
,
"podName"
,
kubecontainer
.
ContainerID
{
Type
:
"docker"
,
ID
:
"dockerid2345"
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -252,7 +252,7 @@ func TestPluginTearDownHook(t *testing.T) {
...
@@ -252,7 +252,7 @@ func TestPluginTearDownHook(t *testing.T) {
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
err
=
plug
.
TearDownPod
(
"podNamespace"
,
"podName"
,
kubecontainer
.
ContainerID
{
Type
:
"docker"
,
ID
:
"dockerid2345"
})
err
=
plug
.
TearDownPod
(
"podNamespace"
,
"podName"
,
kubecontainer
.
ContainerID
{
Type
:
"docker"
,
ID
:
"dockerid2345"
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -280,7 +280,7 @@ func TestPluginStatusHook(t *testing.T) {
...
@@ -280,7 +280,7 @@ func TestPluginStatusHook(t *testing.T) {
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
ip
,
err
:=
plug
.
GetPodNetworkStatus
(
"namespace"
,
"name"
,
kubecontainer
.
ContainerID
{
Type
:
"docker"
,
ID
:
"dockerid2345"
})
ip
,
err
:=
plug
.
GetPodNetworkStatus
(
"namespace"
,
"name"
,
kubecontainer
.
ContainerID
{
Type
:
"docker"
,
ID
:
"dockerid2345"
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -316,7 +316,7 @@ func TestPluginStatusHookIPv6(t *testing.T) {
...
@@ -316,7 +316,7 @@ func TestPluginStatusHookIPv6(t *testing.T) {
}
}
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
execTemplate
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
execTemplate
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"InitNetworkPlugin() failed: %v"
,
err
)
t
.
Errorf
(
"InitNetworkPlugin() failed: %v"
,
err
)
}
}
...
...
pkg/kubelet/network/kubenet/kubenet_linux.go
View file @
e54ebe5e
...
@@ -79,7 +79,8 @@ type kubenetNetworkPlugin struct {
...
@@ -79,7 +79,8 @@ type kubenetNetworkPlugin struct {
iptables
utiliptables
.
Interface
iptables
utiliptables
.
Interface
// vendorDir is passed by kubelet network-plugin-dir parameter.
// vendorDir is passed by kubelet network-plugin-dir parameter.
// kubenet will search for cni binaries in DefaultCNIDir first, then continue to vendorDir.
// kubenet will search for cni binaries in DefaultCNIDir first, then continue to vendorDir.
vendorDir
string
vendorDir
string
nonMasqueradeCIDR
string
}
}
func
NewPlugin
(
networkPluginDir
string
)
network
.
NetworkPlugin
{
func
NewPlugin
(
networkPluginDir
string
)
network
.
NetworkPlugin
{
...
@@ -88,16 +89,17 @@ func NewPlugin(networkPluginDir string) network.NetworkPlugin {
...
@@ -88,16 +89,17 @@ func NewPlugin(networkPluginDir string) network.NetworkPlugin {
dbus
:=
utildbus
.
New
()
dbus
:=
utildbus
.
New
()
iptInterface
:=
utiliptables
.
New
(
execer
,
dbus
,
protocol
)
iptInterface
:=
utiliptables
.
New
(
execer
,
dbus
,
protocol
)
return
&
kubenetNetworkPlugin
{
return
&
kubenetNetworkPlugin
{
podIPs
:
make
(
map
[
kubecontainer
.
ContainerID
]
string
),
podIPs
:
make
(
map
[
kubecontainer
.
ContainerID
]
string
),
hostPortMap
:
make
(
map
[
hostport
]
closeable
),
hostPortMap
:
make
(
map
[
hostport
]
closeable
),
MTU
:
1460
,
//TODO: don't hardcode this
MTU
:
1460
,
//TODO: don't hardcode this
execer
:
utilexec
.
New
(),
execer
:
utilexec
.
New
(),
iptables
:
iptInterface
,
iptables
:
iptInterface
,
vendorDir
:
networkPluginDir
,
vendorDir
:
networkPluginDir
,
nonMasqueradeCIDR
:
"10.0.0.0/8"
,
}
}
}
}
func
(
plugin
*
kubenetNetworkPlugin
)
Init
(
host
network
.
Host
,
hairpinMode
componentconfig
.
HairpinMode
)
error
{
func
(
plugin
*
kubenetNetworkPlugin
)
Init
(
host
network
.
Host
,
hairpinMode
componentconfig
.
HairpinMode
,
nonMasqueradeCIDR
string
)
error
{
plugin
.
host
=
host
plugin
.
host
=
host
plugin
.
hairpinMode
=
hairpinMode
plugin
.
hairpinMode
=
hairpinMode
plugin
.
cniConfig
=
&
libcni
.
CNIConfig
{
plugin
.
cniConfig
=
&
libcni
.
CNIConfig
{
...
@@ -132,6 +134,23 @@ func (plugin *kubenetNetworkPlugin) Init(host network.Host, hairpinMode componen
...
@@ -132,6 +134,23 @@ func (plugin *kubenetNetworkPlugin) Init(host network.Host, hairpinMode componen
return
fmt
.
Errorf
(
"Failed to generate loopback config: %v"
,
err
)
return
fmt
.
Errorf
(
"Failed to generate loopback config: %v"
,
err
)
}
}
plugin
.
nonMasqueradeCIDR
=
nonMasqueradeCIDR
// Need to SNAT outbound traffic from cluster
if
err
=
plugin
.
ensureMasqRule
();
err
!=
nil
{
return
err
}
return
nil
}
// TODO: move thic logic into cni bridge plugin and remove this from kubenet
func
(
plugin
*
kubenetNetworkPlugin
)
ensureMasqRule
()
error
{
if
_
,
err
:=
plugin
.
iptables
.
EnsureRule
(
utiliptables
.
Append
,
utiliptables
.
TableNAT
,
utiliptables
.
ChainPostrouting
,
"-m"
,
"comment"
,
"--comment"
,
"kubenet: SNAT for outbound traffic from cluster"
,
"-m"
,
"addrtype"
,
"!"
,
"--dst-type"
,
"LOCAL"
,
"!"
,
"-d"
,
plugin
.
nonMasqueradeCIDR
,
"-j"
,
"MASQUERADE"
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to ensure that %s chain %s jumps to MASQUERADE: %v"
,
utiliptables
.
TableNAT
,
utiliptables
.
ChainPostrouting
,
err
)
}
return
nil
return
nil
}
}
...
@@ -167,7 +186,7 @@ const NET_CONFIG_TEMPLATE = `{
...
@@ -167,7 +186,7 @@ const NET_CONFIG_TEMPLATE = `{
"mtu": %d,
"mtu": %d,
"addIf": "%s",
"addIf": "%s",
"isGateway": true,
"isGateway": true,
"ipMasq":
tru
e,
"ipMasq":
fals
e,
"ipam": {
"ipam": {
"type": "host-local",
"type": "host-local",
"subnet": "%s",
"subnet": "%s",
...
@@ -354,6 +373,11 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k
...
@@ -354,6 +373,11 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k
}
}
plugin
.
syncHostportsRules
()
plugin
.
syncHostportsRules
()
// Need to SNAT outbound traffic from cluster
if
err
=
plugin
.
ensureMasqRule
();
err
!=
nil
{
glog
.
Errorf
(
"Failed to ensure MASQ rule: %v"
,
err
)
}
return
nil
return
nil
}
}
...
@@ -391,6 +415,11 @@ func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, i
...
@@ -391,6 +415,11 @@ func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, i
delete
(
plugin
.
podIPs
,
id
)
delete
(
plugin
.
podIPs
,
id
)
plugin
.
syncHostportsRules
()
plugin
.
syncHostportsRules
()
// Need to SNAT outbound traffic from cluster
if
err
:=
plugin
.
ensureMasqRule
();
err
!=
nil
{
glog
.
Errorf
(
"Failed to ensure MASQ rule: %v"
,
err
)
}
return
nil
return
nil
}
}
...
...
pkg/kubelet/network/kubenet/kubenet_unsupported.go
View file @
e54ebe5e
...
@@ -34,7 +34,7 @@ func NewPlugin(networkPluginDir string) network.NetworkPlugin {
...
@@ -34,7 +34,7 @@ func NewPlugin(networkPluginDir string) network.NetworkPlugin {
return
&
kubenetNetworkPlugin
{}
return
&
kubenetNetworkPlugin
{}
}
}
func
(
plugin
*
kubenetNetworkPlugin
)
Init
(
host
network
.
Host
,
hairpinMode
componentconfig
.
HairpinMode
)
error
{
func
(
plugin
*
kubenetNetworkPlugin
)
Init
(
host
network
.
Host
,
hairpinMode
componentconfig
.
HairpinMode
,
nonMasqueradeCIDR
string
)
error
{
return
fmt
.
Errorf
(
"Kubenet is not supported in this build"
)
return
fmt
.
Errorf
(
"Kubenet is not supported in this build"
)
}
}
...
...
pkg/kubelet/network/mock_network/network_plugins.go
View file @
e54ebe5e
...
@@ -78,7 +78,7 @@ func (_mr *_MockNetworkPluginRecorder) GetPodNetworkStatus(arg0, arg1, arg2 inte
...
@@ -78,7 +78,7 @@ func (_mr *_MockNetworkPluginRecorder) GetPodNetworkStatus(arg0, arg1, arg2 inte
return
_mr
.
mock
.
ctrl
.
RecordCall
(
_mr
.
mock
,
"GetPodNetworkStatus"
,
arg0
,
arg1
,
arg2
)
return
_mr
.
mock
.
ctrl
.
RecordCall
(
_mr
.
mock
,
"GetPodNetworkStatus"
,
arg0
,
arg1
,
arg2
)
}
}
func
(
_m
*
MockNetworkPlugin
)
Init
(
_param0
network
.
Host
,
_param1
componentconfig
.
HairpinMode
)
error
{
func
(
_m
*
MockNetworkPlugin
)
Init
(
_param0
network
.
Host
,
_param1
componentconfig
.
HairpinMode
,
nonMasqueradeCIDR
string
)
error
{
ret
:=
_m
.
ctrl
.
Call
(
_m
,
"Init"
,
_param0
,
_param1
)
ret
:=
_m
.
ctrl
.
Call
(
_m
,
"Init"
,
_param0
,
_param1
)
ret0
,
_
:=
ret
[
0
]
.
(
error
)
ret0
,
_
:=
ret
[
0
]
.
(
error
)
return
ret0
return
ret0
...
...
pkg/kubelet/network/plugins.go
View file @
e54ebe5e
...
@@ -52,7 +52,7 @@ const (
...
@@ -52,7 +52,7 @@ const (
type
NetworkPlugin
interface
{
type
NetworkPlugin
interface
{
// Init initializes the plugin. This will be called exactly once
// Init initializes the plugin. This will be called exactly once
// before any other methods are called.
// before any other methods are called.
Init
(
host
Host
,
hairpinMode
componentconfig
.
HairpinMode
)
error
Init
(
host
Host
,
hairpinMode
componentconfig
.
HairpinMode
,
nonMasqueradeCIDR
string
)
error
// Called on various events like:
// Called on various events like:
// NET_PLUGIN_EVENT_POD_CIDR_CHANGE
// NET_PLUGIN_EVENT_POD_CIDR_CHANGE
...
@@ -105,11 +105,11 @@ type Host interface {
...
@@ -105,11 +105,11 @@ type Host interface {
}
}
// InitNetworkPlugin inits the plugin that matches networkPluginName. Plugins must have unique names.
// InitNetworkPlugin inits the plugin that matches networkPluginName. Plugins must have unique names.
func
InitNetworkPlugin
(
plugins
[]
NetworkPlugin
,
networkPluginName
string
,
host
Host
,
hairpinMode
componentconfig
.
HairpinMode
)
(
NetworkPlugin
,
error
)
{
func
InitNetworkPlugin
(
plugins
[]
NetworkPlugin
,
networkPluginName
string
,
host
Host
,
hairpinMode
componentconfig
.
HairpinMode
,
nonMasqueradeCIDR
string
)
(
NetworkPlugin
,
error
)
{
if
networkPluginName
==
""
{
if
networkPluginName
==
""
{
// default to the no_op plugin
// default to the no_op plugin
plug
:=
&
NoopNetworkPlugin
{}
plug
:=
&
NoopNetworkPlugin
{}
if
err
:=
plug
.
Init
(
host
,
hairpinMode
);
err
!=
nil
{
if
err
:=
plug
.
Init
(
host
,
hairpinMode
,
nonMasqueradeCIDR
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
plug
,
nil
return
plug
,
nil
...
@@ -134,7 +134,7 @@ func InitNetworkPlugin(plugins []NetworkPlugin, networkPluginName string, host H
...
@@ -134,7 +134,7 @@ func InitNetworkPlugin(plugins []NetworkPlugin, networkPluginName string, host H
chosenPlugin
:=
pluginMap
[
networkPluginName
]
chosenPlugin
:=
pluginMap
[
networkPluginName
]
if
chosenPlugin
!=
nil
{
if
chosenPlugin
!=
nil
{
err
:=
chosenPlugin
.
Init
(
host
,
hairpinMode
)
err
:=
chosenPlugin
.
Init
(
host
,
hairpinMode
,
nonMasqueradeCIDR
)
if
err
!=
nil
{
if
err
!=
nil
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"Network plugin %q failed init: %v"
,
networkPluginName
,
err
))
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"Network plugin %q failed init: %v"
,
networkPluginName
,
err
))
}
else
{
}
else
{
...
@@ -156,7 +156,7 @@ type NoopNetworkPlugin struct {
...
@@ -156,7 +156,7 @@ type NoopNetworkPlugin struct {
const
sysctlBridgeCallIptables
=
"net/bridge/bridge-nf-call-iptables"
const
sysctlBridgeCallIptables
=
"net/bridge/bridge-nf-call-iptables"
func
(
plugin
*
NoopNetworkPlugin
)
Init
(
host
Host
,
hairpinMode
componentconfig
.
HairpinMode
)
error
{
func
(
plugin
*
NoopNetworkPlugin
)
Init
(
host
Host
,
hairpinMode
componentconfig
.
HairpinMode
,
nonMasqueradeCIDR
string
)
error
{
// Set bridge-nf-call-iptables=1 to maintain compatibility with older
// Set bridge-nf-call-iptables=1 to maintain compatibility with older
// kubernetes versions to ensure the iptables-based kube proxy functions
// kubernetes versions to ensure the iptables-based kube proxy functions
// correctly. Other plugins are responsible for setting this correctly
// correctly. Other plugins are responsible for setting this correctly
...
...
pkg/kubelet/network/plugins_test.go
View file @
e54ebe5e
...
@@ -25,7 +25,7 @@ import (
...
@@ -25,7 +25,7 @@ import (
func
TestSelectDefaultPlugin
(
t
*
testing
.
T
)
{
func
TestSelectDefaultPlugin
(
t
*
testing
.
T
)
{
all_plugins
:=
[]
NetworkPlugin
{}
all_plugins
:=
[]
NetworkPlugin
{}
plug
,
err
:=
InitNetworkPlugin
(
all_plugins
,
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
plug
,
err
:=
InitNetworkPlugin
(
all_plugins
,
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
"10.0.0.0/8"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error in selecting default plugin: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error in selecting default plugin: %v"
,
err
)
}
}
...
...
pkg/kubelet/runonce_test.go
View file @
e54ebe5e
...
@@ -84,7 +84,7 @@ func TestRunOnce(t *testing.T) {
...
@@ -84,7 +84,7 @@ func TestRunOnce(t *testing.T) {
}
}
kb
.
containerManager
=
cm
.
NewStubContainerManager
()
kb
.
containerManager
=
cm
.
NewStubContainerManager
()
kb
.
networkPlugin
,
_
=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
)
kb
.
networkPlugin
,
_
=
network
.
InitNetworkPlugin
([]
network
.
NetworkPlugin
{},
""
,
nettest
.
NewFakeHost
(
nil
),
componentconfig
.
HairpinNone
,
kb
.
nonMasqueradeCIDR
)
// TODO: Factor out "StatsProvider" from Kubelet so we don't have a cyclic dependency
// TODO: Factor out "StatsProvider" from Kubelet so we don't have a cyclic dependency
volumeStatsAggPeriod
:=
time
.
Second
*
10
volumeStatsAggPeriod
:=
time
.
Second
*
10
kb
.
resourceAnalyzer
=
stats
.
NewResourceAnalyzer
(
kb
,
volumeStatsAggPeriod
,
kb
.
containerRuntime
)
kb
.
resourceAnalyzer
=
stats
.
NewResourceAnalyzer
(
kb
,
volumeStatsAggPeriod
,
kb
.
containerRuntime
)
...
...
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