From fb97b8cdaa9ac073384a8e2b5258f40e63e5be64 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 22 Mar 2016 11:43:13 -0500 Subject: [PATCH] Implement network plugin capabilities hook and shaping capability Allow network plugins to declare that they handle shaping and that Kuberenetes should not. Will be first used by openshift-sdn which handles shaping through OVS, but this triggers a warning when kubelet notices the bandwidth annotations. --- pkg/kubelet/kubelet.go | 23 +++++++++++++++++++---- pkg/kubelet/network/plugins.go | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index a6695f4767f..0355438c48a 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -1798,6 +1798,9 @@ func (kl *Kubelet) syncPod(pod *api.Pod, mirrorPod *api.Pod, podStatus *kubecont return err } + if !kl.shapingEnabled() { + return nil + } ingress, egress, err := extractBandwidthResources(pod) if err != nil { return err @@ -2734,11 +2737,14 @@ func (kl *Kubelet) reconcileCBR0(podCIDR string) error { if err := ensureCbr0(cidr, kl.hairpinMode == componentconfig.PromiscuousBridge, kl.babysitDaemons); err != nil { return err } - if kl.shaper == nil { - glog.V(5).Info("Shaper is nil, creating") - kl.shaper = bandwidth.NewTCShaper("cbr0") + if kl.shapingEnabled() { + if kl.shaper == nil { + glog.V(5).Info("Shaper is nil, creating") + kl.shaper = bandwidth.NewTCShaper("cbr0") + } + return kl.shaper.ReconcileInterface() } - return kl.shaper.ReconcileInterface() + return nil } // updateNodeStatus updates node status to master with retries. @@ -3594,6 +3600,15 @@ func (kl *Kubelet) updatePodCIDR(cidr string) { kl.networkPlugin.Event(network.NET_PLUGIN_EVENT_POD_CIDR_CHANGE, details) } } + +func (kl *Kubelet) shapingEnabled() bool { + // Disable shaping if a network plugin is defined and supports shaping + if kl.networkPlugin != nil && kl.networkPlugin.Capabilities().Has(network.NET_PLUGIN_CAPABILITY_SHAPING) { + return false + } + return true +} + func (kl *Kubelet) GetNodeConfig() cm.NodeConfig { return kl.containerManager.GetNodeConfig() } diff --git a/pkg/kubelet/network/plugins.go b/pkg/kubelet/network/plugins.go index e45515a2aad..64cfd03c1a3 100644 --- a/pkg/kubelet/network/plugins.go +++ b/pkg/kubelet/network/plugins.go @@ -29,6 +29,7 @@ import ( kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" utilerrors "k8s.io/kubernetes/pkg/util/errors" utilexec "k8s.io/kubernetes/pkg/util/exec" + utilsets "k8s.io/kubernetes/pkg/util/sets" utilsysctl "k8s.io/kubernetes/pkg/util/sysctl" "k8s.io/kubernetes/pkg/util/validation" ) @@ -40,6 +41,12 @@ const DefaultPluginName = "kubernetes.io/no-op" const NET_PLUGIN_EVENT_POD_CIDR_CHANGE = "pod-cidr-change" const NET_PLUGIN_EVENT_POD_CIDR_CHANGE_DETAIL_CIDR = "pod-cidr" +// Plugin capabilities +const ( + // Indicates the plugin handles Kubernetes bandwidth shaping annotations internally + NET_PLUGIN_CAPABILITY_SHAPING int = 1 +) + // Plugin is an interface to network plugins for the kubelet type NetworkPlugin interface { // Init initializes the plugin. This will be called exactly once @@ -54,6 +61,9 @@ type NetworkPlugin interface { // for a plugin by name, e.g. Name() string + // Returns a set of NET_PLUGIN_CAPABILITY_* + Capabilities() utilsets.Int + // SetUpPod is the method called after the infra container of // the pod has been created but before the other containers of the // pod are launched. @@ -166,6 +176,10 @@ func (plugin *NoopNetworkPlugin) Name() string { return DefaultPluginName } +func (plugin *NoopNetworkPlugin) Capabilities() utilsets.Int { + return utilsets.NewInt() +} + func (plugin *NoopNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error { return nil }