Merge pull request #79321 from shufanhao/fix_golint_issue_for_network

Fix golint failure in pkg/kubelet/dockershim/network/cni
This commit is contained in:
Kubernetes Prow Robot 2019-07-03 13:52:26 -07:00 committed by GitHub
commit 8f7bb1fe71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 15 deletions

View File

@ -157,7 +157,6 @@ pkg/kubelet/container/testing
pkg/kubelet/dockershim pkg/kubelet/dockershim
pkg/kubelet/dockershim/libdocker pkg/kubelet/dockershim/libdocker
pkg/kubelet/dockershim/network pkg/kubelet/dockershim/network
pkg/kubelet/dockershim/network/cni
pkg/kubelet/dockershim/network/cni/testing pkg/kubelet/dockershim/network/cni/testing
pkg/kubelet/dockershim/network/hostport pkg/kubelet/dockershim/network/hostport
pkg/kubelet/dockershim/network/hostport/testing pkg/kubelet/dockershim/network/hostport/testing

View File

@ -40,6 +40,7 @@ import (
) )
const ( const (
// CNIPluginName is the name of CNI plugin
CNIPluginName = "cni" CNIPluginName = "cni"
// defaultSyncConfigPeriod is the default period to sync CNI config // defaultSyncConfigPeriod is the default period to sync CNI config
@ -95,8 +96,8 @@ type cniBandwidthEntry struct {
EgressBurst int `json:"egressBurst,omitempty"` EgressBurst int `json:"egressBurst,omitempty"`
} }
// cniIpRange maps to the standard CNI ip range Capability // cniIPRange maps to the standard CNI ip range Capability
type cniIpRange struct { type cniIPRange struct {
Subnet string `json:"subnet"` Subnet string `json:"subnet"`
} }
@ -112,11 +113,13 @@ type cniDNSConfig struct {
Options []string `json:"options,omitempty"` Options []string `json:"options,omitempty"`
} }
// SplitDirs : split dirs by ","
func SplitDirs(dirs string) []string { func SplitDirs(dirs string) []string {
// Use comma rather than colon to work better with Windows too // Use comma rather than colon to work better with Windows too
return strings.Split(dirs, ",") 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 { func ProbeNetworkPlugins(confDir, cacheDir string, binDirs []string) []network.NetworkPlugin {
old := binDirs old := binDirs
binDirs = make([]string, 0, len(binDirs)) binDirs = make([]string, 0, len(binDirs))
@ -416,7 +419,7 @@ func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string
} }
// Set the PodCIDR // Set the PodCIDR
rt.CapabilityArgs["ipRanges"] = [][]cniIpRange{{{Subnet: plugin.podCidr}}} rt.CapabilityArgs["ipRanges"] = [][]cniIPRange{{{Subnet: plugin.podCidr}}}
// Set dns capability args. // Set dns capability args.
if dnsOptions, ok := options["dns"]; ok { if dnsOptions, ok := options["dns"]; ok {

View File

@ -123,14 +123,14 @@ func tearDownPlugin(tmpDir string) {
} }
} }
type fakeNetworkHost struct { type FakeNetworkHost struct {
networktest.FakePortMappingGetter networktest.FakePortMappingGetter
kubeClient clientset.Interface kubeClient clientset.Interface
pods []*containertest.FakePod pods []*containertest.FakePod
} }
func NewFakeHost(kubeClient clientset.Interface, pods []*containertest.FakePod, ports map[string][]*hostport.PortMapping) *fakeNetworkHost { func NewFakeHost(kubeClient clientset.Interface, pods []*containertest.FakePod, ports map[string][]*hostport.PortMapping) *FakeNetworkHost {
host := &fakeNetworkHost{ host := &FakeNetworkHost{
networktest.FakePortMappingGetter{PortMaps: ports}, networktest.FakePortMappingGetter{PortMaps: ports},
kubeClient, kubeClient,
pods, pods,
@ -138,15 +138,15 @@ func NewFakeHost(kubeClient clientset.Interface, pods []*containertest.FakePod,
return host 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 return nil, false
} }
func (fnh *fakeNetworkHost) GetKubeClient() clientset.Interface { func (fnh *FakeNetworkHost) GetKubeClient() clientset.Interface {
return fnh.kubeClient 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 _, fp := range fnh.pods {
for _, c := range fp.Pod.Containers { for _, c := range fp.Pod.Containers {
if c.ID.ID == containerID { 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) return "", fmt.Errorf("container %q not found", containerID)
} }
func (fnh *fakeNetworkHost) SupportsLegacyFeatures() bool { func (fnh *FakeNetworkHost) SupportsLegacyFeatures() bool {
return true return true
} }
@ -281,7 +281,7 @@ func TestCNIPlugin(t *testing.T) {
RuntimeConfig struct { RuntimeConfig struct {
PortMappings []map[string]interface{} `json:"portMappings"` PortMappings []map[string]interface{} `json:"portMappings"`
Bandwidth map[string]interface{} `json:"bandwidth"` Bandwidth map[string]interface{} `json:"bandwidth"`
IpRanges [][]map[string]interface{} `json:"ipRanges"` IPRanges [][]map[string]interface{} `json:"IPRanges"`
} `json:"runtimeConfig"` } `json:"runtimeConfig"`
}{} }{}
inputBytes, inerr := ioutil.ReadFile(inputFile) 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) 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"}, {"subnet": "10.0.2.0/24"},
}, },
} }
if !reflect.DeepEqual(inputConfig.RuntimeConfig.IpRanges, expectedIpRange) { if !reflect.DeepEqual(inputConfig.RuntimeConfig.IPRanges, expectedIPRange) {
t.Errorf("mismatch in expected ipRange. expected %v got %v", expectedIpRange, inputConfig.RuntimeConfig.IpRanges) t.Errorf("mismatch in expected ipRange. expected %v got %v", expectedIPRange, inputConfig.RuntimeConfig.IPRanges)
} }
// Get its IP address // Get its IP address