mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #74389 from answer1991/sync-cni-config-in-goroutine
sync CNI config in goroutine
This commit is contained in:
commit
b77e4e2417
@ -20,6 +20,7 @@ go_library(
|
|||||||
"//pkg/kubelet/container:go_default_library",
|
"//pkg/kubelet/container:go_default_library",
|
||||||
"//pkg/kubelet/dockershim/network:go_default_library",
|
"//pkg/kubelet/dockershim/network:go_default_library",
|
||||||
"//pkg/util/bandwidth:go_default_library",
|
"//pkg/util/bandwidth:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//vendor/github.com/containernetworking/cni/libcni:go_default_library",
|
"//vendor/github.com/containernetworking/cni/libcni:go_default_library",
|
||||||
"//vendor/github.com/containernetworking/cni/pkg/types:go_default_library",
|
"//vendor/github.com/containernetworking/cni/pkg/types:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
|
@ -24,9 +24,11 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"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"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
|
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
|
||||||
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
||||||
@ -38,6 +40,10 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
CNIPluginName = "cni"
|
CNIPluginName = "cni"
|
||||||
|
|
||||||
|
// defaultSyncConfigPeriod is the default period to sync CNI config
|
||||||
|
// TODO: consider making this value configurable or to be a more appropriate value.
|
||||||
|
defaultSyncConfigPeriod = time.Second * 5
|
||||||
)
|
)
|
||||||
|
|
||||||
type cniNetworkPlugin struct {
|
type cniNetworkPlugin struct {
|
||||||
@ -194,6 +200,10 @@ func (plugin *cniNetworkPlugin) Init(host network.Host, hairpinMode kubeletconfi
|
|||||||
plugin.host = host
|
plugin.host = host
|
||||||
|
|
||||||
plugin.syncNetworkConfig()
|
plugin.syncNetworkConfig()
|
||||||
|
|
||||||
|
// start a goroutine to sync network config from confDir periodically to detect network config updates in every 5 seconds
|
||||||
|
go wait.Forever(plugin.syncNetworkConfig, defaultSyncConfigPeriod)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,9 +274,6 @@ func (plugin *cniNetworkPlugin) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) Status() error {
|
func (plugin *cniNetworkPlugin) Status() error {
|
||||||
// sync network config from confDir periodically to detect network config updates
|
|
||||||
plugin.syncNetworkConfig()
|
|
||||||
|
|
||||||
// Can't set up pods if we don't have any CNI network configs yet
|
// Can't set up pods if we don't have any CNI network configs yet
|
||||||
return plugin.checkInitialized()
|
return plugin.checkInitialized()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user