mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-03 11:48:15 +00:00
Add network-plugin-mtu option for MTU selection
MTU selection is difficult, and if there is a transport such as IPSEC in use may be impossible. So we allow specification of the MTU with the network-plugin-mtu flag, and we pass this down into the network provider. Currently implemented by kubenet.
This commit is contained in:
@@ -144,6 +144,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
|
|||||||
fs.DurationVar(&s.VolumeStatsAggPeriod.Duration, "volume-stats-agg-period", s.VolumeStatsAggPeriod.Duration, "Specifies interval for kubelet to calculate and cache the volume disk usage for all pods and volumes. To disable volume calculations, set to 0. Default: '1m'")
|
fs.DurationVar(&s.VolumeStatsAggPeriod.Duration, "volume-stats-agg-period", s.VolumeStatsAggPeriod.Duration, "Specifies interval for kubelet to calculate and cache the volume disk usage for all pods and volumes. To disable volume calculations, set to 0. Default: '1m'")
|
||||||
fs.StringVar(&s.NetworkPluginName, "network-plugin", s.NetworkPluginName, "<Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle")
|
fs.StringVar(&s.NetworkPluginName, "network-plugin", s.NetworkPluginName, "<Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle")
|
||||||
fs.StringVar(&s.NetworkPluginDir, "network-plugin-dir", s.NetworkPluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for network plugins")
|
fs.StringVar(&s.NetworkPluginDir, "network-plugin-dir", s.NetworkPluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for network plugins")
|
||||||
|
fs.Int32Var(&s.NetworkPluginMTU, "network-plugin-mtu", s.NetworkPluginMTU, "<Warning: Alpha feature> The MTU to be passed to the network plugin, to override the default")
|
||||||
fs.StringVar(&s.VolumePluginDir, "volume-plugin-dir", s.VolumePluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for additional third party volume plugins")
|
fs.StringVar(&s.VolumePluginDir, "volume-plugin-dir", s.VolumePluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for additional third party volume plugins")
|
||||||
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. By default, kubelet will attempt to auto-detect the cloud provider. Specify empty string for running with no cloud provider. [default=auto-detect]")
|
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. By default, kubelet will attempt to auto-detect the cloud provider. Specify empty string for running with no cloud provider. [default=auto-detect]")
|
||||||
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
|
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
|
||||||
|
|||||||
@@ -260,6 +260,7 @@ func UnsecuredKubeletConfig(s *options.KubeletServer) (*KubeletConfig, error) {
|
|||||||
MinimumGCAge: s.MinimumGCAge.Duration,
|
MinimumGCAge: s.MinimumGCAge.Duration,
|
||||||
Mounter: mounter,
|
Mounter: mounter,
|
||||||
NetworkPluginName: s.NetworkPluginName,
|
NetworkPluginName: s.NetworkPluginName,
|
||||||
|
NetworkPluginMTU: int(s.NetworkPluginMTU),
|
||||||
NetworkPlugins: ProbeNetworkPlugins(s.NetworkPluginDir),
|
NetworkPlugins: ProbeNetworkPlugins(s.NetworkPluginDir),
|
||||||
NodeLabels: s.NodeLabels,
|
NodeLabels: s.NodeLabels,
|
||||||
NodeStatusUpdateFrequency: s.NodeStatusUpdateFrequency.Duration,
|
NodeStatusUpdateFrequency: s.NodeStatusUpdateFrequency.Duration,
|
||||||
@@ -914,6 +915,7 @@ type KubeletConfig struct {
|
|||||||
MinimumGCAge time.Duration
|
MinimumGCAge time.Duration
|
||||||
Mounter mount.Interface
|
Mounter mount.Interface
|
||||||
NetworkPluginName string
|
NetworkPluginName string
|
||||||
|
NetworkPluginMTU int
|
||||||
NetworkPlugins []network.NetworkPlugin
|
NetworkPlugins []network.NetworkPlugin
|
||||||
NodeName string
|
NodeName string
|
||||||
NodeLabels map[string]string
|
NodeLabels map[string]string
|
||||||
@@ -1016,6 +1018,7 @@ func CreateAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.Pod
|
|||||||
kc.VolumePlugins,
|
kc.VolumePlugins,
|
||||||
kc.NetworkPlugins,
|
kc.NetworkPlugins,
|
||||||
kc.NetworkPluginName,
|
kc.NetworkPluginName,
|
||||||
|
kc.NetworkPluginMTU,
|
||||||
kc.StreamingConnectionIdleTimeout,
|
kc.StreamingConnectionIdleTimeout,
|
||||||
kc.Recorder,
|
kc.Recorder,
|
||||||
kc.CAdvisorInterface,
|
kc.CAdvisorInterface,
|
||||||
|
|||||||
@@ -340,6 +340,7 @@ minion-path-override
|
|||||||
namespace-sync-period
|
namespace-sync-period
|
||||||
network-plugin
|
network-plugin
|
||||||
network-plugin-dir
|
network-plugin-dir
|
||||||
|
network-plugin-mtu
|
||||||
no-headers
|
no-headers
|
||||||
no-suggestions
|
no-suggestions
|
||||||
node-cidr-mask-size
|
node-cidr-mask-size
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -252,6 +252,10 @@ type KubeletConfiguration struct {
|
|||||||
// networkPluginName is the name of the network plugin to be invoked for
|
// networkPluginName is the name of the network plugin to be invoked for
|
||||||
// various events in kubelet/pod lifecycle
|
// various events in kubelet/pod lifecycle
|
||||||
NetworkPluginName string `json:"networkPluginName"`
|
NetworkPluginName string `json:"networkPluginName"`
|
||||||
|
// networkPluginMTU is the MTU to be passed to the network plugin,
|
||||||
|
// and overrides the default MTU for cases where it cannot be automatically
|
||||||
|
// computed (such as IPSEC).
|
||||||
|
NetworkPluginMTU int32 `json:"networkPluginMTU"`
|
||||||
// networkPluginDir is the full path of the directory in which to search
|
// networkPluginDir is the full path of the directory in which to search
|
||||||
// for network plugins
|
// for network plugins
|
||||||
NetworkPluginDir string `json:"networkPluginDir"`
|
NetworkPluginDir string `json:"networkPluginDir"`
|
||||||
|
|||||||
@@ -310,6 +310,10 @@ type KubeletConfiguration struct {
|
|||||||
// networkPluginDir is the full path of the directory in which to search
|
// networkPluginDir is the full path of the directory in which to search
|
||||||
// for network plugins
|
// for network plugins
|
||||||
NetworkPluginDir string `json:"networkPluginDir"`
|
NetworkPluginDir string `json:"networkPluginDir"`
|
||||||
|
// networkPluginMTU is the MTU to be passed to the network plugin,
|
||||||
|
// and overrides the default MTU for cases where it cannot be automatically
|
||||||
|
// computed (such as IPSEC).
|
||||||
|
NetworkPluginMTU int32 `json:"networkPluginMTU"`
|
||||||
// volumePluginDir is the full path of the directory in which to search
|
// volumePluginDir is the full path of the directory in which to search
|
||||||
// for additional third party volume plugins
|
// for additional third party volume plugins
|
||||||
VolumePluginDir string `json:"volumePluginDir"`
|
VolumePluginDir string `json:"volumePluginDir"`
|
||||||
|
|||||||
@@ -233,6 +233,7 @@ func autoConvert_v1alpha1_KubeletConfiguration_To_componentconfig_KubeletConfigu
|
|||||||
out.VolumeStatsAggPeriod = in.VolumeStatsAggPeriod
|
out.VolumeStatsAggPeriod = in.VolumeStatsAggPeriod
|
||||||
out.NetworkPluginName = in.NetworkPluginName
|
out.NetworkPluginName = in.NetworkPluginName
|
||||||
out.NetworkPluginDir = in.NetworkPluginDir
|
out.NetworkPluginDir = in.NetworkPluginDir
|
||||||
|
out.NetworkPluginMTU = in.NetworkPluginMTU
|
||||||
out.VolumePluginDir = in.VolumePluginDir
|
out.VolumePluginDir = in.VolumePluginDir
|
||||||
out.CloudProvider = in.CloudProvider
|
out.CloudProvider = in.CloudProvider
|
||||||
out.CloudConfigFile = in.CloudConfigFile
|
out.CloudConfigFile = in.CloudConfigFile
|
||||||
@@ -408,6 +409,7 @@ func autoConvert_componentconfig_KubeletConfiguration_To_v1alpha1_KubeletConfigu
|
|||||||
out.LowDiskSpaceThresholdMB = in.LowDiskSpaceThresholdMB
|
out.LowDiskSpaceThresholdMB = in.LowDiskSpaceThresholdMB
|
||||||
out.VolumeStatsAggPeriod = in.VolumeStatsAggPeriod
|
out.VolumeStatsAggPeriod = in.VolumeStatsAggPeriod
|
||||||
out.NetworkPluginName = in.NetworkPluginName
|
out.NetworkPluginName = in.NetworkPluginName
|
||||||
|
out.NetworkPluginMTU = in.NetworkPluginMTU
|
||||||
out.NetworkPluginDir = in.NetworkPluginDir
|
out.NetworkPluginDir = in.NetworkPluginDir
|
||||||
out.VolumePluginDir = in.VolumePluginDir
|
out.VolumePluginDir = in.VolumePluginDir
|
||||||
out.CloudProvider = in.CloudProvider
|
out.CloudProvider = in.CloudProvider
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ func DeepCopy_v1alpha1_KubeletConfiguration(in interface{}, out interface{}, c *
|
|||||||
out.VolumeStatsAggPeriod = in.VolumeStatsAggPeriod
|
out.VolumeStatsAggPeriod = in.VolumeStatsAggPeriod
|
||||||
out.NetworkPluginName = in.NetworkPluginName
|
out.NetworkPluginName = in.NetworkPluginName
|
||||||
out.NetworkPluginDir = in.NetworkPluginDir
|
out.NetworkPluginDir = in.NetworkPluginDir
|
||||||
|
out.NetworkPluginMTU = in.NetworkPluginMTU
|
||||||
out.VolumePluginDir = in.VolumePluginDir
|
out.VolumePluginDir = in.VolumePluginDir
|
||||||
out.CloudProvider = in.CloudProvider
|
out.CloudProvider = in.CloudProvider
|
||||||
out.CloudConfigFile = in.CloudConfigFile
|
out.CloudConfigFile = in.CloudConfigFile
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ func DeepCopy_componentconfig_KubeletConfiguration(in interface{}, out interface
|
|||||||
out.LowDiskSpaceThresholdMB = in.LowDiskSpaceThresholdMB
|
out.LowDiskSpaceThresholdMB = in.LowDiskSpaceThresholdMB
|
||||||
out.VolumeStatsAggPeriod = in.VolumeStatsAggPeriod
|
out.VolumeStatsAggPeriod = in.VolumeStatsAggPeriod
|
||||||
out.NetworkPluginName = in.NetworkPluginName
|
out.NetworkPluginName = in.NetworkPluginName
|
||||||
|
out.NetworkPluginMTU = in.NetworkPluginMTU
|
||||||
out.NetworkPluginDir = in.NetworkPluginDir
|
out.NetworkPluginDir = in.NetworkPluginDir
|
||||||
out.VolumePluginDir = in.VolumePluginDir
|
out.VolumePluginDir = in.VolumePluginDir
|
||||||
out.CloudProvider = in.CloudProvider
|
out.CloudProvider = in.CloudProvider
|
||||||
|
|||||||
@@ -122,7 +122,8 @@ func createTestDockerManager(fakeHTTPClient *fakeHTTP, fakeDocker *FakeDockerCli
|
|||||||
"",
|
"",
|
||||||
nettest.NewFakeHost(nil),
|
nettest.NewFakeHost(nil),
|
||||||
componentconfig.HairpinNone,
|
componentconfig.HairpinNone,
|
||||||
"10.0.0.0/8")
|
"10.0.0.0/8",
|
||||||
|
network.UseDefaultMTU)
|
||||||
|
|
||||||
dockerManager := NewFakeDockerManager(
|
dockerManager := NewFakeDockerManager(
|
||||||
fakeDocker,
|
fakeDocker,
|
||||||
|
|||||||
@@ -718,7 +718,7 @@ func TestFindContainersByPod(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
fakeClient := NewFakeDockerClient()
|
fakeClient := NewFakeDockerClient()
|
||||||
np, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8")
|
np, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||||
// image back-off is set to nil, this test should not pull images
|
// image back-off is set to nil, this test should not pull images
|
||||||
containerManager := NewFakeDockerManager(fakeClient, &record.FakeRecorder{}, nil, nil, &cadvisorapi.MachineInfo{}, "", 0, 0, "", &containertest.FakeOS{}, np, nil, nil, nil)
|
containerManager := NewFakeDockerManager(fakeClient, &record.FakeRecorder{}, nil, nil, &cadvisorapi.MachineInfo{}, "", 0, 0, "", &containertest.FakeOS{}, np, nil, nil, nil)
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ func NewMainKubelet(
|
|||||||
volumePlugins []volume.VolumePlugin,
|
volumePlugins []volume.VolumePlugin,
|
||||||
networkPlugins []network.NetworkPlugin,
|
networkPlugins []network.NetworkPlugin,
|
||||||
networkPluginName string,
|
networkPluginName string,
|
||||||
|
networkPluginMTU int,
|
||||||
streamingConnectionIdleTimeout time.Duration,
|
streamingConnectionIdleTimeout time.Duration,
|
||||||
recorder record.EventRecorder,
|
recorder record.EventRecorder,
|
||||||
cadvisorInterface cadvisor.Interface,
|
cadvisorInterface cadvisor.Interface,
|
||||||
@@ -399,7 +400,7 @@ func NewMainKubelet(
|
|||||||
}
|
}
|
||||||
glog.Infof("Hairpin mode set to %q", klet.hairpinMode)
|
glog.Infof("Hairpin mode set to %q", klet.hairpinMode)
|
||||||
|
|
||||||
if plug, err := network.InitNetworkPlugin(networkPlugins, networkPluginName, &networkHost{klet}, klet.hairpinMode, klet.nonMasqueradeCIDR); err != nil {
|
if plug, err := network.InitNetworkPlugin(networkPlugins, networkPluginName, &networkHost{klet}, klet.hairpinMode, klet.nonMasqueradeCIDR, networkPluginMTU); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
klet.networkPlugin = plug
|
klet.networkPlugin = plug
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ func newTestKubeletWithImageList(
|
|||||||
kubelet.nodeName = testKubeletHostname
|
kubelet.nodeName = testKubeletHostname
|
||||||
kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime)
|
kubelet.runtimeState = newRuntimeState(maxWaitForContainerRuntime)
|
||||||
kubelet.runtimeState.setNetworkState(nil)
|
kubelet.runtimeState.setNetworkState(nil)
|
||||||
kubelet.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil), componentconfig.HairpinNone, kubelet.nonMasqueradeCIDR)
|
kubelet.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil), componentconfig.HairpinNone, kubelet.nonMasqueradeCIDR, 1440)
|
||||||
if tempDir, err := ioutil.TempDir("/tmp", "kubelet_test."); err != nil {
|
if tempDir, err := ioutil.TempDir("/tmp", "kubelet_test."); err != nil {
|
||||||
t.Fatalf("can't make a temp rootdir: %v", err)
|
t.Fatalf("can't make a temp rootdir: %v", err)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ func createTestRuntimeManager() (*apitest.FakeRuntimeService, *apitest.FakeImage
|
|||||||
nettest.NewFakeHost(nil),
|
nettest.NewFakeHost(nil),
|
||||||
componentconfig.HairpinNone,
|
componentconfig.HairpinNone,
|
||||||
"10.0.0.0/8",
|
"10.0.0.0/8",
|
||||||
|
network.UseDefaultMTU,
|
||||||
)
|
)
|
||||||
osInterface := &containertest.FakeOS{}
|
osInterface := &containertest.FakeOS{}
|
||||||
manager, err := NewFakeKubeRuntimeManager(fakeRuntimeService, fakeImageService, networkPlugin, osInterface)
|
manager, err := NewFakeKubeRuntimeManager(fakeRuntimeService, fakeImageService, networkPlugin, osInterface)
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ func getLoNetwork(vendorDirPrefix string) *cniNetwork {
|
|||||||
return loNetwork
|
return loNetwork
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) Init(host network.Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string) error {
|
func (plugin *cniNetworkPlugin) Init(host network.Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string, mtu int) error {
|
||||||
var err error
|
var err error
|
||||||
plugin.nsenterPath, err = plugin.execer.LookPath("nsenter")
|
plugin.nsenterPath, err = plugin.execer.LookPath("nsenter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ func TestCNIPlugin(t *testing.T) {
|
|||||||
|
|
||||||
mockLoCNI.On("AddNetwork", cniPlugin.loNetwork.NetworkConfig, mock.AnythingOfType("*libcni.RuntimeConf")).Return(&cnitypes.Result{IP4: &cnitypes.IPConfig{IP: net.IPNet{IP: []byte{127, 0, 0, 1}}}}, nil)
|
mockLoCNI.On("AddNetwork", cniPlugin.loNetwork.NetworkConfig, mock.AnythingOfType("*libcni.RuntimeConf")).Return(&cnitypes.Result{IP4: &cnitypes.IPConfig{IP: net.IPNet{IP: []byte{127, 0, 0, 1}}}}, nil)
|
||||||
|
|
||||||
plug, err := network.InitNetworkPlugin(plugins, "cni", NewFakeHost(nil, pods), componentconfig.HairpinNone, "10.0.0.0/8")
|
plug, err := network.InitNetworkPlugin(plugins, "cni", NewFakeHost(nil, pods), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to select the desired plugin: %v", err)
|
t.Fatalf("Failed to select the desired plugin: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ func ProbeNetworkPlugins(pluginDir string) []network.NetworkPlugin {
|
|||||||
return execPlugins
|
return execPlugins
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *execNetworkPlugin) Init(host network.Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string) error {
|
func (plugin *execNetworkPlugin) Init(host network.Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string, mtu int) error {
|
||||||
err := plugin.validate()
|
err := plugin.validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ func TestSelectPlugin(t *testing.T) {
|
|||||||
|
|
||||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||||
|
|
||||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8")
|
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to select the desired plugin: %v", err)
|
t.Errorf("Failed to select the desired plugin: %v", err)
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ func TestSelectVendoredPlugin(t *testing.T) {
|
|||||||
installPluginUnderTest(t, vendor, testPluginPath, pluginName, nil)
|
installPluginUnderTest(t, vendor, testPluginPath, pluginName, nil)
|
||||||
|
|
||||||
vendoredPluginName := fmt.Sprintf("%s/%s", vendor, pluginName)
|
vendoredPluginName := fmt.Sprintf("%s/%s", vendor, pluginName)
|
||||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), vendoredPluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8")
|
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), vendoredPluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to select the desired plugin: %v", err)
|
t.Errorf("Failed to select the desired plugin: %v", err)
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ func TestSelectWrongPlugin(t *testing.T) {
|
|||||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||||
|
|
||||||
wrongPlugin := "abcd"
|
wrongPlugin := "abcd"
|
||||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), wrongPlugin, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8")
|
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), wrongPlugin, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||||
if plug != nil || err == nil {
|
if plug != nil || err == nil {
|
||||||
t.Errorf("Expected to see an error. Wrong plugin selected.")
|
t.Errorf("Expected to see an error. Wrong plugin selected.")
|
||||||
}
|
}
|
||||||
@@ -206,7 +206,7 @@ func TestPluginValidation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
_, err = network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8")
|
_, err = network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// we expected an error here because validation would have failed
|
// we expected an error here because validation would have failed
|
||||||
t.Errorf("Expected non-nil value.")
|
t.Errorf("Expected non-nil value.")
|
||||||
@@ -224,7 +224,7 @@ func TestPluginSetupHook(t *testing.T) {
|
|||||||
|
|
||||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||||
|
|
||||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8")
|
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||||
|
|
||||||
err = plug.SetUpPod("podNamespace", "podName", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
|
err = plug.SetUpPod("podNamespace", "podName", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -252,7 +252,7 @@ func TestPluginTearDownHook(t *testing.T) {
|
|||||||
|
|
||||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||||
|
|
||||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8")
|
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||||
|
|
||||||
err = plug.TearDownPod("podNamespace", "podName", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
|
err = plug.TearDownPod("podNamespace", "podName", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -280,7 +280,7 @@ func TestPluginStatusHook(t *testing.T) {
|
|||||||
|
|
||||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||||
|
|
||||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8")
|
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||||
|
|
||||||
ip, err := plug.GetPodNetworkStatus("namespace", "name", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
|
ip, err := plug.GetPodNetworkStatus("namespace", "name", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -316,7 +316,7 @@ func TestPluginStatusHookIPv6(t *testing.T) {
|
|||||||
}
|
}
|
||||||
installPluginUnderTest(t, "", testPluginPath, pluginName, execTemplate)
|
installPluginUnderTest(t, "", testPluginPath, pluginName, execTemplate)
|
||||||
|
|
||||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8")
|
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("InitNetworkPlugin() failed: %v", err)
|
t.Errorf("InitNetworkPlugin() failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ const (
|
|||||||
DefaultCNIDir = "/opt/cni/bin"
|
DefaultCNIDir = "/opt/cni/bin"
|
||||||
|
|
||||||
sysctlBridgeCallIptables = "net/bridge/bridge-nf-call-iptables"
|
sysctlBridgeCallIptables = "net/bridge/bridge-nf-call-iptables"
|
||||||
|
|
||||||
|
// fallbackMTU is used if an MTU is not specified, and we cannot determine the MTU
|
||||||
|
fallbackMTU = 1460
|
||||||
)
|
)
|
||||||
|
|
||||||
type kubenetNetworkPlugin struct {
|
type kubenetNetworkPlugin struct {
|
||||||
@@ -65,7 +68,7 @@ type kubenetNetworkPlugin struct {
|
|||||||
bandwidthShaper bandwidth.BandwidthShaper
|
bandwidthShaper bandwidth.BandwidthShaper
|
||||||
mu sync.Mutex //Mutex for protecting podIPs map, netConfig, and shaper initialization
|
mu sync.Mutex //Mutex for protecting podIPs map, netConfig, and shaper initialization
|
||||||
podIPs map[kubecontainer.ContainerID]string
|
podIPs map[kubecontainer.ContainerID]string
|
||||||
MTU int
|
mtu int
|
||||||
execer utilexec.Interface
|
execer utilexec.Interface
|
||||||
nsenterPath string
|
nsenterPath string
|
||||||
hairpinMode componentconfig.HairpinMode
|
hairpinMode componentconfig.HairpinMode
|
||||||
@@ -82,19 +85,20 @@ func NewPlugin(networkPluginDir string) network.NetworkPlugin {
|
|||||||
protocol := utiliptables.ProtocolIpv4
|
protocol := utiliptables.ProtocolIpv4
|
||||||
execer := utilexec.New()
|
execer := utilexec.New()
|
||||||
dbus := utildbus.New()
|
dbus := utildbus.New()
|
||||||
|
sysctl := utilsysctl.New()
|
||||||
iptInterface := utiliptables.New(execer, dbus, protocol)
|
iptInterface := utiliptables.New(execer, dbus, protocol)
|
||||||
return &kubenetNetworkPlugin{
|
return &kubenetNetworkPlugin{
|
||||||
podIPs: make(map[kubecontainer.ContainerID]string),
|
podIPs: make(map[kubecontainer.ContainerID]string),
|
||||||
MTU: 1460, //TODO: don't hardcode this
|
|
||||||
execer: utilexec.New(),
|
execer: utilexec.New(),
|
||||||
iptables: iptInterface,
|
iptables: iptInterface,
|
||||||
|
sysctl: sysctl,
|
||||||
vendorDir: networkPluginDir,
|
vendorDir: networkPluginDir,
|
||||||
hostportHandler: hostport.NewHostportHandler(),
|
hostportHandler: hostport.NewHostportHandler(),
|
||||||
nonMasqueradeCIDR: "10.0.0.0/8",
|
nonMasqueradeCIDR: "10.0.0.0/8",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *kubenetNetworkPlugin) Init(host network.Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string) error {
|
func (plugin *kubenetNetworkPlugin) Init(host network.Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string, mtu int) error {
|
||||||
plugin.host = host
|
plugin.host = host
|
||||||
plugin.hairpinMode = hairpinMode
|
plugin.hairpinMode = hairpinMode
|
||||||
plugin.nonMasqueradeCIDR = nonMasqueradeCIDR
|
plugin.nonMasqueradeCIDR = nonMasqueradeCIDR
|
||||||
@@ -102,11 +106,16 @@ func (plugin *kubenetNetworkPlugin) Init(host network.Host, hairpinMode componen
|
|||||||
Path: []string{DefaultCNIDir, plugin.vendorDir},
|
Path: []string{DefaultCNIDir, plugin.vendorDir},
|
||||||
}
|
}
|
||||||
|
|
||||||
if link, err := findMinMTU(); err == nil {
|
if mtu == network.UseDefaultMTU {
|
||||||
plugin.MTU = link.MTU
|
if link, err := findMinMTU(); err == nil {
|
||||||
glog.V(5).Infof("Using interface %s MTU %d as bridge MTU", link.Name, link.MTU)
|
plugin.mtu = link.MTU
|
||||||
|
glog.V(5).Infof("Using interface %s MTU %d as bridge MTU", link.Name, link.MTU)
|
||||||
|
} else {
|
||||||
|
plugin.mtu = fallbackMTU
|
||||||
|
glog.Warningf("Failed to find default bridge MTU, using %d: %v", fallbackMTU, err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
glog.Warningf("Failed to find default bridge MTU: %v", err)
|
plugin.mtu = mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since this plugin uses a Linux bridge, set bridge-nf-call-iptables=1
|
// Since this plugin uses a Linux bridge, set bridge-nf-call-iptables=1
|
||||||
@@ -224,7 +233,7 @@ func (plugin *kubenetNetworkPlugin) Event(name string, details map[string]interf
|
|||||||
// Set bridge address to first address in IPNet
|
// Set bridge address to first address in IPNet
|
||||||
cidr.IP.To4()[3] += 1
|
cidr.IP.To4()[3] += 1
|
||||||
|
|
||||||
json := fmt.Sprintf(NET_CONFIG_TEMPLATE, BridgeName, plugin.MTU, network.DefaultInterfaceName, setHairpin, podCIDR, cidr.IP.String())
|
json := fmt.Sprintf(NET_CONFIG_TEMPLATE, BridgeName, plugin.mtu, network.DefaultInterfaceName, setHairpin, podCIDR, cidr.IP.String())
|
||||||
glog.V(2).Infof("CNI network config set to %v", json)
|
glog.V(2).Infof("CNI network config set to %v", json)
|
||||||
plugin.netConfig, err = libcni.ConfFromBytes([]byte(json))
|
plugin.netConfig, err = libcni.ConfFromBytes([]byte(json))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
||||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/network/cni/testing"
|
"k8s.io/kubernetes/pkg/kubelet/network/cni/testing"
|
||||||
@@ -32,6 +33,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/util/bandwidth"
|
"k8s.io/kubernetes/pkg/util/bandwidth"
|
||||||
"k8s.io/kubernetes/pkg/util/exec"
|
"k8s.io/kubernetes/pkg/util/exec"
|
||||||
ipttest "k8s.io/kubernetes/pkg/util/iptables/testing"
|
ipttest "k8s.io/kubernetes/pkg/util/iptables/testing"
|
||||||
|
sysctltest "k8s.io/kubernetes/pkg/util/sysctl/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// test it fulfills the NetworkPlugin interface
|
// test it fulfills the NetworkPlugin interface
|
||||||
@@ -41,7 +43,7 @@ func newFakeKubenetPlugin(initMap map[kubecontainer.ContainerID]string, execer e
|
|||||||
return &kubenetNetworkPlugin{
|
return &kubenetNetworkPlugin{
|
||||||
podIPs: initMap,
|
podIPs: initMap,
|
||||||
execer: execer,
|
execer: execer,
|
||||||
MTU: 1460,
|
mtu: 1460,
|
||||||
host: host,
|
host: host,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,4 +159,43 @@ func TestTeardownCallsShaper(t *testing.T) {
|
|||||||
mockcni.AssertExpectations(t)
|
mockcni.AssertExpectations(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestInit tests that a `Init` call with an MTU sets the MTU
|
||||||
|
func TestInit_MTU(t *testing.T) {
|
||||||
|
var fakeCmds []exec.FakeCommandAction
|
||||||
|
{
|
||||||
|
// modprobe br-netfilter
|
||||||
|
fCmd := exec.FakeCmd{
|
||||||
|
CombinedOutputScript: []exec.FakeCombinedOutputAction{
|
||||||
|
func() ([]byte, error) {
|
||||||
|
return make([]byte, 0), nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
fakeCmds = append(fakeCmds, func(cmd string, args ...string) exec.Cmd {
|
||||||
|
return exec.InitFakeCmd(&fCmd, cmd, args...)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fexec := &exec.FakeExec{
|
||||||
|
CommandScript: fakeCmds,
|
||||||
|
LookPathFunc: func(file string) (string, error) {
|
||||||
|
return fmt.Sprintf("/fake-bin/%s", file), nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
fhost := nettest.NewFakeHost(nil)
|
||||||
|
kubenet := newFakeKubenetPlugin(map[kubecontainer.ContainerID]string{}, fexec, fhost)
|
||||||
|
kubenet.iptables = ipttest.NewFake()
|
||||||
|
|
||||||
|
sysctl := sysctltest.NewFake()
|
||||||
|
sysctl.Settings["net/bridge/bridge-nf-call-iptables"] = 0
|
||||||
|
kubenet.sysctl = sysctl
|
||||||
|
|
||||||
|
if err := kubenet.Init(nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", 1234); err != nil {
|
||||||
|
t.Fatalf("Unexpected error in Init: %v", err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, 1234, kubenet.mtu, "kubenet.mtu should have been set")
|
||||||
|
assert.Equal(t, 1, sysctl.Settings["net/bridge/bridge-nf-call-iptables"], "net/bridge/bridge-nf-call-iptables sysctl should have been set")
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: add unit test for each implementation of network plugin interface
|
//TODO: add unit test for each implementation of network plugin interface
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func (_mr *_MockNetworkPluginRecorder) GetPodNetworkStatus(arg0, arg1, arg2 inte
|
|||||||
return _mr.mock.ctrl.RecordCall(_mr.mock, "GetPodNetworkStatus", arg0, arg1, arg2)
|
return _mr.mock.ctrl.RecordCall(_mr.mock, "GetPodNetworkStatus", arg0, arg1, arg2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_m *MockNetworkPlugin) Init(_param0 network.Host, _param1 componentconfig.HairpinMode, nonMasqueradeCIDR string) error {
|
func (_m *MockNetworkPlugin) Init(_param0 network.Host, _param1 componentconfig.HairpinMode, nonMasqueradeCIDR string, mtu int) error {
|
||||||
ret := _m.ctrl.Call(_m, "Init", _param0, _param1)
|
ret := _m.ctrl.Call(_m, "Init", _param0, _param1)
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
return ret0
|
return ret0
|
||||||
|
|||||||
@@ -18,3 +18,7 @@ package network
|
|||||||
|
|
||||||
// TODO: Consider making this value configurable.
|
// TODO: Consider making this value configurable.
|
||||||
const DefaultInterfaceName = "eth0"
|
const DefaultInterfaceName = "eth0"
|
||||||
|
|
||||||
|
// UseDefaultMTU is a marker value that indicates the plugin should determine its own MTU
|
||||||
|
// It is the zero value, so a non-initialized value will mean "UseDefault"
|
||||||
|
const UseDefaultMTU = 0
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const (
|
|||||||
type NetworkPlugin interface {
|
type NetworkPlugin interface {
|
||||||
// Init initializes the plugin. This will be called exactly once
|
// Init initializes the plugin. This will be called exactly once
|
||||||
// before any other methods are called.
|
// before any other methods are called.
|
||||||
Init(host Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string) error
|
Init(host Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string, mtu int) error
|
||||||
|
|
||||||
// Called on various events like:
|
// Called on various events like:
|
||||||
// NET_PLUGIN_EVENT_POD_CIDR_CHANGE
|
// NET_PLUGIN_EVENT_POD_CIDR_CHANGE
|
||||||
@@ -105,11 +105,11 @@ type Host interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InitNetworkPlugin inits the plugin that matches networkPluginName. Plugins must have unique names.
|
// InitNetworkPlugin inits the plugin that matches networkPluginName. Plugins must have unique names.
|
||||||
func InitNetworkPlugin(plugins []NetworkPlugin, networkPluginName string, host Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string) (NetworkPlugin, error) {
|
func InitNetworkPlugin(plugins []NetworkPlugin, networkPluginName string, host Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string, mtu int) (NetworkPlugin, error) {
|
||||||
if networkPluginName == "" {
|
if networkPluginName == "" {
|
||||||
// default to the no_op plugin
|
// default to the no_op plugin
|
||||||
plug := &NoopNetworkPlugin{}
|
plug := &NoopNetworkPlugin{}
|
||||||
if err := plug.Init(host, hairpinMode, nonMasqueradeCIDR); err != nil {
|
if err := plug.Init(host, hairpinMode, nonMasqueradeCIDR, mtu); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return plug, nil
|
return plug, nil
|
||||||
@@ -134,7 +134,7 @@ func InitNetworkPlugin(plugins []NetworkPlugin, networkPluginName string, host H
|
|||||||
|
|
||||||
chosenPlugin := pluginMap[networkPluginName]
|
chosenPlugin := pluginMap[networkPluginName]
|
||||||
if chosenPlugin != nil {
|
if chosenPlugin != nil {
|
||||||
err := chosenPlugin.Init(host, hairpinMode, nonMasqueradeCIDR)
|
err := chosenPlugin.Init(host, hairpinMode, nonMasqueradeCIDR, mtu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
allErrs = append(allErrs, fmt.Errorf("Network plugin %q failed init: %v", networkPluginName, err))
|
allErrs = append(allErrs, fmt.Errorf("Network plugin %q failed init: %v", networkPluginName, err))
|
||||||
} else {
|
} else {
|
||||||
@@ -156,7 +156,7 @@ type NoopNetworkPlugin struct {
|
|||||||
|
|
||||||
const sysctlBridgeCallIptables = "net/bridge/bridge-nf-call-iptables"
|
const sysctlBridgeCallIptables = "net/bridge/bridge-nf-call-iptables"
|
||||||
|
|
||||||
func (plugin *NoopNetworkPlugin) Init(host Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string) error {
|
func (plugin *NoopNetworkPlugin) Init(host Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string, mtu int) error {
|
||||||
// Set bridge-nf-call-iptables=1 to maintain compatibility with older
|
// Set bridge-nf-call-iptables=1 to maintain compatibility with older
|
||||||
// kubernetes versions to ensure the iptables-based kube proxy functions
|
// kubernetes versions to ensure the iptables-based kube proxy functions
|
||||||
// correctly. Other plugins are responsible for setting this correctly
|
// correctly. Other plugins are responsible for setting this correctly
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
func TestSelectDefaultPlugin(t *testing.T) {
|
func TestSelectDefaultPlugin(t *testing.T) {
|
||||||
all_plugins := []NetworkPlugin{}
|
all_plugins := []NetworkPlugin{}
|
||||||
plug, err := InitNetworkPlugin(all_plugins, "", nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8")
|
plug, err := InitNetworkPlugin(all_plugins, "", nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", UseDefaultMTU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error in selecting default plugin: %v", err)
|
t.Fatalf("Unexpected error in selecting default plugin: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ func TestRunOnce(t *testing.T) {
|
|||||||
kb.getPodsDir(),
|
kb.getPodsDir(),
|
||||||
kb.recorder)
|
kb.recorder)
|
||||||
|
|
||||||
kb.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil), componentconfig.HairpinNone, kb.nonMasqueradeCIDR)
|
kb.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", nettest.NewFakeHost(nil), componentconfig.HairpinNone, kb.nonMasqueradeCIDR, network.UseDefaultMTU)
|
||||||
// TODO: Factor out "StatsProvider" from Kubelet so we don't have a cyclic dependency
|
// TODO: Factor out "StatsProvider" from Kubelet so we don't have a cyclic dependency
|
||||||
volumeStatsAggPeriod := time.Second * 10
|
volumeStatsAggPeriod := time.Second * 10
|
||||||
kb.resourceAnalyzer = stats.NewResourceAnalyzer(kb, volumeStatsAggPeriod, kb.containerRuntime)
|
kb.resourceAnalyzer = stats.NewResourceAnalyzer(kb, volumeStatsAggPeriod, kb.containerRuntime)
|
||||||
|
|||||||
Reference in New Issue
Block a user