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
792868c7
Commit
792868c7
authored
Jun 28, 2016
by
Mike Danese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
periodically reload the cni plugin config
Signed-off-by:
Mike Danese
<
mikedanese@google.com
>
parent
03fe6b96
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 @
792868c7
...
...
@@ -17,8 +17,11 @@ limitations under the License.
package
cni
import
(
"errors"
"fmt"
"sort"
"sync"
"time"
"github.com/appc/cni/libcni"
cnitypes
"github.com/appc/cni/pkg/types"
...
...
@@ -27,6 +30,7 @@ import (
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/network"
utilexec
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/wait"
)
const
(
...
...
@@ -39,11 +43,14 @@ const (
type
cniNetworkPlugin
struct
{
network
.
NoopNetworkPlugin
loNetwork
*
cniNetwork
loNetwork
*
cniNetwork
sync
.
RWMutex
defaultNetwork
*
cniNetwork
host
network
.
Host
execer
utilexec
.
Interface
nsenterPath
string
host
network
.
Host
execer
utilexec
.
Interface
nsenterPath
string
}
type
cniNetwork
struct
{
...
...
@@ -53,16 +60,19 @@ type cniNetwork struct {
}
func
probeNetworkPluginsWithVendorCNIDirPrefix
(
pluginDir
,
vendorCNIDirPrefix
string
)
[]
network
.
NetworkPlugin
{
configList
:=
make
([]
network
.
NetworkPlugin
,
0
)
network
,
err
:=
getDefaultCNINetwork
(
pluginDir
,
vendorCNIDirPrefix
)
if
err
!=
nil
{
return
configList
}
return
append
(
configList
,
&
cniNetworkPlugin
{
defaultNetwork
:
network
,
plugin
:=
&
cniNetworkPlugin
{
defaultNetwork
:
nil
,
loNetwork
:
getLoNetwork
(
vendorCNIDirPrefix
),
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
{
...
...
@@ -137,11 +147,42 @@ func (plugin *cniNetworkPlugin) Init(host network.Host, hairpinMode componentcon
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
{
return
CNIPluginName
}
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
)
if
err
!=
nil
{
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
return
err
}
_
,
err
=
plugin
.
defaultNetwork
.
addToNetwork
(
name
,
namespace
,
id
,
netnsPath
)
_
,
err
=
plugin
.
getDefaultNetwork
()
.
addToNetwork
(
name
,
namespace
,
id
,
netnsPath
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error while adding to cni network: %s"
,
err
)
return
err
...
...
@@ -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
{
if
err
:=
plugin
.
checkInitialized
();
err
!=
nil
{
return
err
}
netnsPath
,
err
:=
plugin
.
host
.
GetRuntime
()
.
GetNetNS
(
id
)
if
err
!=
nil
{
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.
...
...
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