mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #10639 from caseydavenport/master
Allow specification of a network plugins directory when starting kubelet
This commit is contained in:
commit
b51b4e740f
@ -69,11 +69,11 @@ func ProbeVolumePlugins() []volume.VolumePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ProbeNetworkPlugins collects all compiled-in plugins
|
// ProbeNetworkPlugins collects all compiled-in plugins
|
||||||
func ProbeNetworkPlugins() []network.NetworkPlugin {
|
func ProbeNetworkPlugins(pluginDir string) []network.NetworkPlugin {
|
||||||
allPlugins := []network.NetworkPlugin{}
|
allPlugins := []network.NetworkPlugin{}
|
||||||
|
|
||||||
// for each existing plugin, add to the list
|
// for each existing plugin, add to the list
|
||||||
allPlugins = append(allPlugins, exec.ProbeNetworkPlugins()...)
|
allPlugins = append(allPlugins, exec.ProbeNetworkPlugins(pluginDir)...)
|
||||||
|
|
||||||
return allPlugins
|
return allPlugins
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,7 @@ type KubeletServer struct {
|
|||||||
ImageGCLowThresholdPercent int
|
ImageGCLowThresholdPercent int
|
||||||
LowDiskSpaceThresholdMB int
|
LowDiskSpaceThresholdMB int
|
||||||
NetworkPluginName string
|
NetworkPluginName string
|
||||||
|
NetworkPluginDir string
|
||||||
CloudProvider string
|
CloudProvider string
|
||||||
CloudConfigFile string
|
CloudConfigFile string
|
||||||
TLSCertFile string
|
TLSCertFile string
|
||||||
@ -171,6 +172,7 @@ func NewKubeletServer() *KubeletServer {
|
|||||||
ImageGCLowThresholdPercent: 80,
|
ImageGCLowThresholdPercent: 80,
|
||||||
LowDiskSpaceThresholdMB: 256,
|
LowDiskSpaceThresholdMB: 256,
|
||||||
NetworkPluginName: "",
|
NetworkPluginName: "",
|
||||||
|
NetworkPluginDir: "/usr/libexec/kubernetes/kubelet-plugins/net/exec/",
|
||||||
HostNetworkSources: kubelet.FileSource,
|
HostNetworkSources: kubelet.FileSource,
|
||||||
CertDirectory: "/var/run/kubernetes",
|
CertDirectory: "/var/run/kubernetes",
|
||||||
NodeStatusUpdateFrequency: 10 * time.Second,
|
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.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.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.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.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.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).")
|
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,
|
KubeClient: apiclient,
|
||||||
MasterServiceNamespace: s.MasterServiceNamespace,
|
MasterServiceNamespace: s.MasterServiceNamespace,
|
||||||
VolumePlugins: ProbeVolumePlugins(),
|
VolumePlugins: ProbeVolumePlugins(),
|
||||||
NetworkPlugins: ProbeNetworkPlugins(),
|
NetworkPlugins: ProbeNetworkPlugins(s.NetworkPluginDir),
|
||||||
NetworkPluginName: s.NetworkPluginName,
|
NetworkPluginName: s.NetworkPluginName,
|
||||||
StreamingConnectionIdleTimeout: s.StreamingConnectionIdleTimeout,
|
StreamingConnectionIdleTimeout: s.StreamingConnectionIdleTimeout,
|
||||||
TLSOptions: tlsOptions,
|
TLSOptions: tlsOptions,
|
||||||
|
@ -240,7 +240,7 @@ func (s *KubeletExecutorServer) Run(hks hyperkube.Interface, _ []string) error {
|
|||||||
KubeClient: apiclient,
|
KubeClient: apiclient,
|
||||||
MasterServiceNamespace: s.MasterServiceNamespace,
|
MasterServiceNamespace: s.MasterServiceNamespace,
|
||||||
VolumePlugins: app.ProbeVolumePlugins(),
|
VolumePlugins: app.ProbeVolumePlugins(),
|
||||||
NetworkPlugins: app.ProbeNetworkPlugins(),
|
NetworkPlugins: app.ProbeNetworkPlugins(s.NetworkPluginDir),
|
||||||
NetworkPluginName: s.NetworkPluginName,
|
NetworkPluginName: s.NetworkPluginName,
|
||||||
StreamingConnectionIdleTimeout: s.StreamingConnectionIdleTimeout,
|
StreamingConnectionIdleTimeout: s.StreamingConnectionIdleTimeout,
|
||||||
TLSOptions: tlsOptions,
|
TLSOptions: tlsOptions,
|
||||||
|
@ -70,14 +70,9 @@ const (
|
|||||||
initCmd = "init"
|
initCmd = "init"
|
||||||
setUpCmd = "setup"
|
setUpCmd = "setup"
|
||||||
tearDownCmd = "teardown"
|
tearDownCmd = "teardown"
|
||||||
execDir = "/usr/libexec/kubernetes/kubelet-plugins/net/exec/"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProbeNetworkPlugins() []network.NetworkPlugin {
|
func ProbeNetworkPlugins(pluginDir string) []network.NetworkPlugin {
|
||||||
return probeNetworkPluginsWithExecDir(execDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
func probeNetworkPluginsWithExecDir(pluginDir string) []network.NetworkPlugin {
|
|
||||||
execPlugins := []network.NetworkPlugin{}
|
execPlugins := []network.NetworkPlugin{}
|
||||||
|
|
||||||
files, _ := ioutil.ReadDir(pluginDir)
|
files, _ := ioutil.ReadDir(pluginDir)
|
||||||
|
@ -72,7 +72,7 @@ func TestSelectPlugin(t *testing.T) {
|
|||||||
defer tearDownPlugin(pluginName)
|
defer tearDownPlugin(pluginName)
|
||||||
installPluginUnderTest(t, "", 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 {
|
if err != nil {
|
||||||
t.Errorf("Failed to select the desired plugin: %v", err)
|
t.Errorf("Failed to select the desired plugin: %v", err)
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ func TestSelectVendoredPlugin(t *testing.T) {
|
|||||||
installPluginUnderTest(t, vendor, pluginName)
|
installPluginUnderTest(t, vendor, pluginName)
|
||||||
|
|
||||||
vendoredPluginName := fmt.Sprintf("%s/%s", 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 {
|
if err != nil {
|
||||||
t.Errorf("Failed to select the desired plugin: %v", err)
|
t.Errorf("Failed to select the desired plugin: %v", err)
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ func TestSelectWrongPlugin(t *testing.T) {
|
|||||||
installPluginUnderTest(t, "", pluginName)
|
installPluginUnderTest(t, "", pluginName)
|
||||||
|
|
||||||
wrongPlugin := "abcd"
|
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 {
|
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.")
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ func TestPluginValidation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
_, err = network.InitNetworkPlugin(probeNetworkPluginsWithExecDir(testPluginPath), pluginName, network.NewFakeHost(nil))
|
_, err = network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, network.NewFakeHost(nil))
|
||||||
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.")
|
||||||
@ -139,7 +139,7 @@ func TestPluginSetupHook(t *testing.T) {
|
|||||||
defer tearDownPlugin(pluginName)
|
defer tearDownPlugin(pluginName)
|
||||||
installPluginUnderTest(t, "", 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")
|
err = plug.SetUpPod("podNamespace", "podName", "dockerid2345")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -161,7 +161,7 @@ func TestPluginTearDownHook(t *testing.T) {
|
|||||||
defer tearDownPlugin(pluginName)
|
defer tearDownPlugin(pluginName)
|
||||||
installPluginUnderTest(t, "", 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")
|
err = plug.TearDownPod("podNamespace", "podName", "dockerid2345")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user