diff --git a/hack/.golint_failures b/hack/.golint_failures index df4dd16db45..de0afe584e5 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -287,7 +287,6 @@ pkg/security/podsecuritypolicy/user pkg/security/podsecuritypolicy/util pkg/serviceaccount pkg/ssh -pkg/util/bandwidth pkg/util/config pkg/util/ebtables pkg/util/env diff --git a/pkg/kubelet/dockershim/network/kubenet/kubenet_linux.go b/pkg/kubelet/dockershim/network/kubenet/kubenet_linux.go index c3909b1c7f4..acd47ee2fbd 100644 --- a/pkg/kubelet/dockershim/network/kubenet/kubenet_linux.go +++ b/pkg/kubelet/dockershim/network/kubenet/kubenet_linux.go @@ -74,7 +74,7 @@ type kubenetNetworkPlugin struct { netConfig *libcni.NetworkConfig loConfig *libcni.NetworkConfig cniConfig libcni.CNI - bandwidthShaper bandwidth.BandwidthShaper + bandwidthShaper bandwidth.Shaper mu sync.Mutex //Mutex for protecting podIPs map, netConfig, and shaper initialization podIPs map[kubecontainer.ContainerID]string mtu int @@ -597,7 +597,7 @@ func (plugin *kubenetNetworkPlugin) delContainerFromNetwork(config *libcni.Netwo // shaper retrieves the bandwidth shaper and, if it hasn't been fetched before, // initializes it and ensures the bridge is appropriately configured // This function should only be called while holding the `plugin.mu` lock -func (plugin *kubenetNetworkPlugin) shaper() bandwidth.BandwidthShaper { +func (plugin *kubenetNetworkPlugin) shaper() bandwidth.Shaper { if plugin.bandwidthShaper == nil { plugin.bandwidthShaper = bandwidth.NewTCShaper(BridgeName) plugin.bandwidthShaper.ReconcileInterface() diff --git a/pkg/util/bandwidth/fake_shaper.go b/pkg/util/bandwidth/fake_shaper.go index 8c95e3bb317..78577185d73 100644 --- a/pkg/util/bandwidth/fake_shaper.go +++ b/pkg/util/bandwidth/fake_shaper.go @@ -22,28 +22,35 @@ import ( "k8s.io/apimachinery/pkg/api/resource" ) +// FakeShaper provides an implementation of the bandwith.Shaper. +// Beware this is implementation has no features besides Reset and GetCIDRs. type FakeShaper struct { CIDRs []string ResetCIDRs []string } +// Limit is not implemented func (f *FakeShaper) Limit(cidr string, egress, ingress *resource.Quantity) error { return errors.New("unimplemented") } +// Reset appends a particular CIDR to the set of ResetCIDRs being managed by this shaper func (f *FakeShaper) Reset(cidr string) error { f.ResetCIDRs = append(f.ResetCIDRs, cidr) return nil } +// ReconcileInterface is not implemented func (f *FakeShaper) ReconcileInterface() error { return errors.New("unimplemented") } +// ReconcileCIDR is not implemented func (f *FakeShaper) ReconcileCIDR(cidr string, egress, ingress *resource.Quantity) error { return errors.New("unimplemented") } +// GetCIDRs returns the set of CIDRs that are being managed by this shaper func (f *FakeShaper) GetCIDRs() ([]string, error) { return f.CIDRs, nil } diff --git a/pkg/util/bandwidth/interfaces.go b/pkg/util/bandwidth/interfaces.go index 6b0e160aae6..ec29d5d1047 100644 --- a/pkg/util/bandwidth/interfaces.go +++ b/pkg/util/bandwidth/interfaces.go @@ -18,7 +18,9 @@ package bandwidth import "k8s.io/apimachinery/pkg/api/resource" -type BandwidthShaper interface { +// Shaper is designed so that the shaper structs created +// satisfy the Shaper interface. +type Shaper interface { // Limit the bandwidth for a particular CIDR on a particular interface // * ingress and egress are in bits/second // * cidr is expected to be a valid network CIDR (e.g. '1.2.3.4/32' or '10.20.0.1/16') diff --git a/pkg/util/bandwidth/linux.go b/pkg/util/bandwidth/linux.go index 7050b4f763c..f01e7cc02f9 100644 --- a/pkg/util/bandwidth/linux.go +++ b/pkg/util/bandwidth/linux.go @@ -33,7 +33,7 @@ import ( "k8s.io/klog" ) -// tcShaper provides an implementation of the BandwidthShaper interface on Linux using the 'tc' tool. +// tcShaper provides an implementation of the Shaper interface on Linux using the 'tc' tool. // In general, using this requires that the caller posses the NET_CAP_ADMIN capability, though if you // do this within an container, it only requires the NS_CAPABLE capability for manipulations to that // container's network namespace. @@ -44,7 +44,8 @@ type tcShaper struct { iface string } -func NewTCShaper(iface string) BandwidthShaper { +// NewTCShaper makes a new tcShaper for the given interface +func NewTCShaper(iface string) Shaper { shaper := &tcShaper{ e: exec.New(), iface: iface, @@ -157,10 +158,9 @@ func (t *tcShaper) findCIDRClass(cidr string) (classAndHandleList [][]string, fo // filter parent 1: protocol ip pref 1 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 if len(parts) != 19 { return classAndHandleList, false, fmt.Errorf("unexpected output from tc: %s %d (%v)", filter, len(parts), parts) - } else { - resultTmp := []string{parts[18], parts[9]} - classAndHandleList = append(classAndHandleList, resultTmp) } + resultTmp := []string{parts[18], parts[9]} + classAndHandleList = append(classAndHandleList, resultTmp) } } if len(classAndHandleList) > 0 { diff --git a/pkg/util/bandwidth/unsupported.go b/pkg/util/bandwidth/unsupported.go index 7d556fd64da..929f5e0584d 100644 --- a/pkg/util/bandwidth/unsupported.go +++ b/pkg/util/bandwidth/unsupported.go @@ -27,7 +27,8 @@ import ( type unsupportedShaper struct { } -func NewTCShaper(iface string) BandwidthShaper { +// NewTCShaper makes a new unsupportedShapper for the given interface +func NewTCShaper(iface string) Shaper { return &unsupportedShaper{} } diff --git a/pkg/util/bandwidth/utils.go b/pkg/util/bandwidth/utils.go index 451ab68836c..b29825bdfb9 100644 --- a/pkg/util/bandwidth/utils.go +++ b/pkg/util/bandwidth/utils.go @@ -35,6 +35,7 @@ func validateBandwidthIsReasonable(rsrc *resource.Quantity) error { return nil } +// ExtractPodBandwidthResources extracts the ingress and egress from the given pod annotations func ExtractPodBandwidthResources(podAnnotations map[string]string) (ingress, egress *resource.Quantity, err error) { if podAnnotations == nil { return nil, nil, nil