mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #10639 from caseydavenport/master
Allow specification of a network plugins directory when starting kubelet
This commit is contained in:
		@@ -69,11 +69,11 @@ func ProbeVolumePlugins() []volume.VolumePlugin {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ProbeNetworkPlugins collects all compiled-in plugins
 | 
			
		||||
func ProbeNetworkPlugins() []network.NetworkPlugin {
 | 
			
		||||
func ProbeNetworkPlugins(pluginDir string) []network.NetworkPlugin {
 | 
			
		||||
	allPlugins := []network.NetworkPlugin{}
 | 
			
		||||
 | 
			
		||||
	// for each existing plugin, add to the list
 | 
			
		||||
	allPlugins = append(allPlugins, exec.ProbeNetworkPlugins()...)
 | 
			
		||||
	allPlugins = append(allPlugins, exec.ProbeNetworkPlugins(pluginDir)...)
 | 
			
		||||
 | 
			
		||||
	return allPlugins
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -103,6 +103,7 @@ type KubeletServer struct {
 | 
			
		||||
	ImageGCLowThresholdPercent     int
 | 
			
		||||
	LowDiskSpaceThresholdMB        int
 | 
			
		||||
	NetworkPluginName              string
 | 
			
		||||
	NetworkPluginDir               string
 | 
			
		||||
	CloudProvider                  string
 | 
			
		||||
	CloudConfigFile                string
 | 
			
		||||
	TLSCertFile                    string
 | 
			
		||||
@@ -171,6 +172,7 @@ func NewKubeletServer() *KubeletServer {
 | 
			
		||||
		ImageGCLowThresholdPercent:  80,
 | 
			
		||||
		LowDiskSpaceThresholdMB:     256,
 | 
			
		||||
		NetworkPluginName:           "",
 | 
			
		||||
		NetworkPluginDir:            "/usr/libexec/kubernetes/kubelet-plugins/net/exec/",
 | 
			
		||||
		HostNetworkSources:          kubelet.FileSource,
 | 
			
		||||
		CertDirectory:               "/var/run/kubernetes",
 | 
			
		||||
		NodeStatusUpdateFrequency:   10 * time.Second,
 | 
			
		||||
@@ -233,6 +235,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
 | 
			
		||||
	fs.IntVar(&s.ImageGCLowThresholdPercent, "image-gc-low-threshold", s.ImageGCLowThresholdPercent, "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Default: 80%%")
 | 
			
		||||
	fs.IntVar(&s.LowDiskSpaceThresholdMB, "low-diskspace-threshold-mb", s.LowDiskSpaceThresholdMB, "The absolute free disk space, in MB, to maintain. When disk space falls below this threshold, new pods would be rejected. Default: 256")
 | 
			
		||||
	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.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services.  Empty string for no provider.")
 | 
			
		||||
	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.ResourceContainer, "resource-container", s.ResourceContainer, "Absolute name of the resource-only container to create and run the Kubelet in (Default: /kubelet).")
 | 
			
		||||
@@ -350,7 +353,7 @@ func (s *KubeletServer) Run(_ []string) error {
 | 
			
		||||
		KubeClient:                     apiclient,
 | 
			
		||||
		MasterServiceNamespace:         s.MasterServiceNamespace,
 | 
			
		||||
		VolumePlugins:                  ProbeVolumePlugins(),
 | 
			
		||||
		NetworkPlugins:                 ProbeNetworkPlugins(),
 | 
			
		||||
		NetworkPlugins:                 ProbeNetworkPlugins(s.NetworkPluginDir),
 | 
			
		||||
		NetworkPluginName:              s.NetworkPluginName,
 | 
			
		||||
		StreamingConnectionIdleTimeout: s.StreamingConnectionIdleTimeout,
 | 
			
		||||
		TLSOptions:                     tlsOptions,
 | 
			
		||||
 
 | 
			
		||||
@@ -240,7 +240,7 @@ func (s *KubeletExecutorServer) Run(hks hyperkube.Interface, _ []string) error {
 | 
			
		||||
		KubeClient:                     apiclient,
 | 
			
		||||
		MasterServiceNamespace:         s.MasterServiceNamespace,
 | 
			
		||||
		VolumePlugins:                  app.ProbeVolumePlugins(),
 | 
			
		||||
		NetworkPlugins:                 app.ProbeNetworkPlugins(),
 | 
			
		||||
		NetworkPlugins:                 app.ProbeNetworkPlugins(s.NetworkPluginDir),
 | 
			
		||||
		NetworkPluginName:              s.NetworkPluginName,
 | 
			
		||||
		StreamingConnectionIdleTimeout: s.StreamingConnectionIdleTimeout,
 | 
			
		||||
		TLSOptions:                     tlsOptions,
 | 
			
		||||
 
 | 
			
		||||
@@ -70,14 +70,9 @@ const (
 | 
			
		||||
	initCmd     = "init"
 | 
			
		||||
	setUpCmd    = "setup"
 | 
			
		||||
	tearDownCmd = "teardown"
 | 
			
		||||
	execDir     = "/usr/libexec/kubernetes/kubelet-plugins/net/exec/"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func ProbeNetworkPlugins() []network.NetworkPlugin {
 | 
			
		||||
	return probeNetworkPluginsWithExecDir(execDir)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func probeNetworkPluginsWithExecDir(pluginDir string) []network.NetworkPlugin {
 | 
			
		||||
func ProbeNetworkPlugins(pluginDir string) []network.NetworkPlugin {
 | 
			
		||||
	execPlugins := []network.NetworkPlugin{}
 | 
			
		||||
 | 
			
		||||
	files, _ := ioutil.ReadDir(pluginDir)
 | 
			
		||||
 
 | 
			
		||||
@@ -72,7 +72,7 @@ func TestSelectPlugin(t *testing.T) {
 | 
			
		||||
	defer tearDownPlugin(pluginName)
 | 
			
		||||
	installPluginUnderTest(t, "", pluginName)
 | 
			
		||||
 | 
			
		||||
	plug, err := network.InitNetworkPlugin(probeNetworkPluginsWithExecDir(testPluginPath), pluginName, network.NewFakeHost(nil))
 | 
			
		||||
	plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("Failed to select the desired plugin: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -89,7 +89,7 @@ func TestSelectVendoredPlugin(t *testing.T) {
 | 
			
		||||
	installPluginUnderTest(t, vendor, pluginName)
 | 
			
		||||
 | 
			
		||||
	vendoredPluginName := fmt.Sprintf("%s/%s", vendor, pluginName)
 | 
			
		||||
	plug, err := network.InitNetworkPlugin(probeNetworkPluginsWithExecDir(testPluginPath), vendoredPluginName, network.NewFakeHost(nil))
 | 
			
		||||
	plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), vendoredPluginName, network.NewFakeHost(nil))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("Failed to select the desired plugin: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -105,7 +105,7 @@ func TestSelectWrongPlugin(t *testing.T) {
 | 
			
		||||
	installPluginUnderTest(t, "", pluginName)
 | 
			
		||||
 | 
			
		||||
	wrongPlugin := "abcd"
 | 
			
		||||
	plug, err := network.InitNetworkPlugin(probeNetworkPluginsWithExecDir(testPluginPath), wrongPlugin, network.NewFakeHost(nil))
 | 
			
		||||
	plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), wrongPlugin, network.NewFakeHost(nil))
 | 
			
		||||
	if plug != nil || err == nil {
 | 
			
		||||
		t.Errorf("Expected to see an error. Wrong plugin selected.")
 | 
			
		||||
	}
 | 
			
		||||
@@ -127,7 +127,7 @@ func TestPluginValidation(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
	f.Close()
 | 
			
		||||
 | 
			
		||||
	_, err = network.InitNetworkPlugin(probeNetworkPluginsWithExecDir(testPluginPath), pluginName, network.NewFakeHost(nil))
 | 
			
		||||
	_, err = network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		// we expected an error here because validation would have failed
 | 
			
		||||
		t.Errorf("Expected non-nil value.")
 | 
			
		||||
@@ -139,7 +139,7 @@ func TestPluginSetupHook(t *testing.T) {
 | 
			
		||||
	defer tearDownPlugin(pluginName)
 | 
			
		||||
	installPluginUnderTest(t, "", pluginName)
 | 
			
		||||
 | 
			
		||||
	plug, err := network.InitNetworkPlugin(probeNetworkPluginsWithExecDir(testPluginPath), pluginName, network.NewFakeHost(nil))
 | 
			
		||||
	plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
 | 
			
		||||
 | 
			
		||||
	err = plug.SetUpPod("podNamespace", "podName", "dockerid2345")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -161,7 +161,7 @@ func TestPluginTearDownHook(t *testing.T) {
 | 
			
		||||
	defer tearDownPlugin(pluginName)
 | 
			
		||||
	installPluginUnderTest(t, "", pluginName)
 | 
			
		||||
 | 
			
		||||
	plug, err := network.InitNetworkPlugin(probeNetworkPluginsWithExecDir(testPluginPath), pluginName, network.NewFakeHost(nil))
 | 
			
		||||
	plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
 | 
			
		||||
 | 
			
		||||
	err = plug.TearDownPod("podNamespace", "podName", "dockerid2345")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user