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
2480ef5f
Commit
2480ef5f
authored
Jul 28, 2016
by
k8s-merge-robot
Committed by
GitHub
Jul 28, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #28178 from mikedanese/cni-reload
Automatic merge from submit-queue periodically reload the cni plugin configuration Might fix #28787
parents
5c6c8eb9
792868c7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
14 deletions
+58
-14
cni.go
pkg/kubelet/network/cni/cni.go
+58
-14
No files found.
pkg/kubelet/network/cni/cni.go
View file @
2480ef5f
...
@@ -17,8 +17,11 @@ limitations under the License.
...
@@ -17,8 +17,11 @@ limitations under the License.
package
cni
package
cni
import
(
import
(
"errors"
"fmt"
"fmt"
"sort"
"sort"
"sync"
"time"
"github.com/appc/cni/libcni"
"github.com/appc/cni/libcni"
cnitypes
"github.com/appc/cni/pkg/types"
cnitypes
"github.com/appc/cni/pkg/types"
...
@@ -27,6 +30,7 @@ import (
...
@@ -27,6 +30,7 @@ import (
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/network"
"k8s.io/kubernetes/pkg/kubelet/network"
utilexec
"k8s.io/kubernetes/pkg/util/exec"
utilexec
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/wait"
)
)
const
(
const
(
...
@@ -39,11 +43,14 @@ const (
...
@@ -39,11 +43,14 @@ const (
type
cniNetworkPlugin
struct
{
type
cniNetworkPlugin
struct
{
network
.
NoopNetworkPlugin
network
.
NoopNetworkPlugin
loNetwork
*
cniNetwork
loNetwork
*
cniNetwork
sync
.
RWMutex
defaultNetwork
*
cniNetwork
defaultNetwork
*
cniNetwork
host
network
.
Host
execer
utilexec
.
Interface
host
network
.
Host
nsenterPath
string
execer
utilexec
.
Interface
nsenterPath
string
}
}
type
cniNetwork
struct
{
type
cniNetwork
struct
{
...
@@ -53,16 +60,19 @@ type cniNetwork struct {
...
@@ -53,16 +60,19 @@ type cniNetwork struct {
}
}
func
probeNetworkPluginsWithVendorCNIDirPrefix
(
pluginDir
,
vendorCNIDirPrefix
string
)
[]
network
.
NetworkPlugin
{
func
probeNetworkPluginsWithVendorCNIDirPrefix
(
pluginDir
,
vendorCNIDirPrefix
string
)
[]
network
.
NetworkPlugin
{
configList
:=
make
([]
network
.
NetworkPlugin
,
0
)
plugin
:=
&
cniNetworkPlugin
{
network
,
err
:=
getDefaultCNINetwork
(
pluginDir
,
vendorCNIDirPrefix
)
defaultNetwork
:
nil
,
if
err
!=
nil
{
return
configList
}
return
append
(
configList
,
&
cniNetworkPlugin
{
defaultNetwork
:
network
,
loNetwork
:
getLoNetwork
(
vendorCNIDirPrefix
),
loNetwork
:
getLoNetwork
(
vendorCNIDirPrefix
),
execer
:
utilexec
.
New
(),
execer
:
utilexec
.
New
(),
})
}
plugin
.
syncNetworkConfig
(
pluginDir
,
vendorCNIDirPrefix
)
// sync network config from pluginDir periodically to detect network config updates
go
wait
.
Forever
(
func
()
{
plugin
.
syncNetworkConfig
(
pluginDir
,
vendorCNIDirPrefix
)
},
10
*
time
.
Second
)
return
[]
network
.
NetworkPlugin
{
plugin
}
}
}
func
ProbeNetworkPlugins
(
pluginDir
string
)
[]
network
.
NetworkPlugin
{
func
ProbeNetworkPlugins
(
pluginDir
string
)
[]
network
.
NetworkPlugin
{
...
@@ -137,11 +147,42 @@ func (plugin *cniNetworkPlugin) Init(host network.Host, hairpinMode componentcon
...
@@ -137,11 +147,42 @@ func (plugin *cniNetworkPlugin) Init(host network.Host, hairpinMode componentcon
return
nil
return
nil
}
}
func
(
plugin
*
cniNetworkPlugin
)
syncNetworkConfig
(
pluginDir
,
vendorCNIDirPrefix
string
)
{
network
,
err
:=
getDefaultCNINetwork
(
pluginDir
,
vendorCNIDirPrefix
)
if
err
!=
nil
{
glog
.
Errorf
(
"error updating cni config: %s"
,
err
)
return
}
plugin
.
setDefaultNetwork
(
network
)
}
func
(
plugin
*
cniNetworkPlugin
)
getDefaultNetwork
()
*
cniNetwork
{
plugin
.
RLock
()
defer
plugin
.
RUnlock
()
return
plugin
.
defaultNetwork
}
func
(
plugin
*
cniNetworkPlugin
)
setDefaultNetwork
(
n
*
cniNetwork
)
{
plugin
.
Lock
()
defer
plugin
.
Unlock
()
plugin
.
defaultNetwork
=
n
}
func
(
plugin
*
cniNetworkPlugin
)
checkInitialized
()
error
{
if
plugin
.
getDefaultNetwork
()
==
nil
{
return
errors
.
New
(
"cni config unintialized"
)
}
return
nil
}
func
(
plugin
*
cniNetworkPlugin
)
Name
()
string
{
func
(
plugin
*
cniNetworkPlugin
)
Name
()
string
{
return
CNIPluginName
return
CNIPluginName
}
}
func
(
plugin
*
cniNetworkPlugin
)
SetUpPod
(
namespace
string
,
name
string
,
id
kubecontainer
.
ContainerID
)
error
{
func
(
plugin
*
cniNetworkPlugin
)
SetUpPod
(
namespace
string
,
name
string
,
id
kubecontainer
.
ContainerID
)
error
{
if
err
:=
plugin
.
checkInitialized
();
err
!=
nil
{
return
err
}
netnsPath
,
err
:=
plugin
.
host
.
GetRuntime
()
.
GetNetNS
(
id
)
netnsPath
,
err
:=
plugin
.
host
.
GetRuntime
()
.
GetNetNS
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"CNI failed to retrieve network namespace path: %v"
,
err
)
return
fmt
.
Errorf
(
"CNI failed to retrieve network namespace path: %v"
,
err
)
...
@@ -153,7 +194,7 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubec
...
@@ -153,7 +194,7 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubec
return
err
return
err
}
}
_
,
err
=
plugin
.
defaultNetwork
.
addToNetwork
(
name
,
namespace
,
id
,
netnsPath
)
_
,
err
=
plugin
.
getDefaultNetwork
()
.
addToNetwork
(
name
,
namespace
,
id
,
netnsPath
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error while adding to cni network: %s"
,
err
)
glog
.
Errorf
(
"Error while adding to cni network: %s"
,
err
)
return
err
return
err
...
@@ -163,12 +204,15 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubec
...
@@ -163,12 +204,15 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubec
}
}
func
(
plugin
*
cniNetworkPlugin
)
TearDownPod
(
namespace
string
,
name
string
,
id
kubecontainer
.
ContainerID
)
error
{
func
(
plugin
*
cniNetworkPlugin
)
TearDownPod
(
namespace
string
,
name
string
,
id
kubecontainer
.
ContainerID
)
error
{
if
err
:=
plugin
.
checkInitialized
();
err
!=
nil
{
return
err
}
netnsPath
,
err
:=
plugin
.
host
.
GetRuntime
()
.
GetNetNS
(
id
)
netnsPath
,
err
:=
plugin
.
host
.
GetRuntime
()
.
GetNetNS
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"CNI failed to retrieve network namespace path: %v"
,
err
)
return
fmt
.
Errorf
(
"CNI failed to retrieve network namespace path: %v"
,
err
)
}
}
return
plugin
.
defaultNetwork
.
deleteFromNetwork
(
name
,
namespace
,
id
,
netnsPath
)
return
plugin
.
getDefaultNetwork
()
.
deleteFromNetwork
(
name
,
namespace
,
id
,
netnsPath
)
}
}
// TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin.
// TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin.
...
...
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