Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement network plugin capabilities hook and shaping capability #22827

Merged
merged 2 commits into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you just return this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean here...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return kl.networkPlugin != nil && kl.networkPlugin.Capabilities().Has(network.NET_PLUGIN_CAPABILITY_SHAPING)

Also why return false if the network plugin has shaping enabled?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it just read weird, this is answering the question is shaping enabled inline for the kubelet. Please add comment saying that the plugin will handle in, for hasty people like myself.

return false
}
return true
}

func (kl *Kubelet) GetNodeConfig() cm.NodeConfig {
return kl.containerManager.GetNodeConfig()
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/kubelet/network/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (
)

type cniNetworkPlugin struct {
network.NoopNetworkPlugin

defaultNetwork *cniNetwork
host network.Host
}
Expand Down Expand Up @@ -96,9 +98,6 @@ func (plugin *cniNetworkPlugin) Init(host network.Host) error {
return nil
}

func (plugin *cniNetworkPlugin) Event(name string, details map[string]interface{}) {
}

func (plugin *cniNetworkPlugin) Name() string {
return CNIPluginName
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/kubelet/network/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ import (
)

type execNetworkPlugin struct {
network.NoopNetworkPlugin

execName string
execPath string
host network.Host
Expand Down Expand Up @@ -120,9 +122,6 @@ func (plugin *execNetworkPlugin) getExecutable() string {
return path.Join(plugin.execPath, execName)
}

func (plugin *execNetworkPlugin) Event(name string, details map[string]interface{}) {
}

func (plugin *execNetworkPlugin) Name() string {
return plugin.execName
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/kubelet/network/kubenet/kubenet_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const (
)

type kubenetNetworkPlugin struct {
network.NoopNetworkPlugin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me that kubenet already support shaping
https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/network/kubenet/kubenet_linux.go#L211

Just include NET_PLUGIN_CAPABILITY_SHAPING for kubenet would work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ignore my comment above. The shaper in kubenet is not complete. Ingress/egress for pod has not been covered.


host network.Host
netConfig *libcni.NetworkConfig
cniConfig *libcni.CNIConfig
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubelet/network/kubenet/kubenet_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
)

type kubenetNetworkPlugin struct {
network.NoopNetworkPlugin
}

func NewPlugin() network.NetworkPlugin {
Expand All @@ -35,8 +36,6 @@ func NewPlugin() network.NetworkPlugin {
func (plugin *kubenetNetworkPlugin) Init(host network.Host) error {
return fmt.Errorf("Kubenet is not supported in this build")
}
func (plugin *kubenetNetworkPlugin) Event(name string, details map[string]interface{}) {
}

func (plugin *kubenetNetworkPlugin) Name() string {
return "kubenet"
Expand Down
30 changes: 22 additions & 8 deletions pkg/kubelet/network/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -94,7 +104,7 @@ type Host interface {
func InitNetworkPlugin(plugins []NetworkPlugin, networkPluginName string, host Host) (NetworkPlugin, error) {
if networkPluginName == "" {
// default to the no_op plugin
plug := &noopNetworkPlugin{}
plug := &NoopNetworkPlugin{}
if err := plug.Init(host); err != nil {
return nil, err
}
Expand Down Expand Up @@ -137,12 +147,12 @@ func UnescapePluginName(in string) string {
return strings.Replace(in, "~", "/", -1)
}

type noopNetworkPlugin struct {
type NoopNetworkPlugin struct {
}

const sysctlBridgeCallIptables = "net/bridge/bridge-nf-call-iptables"

func (plugin *noopNetworkPlugin) Init(host Host) error {
func (plugin *NoopNetworkPlugin) Init(host Host) error {
// Set bridge-nf-call-iptables=1 to maintain compatibility with older
// kubernetes versions to ensure the iptables-based kube proxy functions
// correctly. Other plugins are responsible for setting this correctly
Expand All @@ -159,21 +169,25 @@ func (plugin *noopNetworkPlugin) Init(host Host) error {
return nil
}

func (plugin *noopNetworkPlugin) Event(name string, details map[string]interface{}) {
func (plugin *NoopNetworkPlugin) Event(name string, details map[string]interface{}) {
}

func (plugin *noopNetworkPlugin) Name() string {
func (plugin *NoopNetworkPlugin) Name() string {
return DefaultPluginName
}

func (plugin *noopNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
func (plugin *NoopNetworkPlugin) Capabilities() utilsets.Int {
return utilsets.NewInt()
}

func (plugin *NoopNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
return nil
}

func (plugin *noopNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
func (plugin *NoopNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
return nil
}

func (plugin *noopNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*PodNetworkStatus, error) {
func (plugin *NoopNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*PodNetworkStatus, error) {
return nil, nil
}