Skip to content

Commit 37281a4

Browse files
authored
Merge pull request kubernetes#76442 from viegasdom/fix-golint-utils-bandwith
Fix golint failures of util/bandwith/*.go
2 parents 929adb6 + 9d3d7a7 commit 37281a4

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed

hack/.golint_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ pkg/security/podsecuritypolicy/user
287287
pkg/security/podsecuritypolicy/util
288288
pkg/serviceaccount
289289
pkg/ssh
290-
pkg/util/bandwidth
291290
pkg/util/config
292291
pkg/util/ebtables
293292
pkg/util/env

pkg/kubelet/dockershim/network/kubenet/kubenet_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type kubenetNetworkPlugin struct {
7474
netConfig *libcni.NetworkConfig
7575
loConfig *libcni.NetworkConfig
7676
cniConfig libcni.CNI
77-
bandwidthShaper bandwidth.BandwidthShaper
77+
bandwidthShaper bandwidth.Shaper
7878
mu sync.Mutex //Mutex for protecting podIPs map, netConfig, and shaper initialization
7979
podIPs map[kubecontainer.ContainerID]string
8080
mtu int
@@ -597,7 +597,7 @@ func (plugin *kubenetNetworkPlugin) delContainerFromNetwork(config *libcni.Netwo
597597
// shaper retrieves the bandwidth shaper and, if it hasn't been fetched before,
598598
// initializes it and ensures the bridge is appropriately configured
599599
// This function should only be called while holding the `plugin.mu` lock
600-
func (plugin *kubenetNetworkPlugin) shaper() bandwidth.BandwidthShaper {
600+
func (plugin *kubenetNetworkPlugin) shaper() bandwidth.Shaper {
601601
if plugin.bandwidthShaper == nil {
602602
plugin.bandwidthShaper = bandwidth.NewTCShaper(BridgeName)
603603
plugin.bandwidthShaper.ReconcileInterface()

pkg/util/bandwidth/fake_shaper.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,35 @@ import (
2222
"k8s.io/apimachinery/pkg/api/resource"
2323
)
2424

25+
// FakeShaper provides an implementation of the bandwith.Shaper.
26+
// Beware this is implementation has no features besides Reset and GetCIDRs.
2527
type FakeShaper struct {
2628
CIDRs []string
2729
ResetCIDRs []string
2830
}
2931

32+
// Limit is not implemented
3033
func (f *FakeShaper) Limit(cidr string, egress, ingress *resource.Quantity) error {
3134
return errors.New("unimplemented")
3235
}
3336

37+
// Reset appends a particular CIDR to the set of ResetCIDRs being managed by this shaper
3438
func (f *FakeShaper) Reset(cidr string) error {
3539
f.ResetCIDRs = append(f.ResetCIDRs, cidr)
3640
return nil
3741
}
3842

43+
// ReconcileInterface is not implemented
3944
func (f *FakeShaper) ReconcileInterface() error {
4045
return errors.New("unimplemented")
4146
}
4247

48+
// ReconcileCIDR is not implemented
4349
func (f *FakeShaper) ReconcileCIDR(cidr string, egress, ingress *resource.Quantity) error {
4450
return errors.New("unimplemented")
4551
}
4652

53+
// GetCIDRs returns the set of CIDRs that are being managed by this shaper
4754
func (f *FakeShaper) GetCIDRs() ([]string, error) {
4855
return f.CIDRs, nil
4956
}

pkg/util/bandwidth/interfaces.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ package bandwidth
1818

1919
import "k8s.io/apimachinery/pkg/api/resource"
2020

21-
type BandwidthShaper interface {
21+
// Shaper is designed so that the shaper structs created
22+
// satisfy the Shaper interface.
23+
type Shaper interface {
2224
// Limit the bandwidth for a particular CIDR on a particular interface
2325
// * ingress and egress are in bits/second
2426
// * cidr is expected to be a valid network CIDR (e.g. '1.2.3.4/32' or '10.20.0.1/16')

pkg/util/bandwidth/linux.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"k8s.io/klog"
3434
)
3535

36-
// tcShaper provides an implementation of the BandwidthShaper interface on Linux using the 'tc' tool.
36+
// tcShaper provides an implementation of the Shaper interface on Linux using the 'tc' tool.
3737
// In general, using this requires that the caller posses the NET_CAP_ADMIN capability, though if you
3838
// do this within an container, it only requires the NS_CAPABLE capability for manipulations to that
3939
// container's network namespace.
@@ -44,7 +44,8 @@ type tcShaper struct {
4444
iface string
4545
}
4646

47-
func NewTCShaper(iface string) BandwidthShaper {
47+
// NewTCShaper makes a new tcShaper for the given interface
48+
func NewTCShaper(iface string) Shaper {
4849
shaper := &tcShaper{
4950
e: exec.New(),
5051
iface: iface,
@@ -157,10 +158,9 @@ func (t *tcShaper) findCIDRClass(cidr string) (classAndHandleList [][]string, fo
157158
// filter parent 1: protocol ip pref 1 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1
158159
if len(parts) != 19 {
159160
return classAndHandleList, false, fmt.Errorf("unexpected output from tc: %s %d (%v)", filter, len(parts), parts)
160-
} else {
161-
resultTmp := []string{parts[18], parts[9]}
162-
classAndHandleList = append(classAndHandleList, resultTmp)
163161
}
162+
resultTmp := []string{parts[18], parts[9]}
163+
classAndHandleList = append(classAndHandleList, resultTmp)
164164
}
165165
}
166166
if len(classAndHandleList) > 0 {

pkg/util/bandwidth/unsupported.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import (
2727
type unsupportedShaper struct {
2828
}
2929

30-
func NewTCShaper(iface string) BandwidthShaper {
30+
// NewTCShaper makes a new unsupportedShapper for the given interface
31+
func NewTCShaper(iface string) Shaper {
3132
return &unsupportedShaper{}
3233
}
3334

pkg/util/bandwidth/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func validateBandwidthIsReasonable(rsrc *resource.Quantity) error {
3535
return nil
3636
}
3737

38+
// ExtractPodBandwidthResources extracts the ingress and egress from the given pod annotations
3839
func ExtractPodBandwidthResources(podAnnotations map[string]string) (ingress, egress *resource.Quantity, err error) {
3940
if podAnnotations == nil {
4041
return nil, nil, nil

0 commit comments

Comments
 (0)