mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
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:
commit
8f7bb1fe71
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user