network: hook net plugin Status() up to NetworkReady and runtime status
Port https://github.com/kubernetes/kubernetes/pull/43474 over to CRI-O and hook network plugin status up to the runtime NetworkReady() call so the plugin's status is accurately reported back to the orchestrator.
This commit is contained in:
parent
93b1ff5207
commit
8d2d1d09f4
3 changed files with 16 additions and 17 deletions
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/containernetworking/cni/pkg/ns"
|
"github.com/containernetworking/cni/pkg/ns"
|
||||||
"github.com/kubernetes-incubator/cri-o/utils"
|
"github.com/kubernetes-incubator/cri-o/utils"
|
||||||
|
"github.com/kubernetes-incubator/cri-o/pkg/ocicni"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
||||||
|
@ -36,7 +37,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// New creates a new Runtime with options provided
|
// New creates a new Runtime with options provided
|
||||||
func New(runtimePath string, runtimeHostPrivilegedPath string, conmonPath string, conmonEnv []string, cgroupManager string) (*Runtime, error) {
|
func New(runtimePath string, runtimeHostPrivilegedPath string, conmonPath string, conmonEnv []string, cgroupManager string, netPlugin ocicni.CNIPlugin) (*Runtime, error) {
|
||||||
r := &Runtime{
|
r := &Runtime{
|
||||||
name: filepath.Base(runtimePath),
|
name: filepath.Base(runtimePath),
|
||||||
path: runtimePath,
|
path: runtimePath,
|
||||||
|
@ -44,6 +45,7 @@ func New(runtimePath string, runtimeHostPrivilegedPath string, conmonPath string
|
||||||
conmonPath: conmonPath,
|
conmonPath: conmonPath,
|
||||||
conmonEnv: conmonEnv,
|
conmonEnv: conmonEnv,
|
||||||
cgroupManager: cgroupManager,
|
cgroupManager: cgroupManager,
|
||||||
|
netPlugin: netPlugin,
|
||||||
}
|
}
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
@ -56,6 +58,7 @@ type Runtime struct {
|
||||||
conmonPath string
|
conmonPath string
|
||||||
conmonEnv []string
|
conmonEnv []string
|
||||||
cgroupManager string
|
cgroupManager string
|
||||||
|
netPlugin ocicni.CNIPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
// syncInfo is used to return data from monitor process to daemon
|
// syncInfo is used to return data from monitor process to daemon
|
||||||
|
@ -579,5 +582,8 @@ func (r *Runtime) RuntimeReady() (bool, error) {
|
||||||
// NetworkReady checks if the runtime network is up and ready to
|
// NetworkReady checks if the runtime network is up and ready to
|
||||||
// accept containers which require container network.
|
// accept containers which require container network.
|
||||||
func (r *Runtime) NetworkReady() (bool, error) {
|
func (r *Runtime) NetworkReady() (bool, error) {
|
||||||
|
if err := r.netPlugin.Status(); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/containernetworking/cni/libcni"
|
"github.com/containernetworking/cni/libcni"
|
||||||
cnitypes "github.com/containernetworking/cni/pkg/types"
|
cnitypes "github.com/containernetworking/cni/pkg/types"
|
||||||
|
@ -44,19 +43,10 @@ func InitCNI(pluginDir string, cniDirs ...string) (CNIPlugin, error) {
|
||||||
// check if a default network exists, otherwise dump the CNI search and return a noop plugin
|
// check if a default network exists, otherwise dump the CNI search and return a noop plugin
|
||||||
_, err = getDefaultCNINetwork(plugin.pluginDir, plugin.cniDirs, plugin.vendorCNIDirPrefix)
|
_, err = getDefaultCNINetwork(plugin.pluginDir, plugin.cniDirs, plugin.vendorCNIDirPrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("Error in finding usable CNI plugin - %v", err)
|
glog.Warningf("Error in finding usable CNI plugin; waiting for CNI network configuration")
|
||||||
// create a noop plugin instead
|
|
||||||
return &cniNoOp{}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sync network config from pluginDir periodically to detect network config updates
|
plugin.syncNetworkConfig()
|
||||||
go func() {
|
|
||||||
t := time.NewTimer(10 * time.Second)
|
|
||||||
for {
|
|
||||||
plugin.syncNetworkConfig()
|
|
||||||
<-t.C
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return plugin, nil
|
return plugin, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,5 +258,6 @@ func buildCNIRuntimeConf(podName string, podNs string, podInfraContainerID strin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) Status() error {
|
func (plugin *cniNetworkPlugin) Status() error {
|
||||||
|
plugin.syncNetworkConfig()
|
||||||
return plugin.checkInitialized()
|
return plugin.checkInitialized()
|
||||||
}
|
}
|
||||||
|
|
|
@ -454,16 +454,18 @@ func New(config *Config) (*Server, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := oci.New(config.Runtime, config.RuntimeHostPrivileged, config.Conmon, config.ConmonEnv, config.CgroupManager)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sandboxes := make(map[string]*sandbox)
|
sandboxes := make(map[string]*sandbox)
|
||||||
containers := oci.NewMemoryStore()
|
containers := oci.NewMemoryStore()
|
||||||
netPlugin, err := ocicni.InitCNI(config.NetworkDir, config.PluginDir)
|
netPlugin, err := ocicni.InitCNI(config.NetworkDir, config.PluginDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r, err := oci.New(config.Runtime, config.RuntimeHostPrivileged, config.Conmon, config.ConmonEnv, config.CgroupManager, netPlugin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
s := &Server{
|
s := &Server{
|
||||||
runtime: r,
|
runtime: r,
|
||||||
store: store,
|
store: store,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue