mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Send PodCIDR to network plugins as an event
This commit is contained in:
parent
fc2929ed05
commit
67414afd11
@ -398,7 +398,8 @@ func NewMainKubelet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
klet.pleg = pleg.NewGenericPLEG(klet.containerRuntime, plegChannelCapacity, plegRelistPeriod, klet.podCache)
|
klet.pleg = pleg.NewGenericPLEG(klet.containerRuntime, plegChannelCapacity, plegRelistPeriod, klet.podCache)
|
||||||
klet.runtimeState = newRuntimeState(maxWaitForContainerRuntime, configureCBR0, podCIDR, klet.isContainerRuntimeVersionCompatible)
|
klet.runtimeState = newRuntimeState(maxWaitForContainerRuntime, configureCBR0, klet.isContainerRuntimeVersionCompatible)
|
||||||
|
klet.updatePodCIDR(podCIDR)
|
||||||
|
|
||||||
// setup containerGC
|
// setup containerGC
|
||||||
containerGC, err := kubecontainer.NewContainerGC(klet.containerRuntime, containerGCPolicy)
|
containerGC, err := kubecontainer.NewContainerGC(klet.containerRuntime, containerGCPolicy)
|
||||||
@ -2644,9 +2645,7 @@ func (kl *Kubelet) syncNetworkStatus() {
|
|||||||
glog.Infof("Flannel server handshake failed %v", err)
|
glog.Infof("Flannel server handshake failed %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
glog.Infof("Setting cidr: %v -> %v",
|
kl.updatePodCIDR(podCIDR)
|
||||||
kl.runtimeState.podCIDR(), podCIDR)
|
|
||||||
kl.runtimeState.setPodCIDR(podCIDR)
|
|
||||||
}
|
}
|
||||||
if err := ensureIPTablesMasqRule(kl.nonMasqueradeCIDR); err != nil {
|
if err := ensureIPTablesMasqRule(kl.nonMasqueradeCIDR); err != nil {
|
||||||
err = fmt.Errorf("Error on adding ip table rules: %v", err)
|
err = fmt.Errorf("Error on adding ip table rules: %v", err)
|
||||||
@ -3026,7 +3025,7 @@ func (kl *Kubelet) tryUpdateNodeStatus() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if kl.reconcileCIDR {
|
} else if kl.reconcileCIDR {
|
||||||
kl.runtimeState.setPodCIDR(node.Spec.PodCIDR)
|
kl.updatePodCIDR(node.Spec.PodCIDR)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := kl.setNodeStatus(node); err != nil {
|
if err := kl.setNodeStatus(node); err != nil {
|
||||||
@ -3445,6 +3444,21 @@ func (kl *Kubelet) GetRuntime() kubecontainer.Runtime {
|
|||||||
return kl.containerRuntime
|
return kl.containerRuntime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (kl *Kubelet) updatePodCIDR(cidr string) {
|
||||||
|
if kl.runtimeState.podCIDR() == cidr {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.Infof("Setting Pod CIDR: %v -> %v", kl.runtimeState.podCIDR(), cidr)
|
||||||
|
kl.runtimeState.setPodCIDR(cidr)
|
||||||
|
|
||||||
|
if kl.networkPlugin != nil {
|
||||||
|
details := make(map[string]interface{})
|
||||||
|
details[network.NET_PLUGIN_EVENT_POD_CIDR_CHANGE_DETAIL_CIDR] = cidr
|
||||||
|
kl.networkPlugin.Event(network.NET_PLUGIN_EVENT_POD_CIDR_CHANGE, details)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var minRsrc = resource.MustParse("1k")
|
var minRsrc = resource.MustParse("1k")
|
||||||
var maxRsrc = resource.MustParse("1P")
|
var maxRsrc = resource.MustParse("1P")
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
|
|||||||
|
|
||||||
kubelet.hostname = testKubeletHostname
|
kubelet.hostname = testKubeletHostname
|
||||||
kubelet.nodeName = testKubeletHostname
|
kubelet.nodeName = testKubeletHostname
|
||||||
kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime, false, "" /* Pod CIDR */, func() error { return nil })
|
kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime, false, func() error { return nil })
|
||||||
kubelet.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil))
|
kubelet.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil))
|
||||||
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)
|
||||||
@ -2961,7 +2961,7 @@ func TestDockerRuntimeVersion(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime, false, "", kubelet.isContainerRuntimeVersionCompatible)
|
kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime, false, kubelet.isContainerRuntimeVersionCompatible)
|
||||||
kubelet.updateRuntimeUp()
|
kubelet.updateRuntimeUp()
|
||||||
if err := kubelet.updateNodeStatus(); err != nil {
|
if err := kubelet.updateNodeStatus(); err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
@ -3424,7 +3424,7 @@ func TestUpdateNodeStatusWithoutContainerRuntime(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
kubelet.runtimeState = newRuntimeState(time.Duration(0), false, "" /* Pod CIDR */, func() error { return nil })
|
kubelet.runtimeState = newRuntimeState(time.Duration(0), false, func() error { return nil })
|
||||||
kubelet.updateRuntimeUp()
|
kubelet.updateRuntimeUp()
|
||||||
if err := kubelet.updateNodeStatus(); err != nil {
|
if err := kubelet.updateNodeStatus(); err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -97,6 +97,9 @@ func (plugin *cniNetworkPlugin) Init(host network.Host) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (plugin *cniNetworkPlugin) Event(name string, details map[string]interface{}) {
|
||||||
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) Name() string {
|
func (plugin *cniNetworkPlugin) Name() string {
|
||||||
return CNIPluginName
|
return CNIPluginName
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,9 @@ func (plugin *execNetworkPlugin) getExecutable() string {
|
|||||||
return path.Join(plugin.execPath, execName)
|
return path.Join(plugin.execPath, execName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (plugin *execNetworkPlugin) Event(name string, details map[string]interface{}) {
|
||||||
|
}
|
||||||
|
|
||||||
func (plugin *execNetworkPlugin) Name() string {
|
func (plugin *execNetworkPlugin) Name() string {
|
||||||
return plugin.execName
|
return plugin.execName
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,21 @@ import (
|
|||||||
|
|
||||||
const DefaultPluginName = "kubernetes.io/no-op"
|
const DefaultPluginName = "kubernetes.io/no-op"
|
||||||
|
|
||||||
|
// Called when the node's Pod CIDR is known when using the
|
||||||
|
// controller manager's --allocate-node-cidrs=true option
|
||||||
|
const NET_PLUGIN_EVENT_POD_CIDR_CHANGE = "pod-cidr-change"
|
||||||
|
const NET_PLUGIN_EVENT_POD_CIDR_CHANGE_DETAIL_CIDR = "pod-cidr"
|
||||||
|
|
||||||
// Plugin is an interface to network plugins for the kubelet
|
// Plugin is an interface to network plugins for the kubelet
|
||||||
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) error
|
Init(host Host) error
|
||||||
|
|
||||||
|
// Called on various events like:
|
||||||
|
// NET_PLUGIN_EVENT_POD_CIDR_CHANGE
|
||||||
|
Event(name string, details map[string]interface{})
|
||||||
|
|
||||||
// Name returns the plugin's name. This will be used when searching
|
// Name returns the plugin's name. This will be used when searching
|
||||||
// for a plugin by name, e.g.
|
// for a plugin by name, e.g.
|
||||||
Name() string
|
Name() string
|
||||||
@ -130,6 +139,9 @@ func (plugin *noopNetworkPlugin) Init(host Host) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (plugin *noopNetworkPlugin) Event(name string, details map[string]interface{}) {
|
||||||
|
}
|
||||||
|
|
||||||
func (plugin *noopNetworkPlugin) Name() string {
|
func (plugin *noopNetworkPlugin) Name() string {
|
||||||
return DefaultPluginName
|
return DefaultPluginName
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,6 @@ func (s *runtimeState) errors() []string {
|
|||||||
func newRuntimeState(
|
func newRuntimeState(
|
||||||
runtimeSyncThreshold time.Duration,
|
runtimeSyncThreshold time.Duration,
|
||||||
configureNetwork bool,
|
configureNetwork bool,
|
||||||
cidr string,
|
|
||||||
runtimeCompatibility func() error,
|
runtimeCompatibility func() error,
|
||||||
) *runtimeState {
|
) *runtimeState {
|
||||||
var networkError error = nil
|
var networkError error = nil
|
||||||
@ -105,7 +104,6 @@ func newRuntimeState(
|
|||||||
lastBaseRuntimeSync: time.Time{},
|
lastBaseRuntimeSync: time.Time{},
|
||||||
baseRuntimeSyncThreshold: runtimeSyncThreshold,
|
baseRuntimeSyncThreshold: runtimeSyncThreshold,
|
||||||
networkError: networkError,
|
networkError: networkError,
|
||||||
cidr: cidr,
|
|
||||||
internalError: nil,
|
internalError: nil,
|
||||||
runtimeCompatibility: runtimeCompatibility,
|
runtimeCompatibility: runtimeCompatibility,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user