diff --git a/hack/.golint_failures b/hack/.golint_failures index 8ef17efd06c..dec185def3f 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -157,7 +157,6 @@ pkg/kubelet/container/testing pkg/kubelet/dockershim pkg/kubelet/dockershim/libdocker pkg/kubelet/dockershim/network -pkg/kubelet/dockershim/network/cni pkg/kubelet/dockershim/network/cni/testing pkg/kubelet/dockershim/network/hostport pkg/kubelet/dockershim/network/hostport/testing diff --git a/pkg/kubelet/dockershim/network/cni/cni.go b/pkg/kubelet/dockershim/network/cni/cni.go index 3e79c16c93f..81351dcaa5b 100644 --- a/pkg/kubelet/dockershim/network/cni/cni.go +++ b/pkg/kubelet/dockershim/network/cni/cni.go @@ -40,6 +40,7 @@ import ( ) const ( + // CNIPluginName is the name of CNI plugin CNIPluginName = "cni" // defaultSyncConfigPeriod is the default period to sync CNI config @@ -95,8 +96,8 @@ type cniBandwidthEntry struct { EgressBurst int `json:"egressBurst,omitempty"` } -// cniIpRange maps to the standard CNI ip range Capability -type cniIpRange struct { +// cniIPRange maps to the standard CNI ip range Capability +type cniIPRange struct { Subnet string `json:"subnet"` } @@ -112,11 +113,13 @@ type cniDNSConfig struct { Options []string `json:"options,omitempty"` } +// SplitDirs : split dirs by "," func SplitDirs(dirs string) []string { // Use comma rather than colon to work better with Windows too return strings.Split(dirs, ",") } +// ProbeNetworkPlugins : get the network plugin based on cni conf file and bin file func ProbeNetworkPlugins(confDir, cacheDir string, binDirs []string) []network.NetworkPlugin { old := binDirs binDirs = make([]string, 0, len(binDirs)) @@ -416,7 +419,7 @@ func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string } // Set the PodCIDR - rt.CapabilityArgs["ipRanges"] = [][]cniIpRange{{{Subnet: plugin.podCidr}}} + rt.CapabilityArgs["ipRanges"] = [][]cniIPRange{{{Subnet: plugin.podCidr}}} // Set dns capability args. if dnsOptions, ok := options["dns"]; ok { diff --git a/pkg/kubelet/dockershim/network/cni/cni_test.go b/pkg/kubelet/dockershim/network/cni/cni_test.go index aa8fe117d21..dab866bbbf9 100644 --- a/pkg/kubelet/dockershim/network/cni/cni_test.go +++ b/pkg/kubelet/dockershim/network/cni/cni_test.go @@ -123,14 +123,14 @@ func tearDownPlugin(tmpDir string) { } } -type fakeNetworkHost struct { +type FakeNetworkHost struct { networktest.FakePortMappingGetter kubeClient clientset.Interface pods []*containertest.FakePod } -func NewFakeHost(kubeClient clientset.Interface, pods []*containertest.FakePod, ports map[string][]*hostport.PortMapping) *fakeNetworkHost { - host := &fakeNetworkHost{ +func NewFakeHost(kubeClient clientset.Interface, pods []*containertest.FakePod, ports map[string][]*hostport.PortMapping) *FakeNetworkHost { + host := &FakeNetworkHost{ networktest.FakePortMappingGetter{PortMaps: ports}, kubeClient, pods, @@ -138,15 +138,15 @@ func NewFakeHost(kubeClient clientset.Interface, pods []*containertest.FakePod, return host } -func (fnh *fakeNetworkHost) GetPodByName(name, namespace string) (*v1.Pod, bool) { +func (fnh *FakeNetworkHost) GetPodByName(name, namespace string) (*v1.Pod, bool) { return nil, false } -func (fnh *fakeNetworkHost) GetKubeClient() clientset.Interface { +func (fnh *FakeNetworkHost) GetKubeClient() clientset.Interface { return fnh.kubeClient } -func (fnh *fakeNetworkHost) GetNetNS(containerID string) (string, error) { +func (fnh *FakeNetworkHost) GetNetNS(containerID string) (string, error) { for _, fp := range fnh.pods { for _, c := range fp.Pod.Containers { if c.ID.ID == containerID { @@ -157,7 +157,7 @@ func (fnh *fakeNetworkHost) GetNetNS(containerID string) (string, error) { return "", fmt.Errorf("container %q not found", containerID) } -func (fnh *fakeNetworkHost) SupportsLegacyFeatures() bool { +func (fnh *FakeNetworkHost) SupportsLegacyFeatures() bool { return true } @@ -281,7 +281,7 @@ func TestCNIPlugin(t *testing.T) { RuntimeConfig struct { PortMappings []map[string]interface{} `json:"portMappings"` Bandwidth map[string]interface{} `json:"bandwidth"` - IpRanges [][]map[string]interface{} `json:"ipRanges"` + IPRanges [][]map[string]interface{} `json:"IPRanges"` } `json:"runtimeConfig"` }{} inputBytes, inerr := ioutil.ReadFile(inputFile) @@ -304,14 +304,14 @@ func TestCNIPlugin(t *testing.T) { t.Errorf("mismatch in expected bandwidth. expected %v got %v", expectedBandwidth, inputConfig.RuntimeConfig.Bandwidth) } - expectedIpRange := [][]map[string]interface{}{ + expectedIPRange := [][]map[string]interface{}{ { {"subnet": "10.0.2.0/24"}, }, } - if !reflect.DeepEqual(inputConfig.RuntimeConfig.IpRanges, expectedIpRange) { - t.Errorf("mismatch in expected ipRange. expected %v got %v", expectedIpRange, inputConfig.RuntimeConfig.IpRanges) + if !reflect.DeepEqual(inputConfig.RuntimeConfig.IPRanges, expectedIPRange) { + t.Errorf("mismatch in expected ipRange. expected %v got %v", expectedIPRange, inputConfig.RuntimeConfig.IPRanges) } // Get its IP address