mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
Add options to set CNI config and binary directories
Also make clearer the function of --network-plugin-dir when using CNI
This commit is contained in:
parent
dc529a03b1
commit
4e961e2bf5
@ -147,7 +147,9 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
|
|||||||
fs.Int32Var(&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.Int32Var(&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.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 or CNI config")
|
||||||
|
fs.StringVar(&s.CNIConfDir, "cni-conf-dir", s.CNIConfDir, "<Warning: Alpha feature> The full path of the directory in which to search for CNI config files. Default: /etc/cni/net.d")
|
||||||
|
fs.StringVar(&s.CNIBinDir, "cni-bin-dir", s.CNIBinDir, "<Warning: Alpha feature> The full path of the directory in which to search for CNI plugin binaries. Default: /opt/cni/bin")
|
||||||
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. Set to 0 to use the default 1460 MTU.")
|
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. Set to 0 to use the default 1460 MTU.")
|
||||||
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]")
|
||||||
|
@ -90,12 +90,16 @@ func ProbeVolumePlugins(pluginDir string) []volume.VolumePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ProbeNetworkPlugins collects all compiled-in plugins
|
// ProbeNetworkPlugins collects all compiled-in plugins
|
||||||
func ProbeNetworkPlugins(pluginDir string) []network.NetworkPlugin {
|
func ProbeNetworkPlugins(pluginDir, cniConfDir, cniBinDir string) []network.NetworkPlugin {
|
||||||
allPlugins := []network.NetworkPlugin{}
|
allPlugins := []network.NetworkPlugin{}
|
||||||
|
|
||||||
|
// for backwards-compat, allow pluginDir as a source of CNI config files
|
||||||
|
if cniConfDir == "" {
|
||||||
|
cniConfDir = pluginDir
|
||||||
|
}
|
||||||
// for each existing plugin, add to the list
|
// for each existing plugin, add to the list
|
||||||
allPlugins = append(allPlugins, exec.ProbeNetworkPlugins(pluginDir)...)
|
allPlugins = append(allPlugins, exec.ProbeNetworkPlugins(pluginDir)...)
|
||||||
allPlugins = append(allPlugins, cni.ProbeNetworkPlugins(pluginDir)...)
|
allPlugins = append(allPlugins, cni.ProbeNetworkPlugins(cniConfDir, cniBinDir)...)
|
||||||
allPlugins = append(allPlugins, kubenet.NewPlugin(pluginDir))
|
allPlugins = append(allPlugins, kubenet.NewPlugin(pluginDir))
|
||||||
|
|
||||||
return allPlugins
|
return allPlugins
|
||||||
|
@ -139,7 +139,7 @@ func UnsecuredKubeletDeps(s *options.KubeletServer) (*kubelet.KubeletDeps, error
|
|||||||
DockerClient: dockerClient,
|
DockerClient: dockerClient,
|
||||||
KubeClient: nil,
|
KubeClient: nil,
|
||||||
Mounter: mounter,
|
Mounter: mounter,
|
||||||
NetworkPlugins: ProbeNetworkPlugins(s.NetworkPluginDir),
|
NetworkPlugins: ProbeNetworkPlugins(s.NetworkPluginDir, s.CNIConfDir, s.CNIBinDir),
|
||||||
OOMAdjuster: oom.NewOOMAdjuster(),
|
OOMAdjuster: oom.NewOOMAdjuster(),
|
||||||
OSInterface: kubecontainer.RealOS{},
|
OSInterface: kubecontainer.RealOS{},
|
||||||
Writer: writer,
|
Writer: writer,
|
||||||
|
@ -257,8 +257,14 @@ type KubeletConfiguration struct {
|
|||||||
// computed (such as IPSEC).
|
// computed (such as IPSEC).
|
||||||
NetworkPluginMTU int32 `json:"networkPluginMTU"`
|
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 (and, for backwards-compat, CNI config files)
|
||||||
NetworkPluginDir string `json:"networkPluginDir"`
|
NetworkPluginDir string `json:"networkPluginDir"`
|
||||||
|
// CNIConfDir is the full path of the directory in which to search for
|
||||||
|
// CNI config files
|
||||||
|
CNIConfDir string `json:"cniConfDir"`
|
||||||
|
// CNIBinDir is the full path of the directory in which to search for
|
||||||
|
// CNI plugin binaries
|
||||||
|
CNIBinDir string `json:"cniBinDir"`
|
||||||
// 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"`
|
||||||
|
@ -249,7 +249,9 @@ func SetDefaults_KubeletConfiguration(obj *KubeletConfiguration) {
|
|||||||
if obj.MinimumGCAge == zeroDuration {
|
if obj.MinimumGCAge == zeroDuration {
|
||||||
obj.MinimumGCAge = unversioned.Duration{Duration: 0}
|
obj.MinimumGCAge = unversioned.Duration{Duration: 0}
|
||||||
}
|
}
|
||||||
if obj.NetworkPluginDir == "" {
|
// For backwards-compat NetworkPluginDir is consulted as source of CNI config
|
||||||
|
// but CNIConfDir is preferred; don't set this default if CNI is in use.
|
||||||
|
if obj.NetworkPluginDir == "" && obj.NetworkPluginName != "cni" {
|
||||||
obj.NetworkPluginDir = "/usr/libexec/kubernetes/kubelet-plugins/net/exec/"
|
obj.NetworkPluginDir = "/usr/libexec/kubernetes/kubelet-plugins/net/exec/"
|
||||||
}
|
}
|
||||||
if obj.NonMasqueradeCIDR == "" {
|
if obj.NonMasqueradeCIDR == "" {
|
||||||
|
@ -308,8 +308,14 @@ type KubeletConfiguration struct {
|
|||||||
// various events in kubelet/pod lifecycle
|
// various events in kubelet/pod lifecycle
|
||||||
NetworkPluginName string `json:"networkPluginName"`
|
NetworkPluginName string `json:"networkPluginName"`
|
||||||
// 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 (and, for backwards-compat, CNI config files)
|
||||||
NetworkPluginDir string `json:"networkPluginDir"`
|
NetworkPluginDir string `json:"networkPluginDir"`
|
||||||
|
// CNIConfDir is the full path of the directory in which to search for
|
||||||
|
// CNI config files
|
||||||
|
CNIConfDir string `json:"cniConfDir"`
|
||||||
|
// CNIBinDir is the full path of the directory in which to search for
|
||||||
|
// CNI plugin binaries
|
||||||
|
CNIBinDir string `json:"cniBinDir"`
|
||||||
// networkPluginMTU is the MTU to be passed to the network plugin,
|
// networkPluginMTU is the MTU to be passed to the network plugin,
|
||||||
// and overrides the default MTU for cases where it cannot be automatically
|
// and overrides the default MTU for cases where it cannot be automatically
|
||||||
// computed (such as IPSEC).
|
// computed (such as IPSEC).
|
||||||
|
@ -233,6 +233,8 @@ 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.CNIConfDir = in.CNIConfDir
|
||||||
|
out.CNIBinDir = in.CNIBinDir
|
||||||
out.NetworkPluginMTU = in.NetworkPluginMTU
|
out.NetworkPluginMTU = in.NetworkPluginMTU
|
||||||
out.VolumePluginDir = in.VolumePluginDir
|
out.VolumePluginDir = in.VolumePluginDir
|
||||||
out.CloudProvider = in.CloudProvider
|
out.CloudProvider = in.CloudProvider
|
||||||
@ -412,6 +414,8 @@ func autoConvert_componentconfig_KubeletConfiguration_To_v1alpha1_KubeletConfigu
|
|||||||
out.NetworkPluginName = in.NetworkPluginName
|
out.NetworkPluginName = in.NetworkPluginName
|
||||||
out.NetworkPluginMTU = in.NetworkPluginMTU
|
out.NetworkPluginMTU = in.NetworkPluginMTU
|
||||||
out.NetworkPluginDir = in.NetworkPluginDir
|
out.NetworkPluginDir = in.NetworkPluginDir
|
||||||
|
out.CNIConfDir = in.CNIConfDir
|
||||||
|
out.CNIBinDir = in.CNIBinDir
|
||||||
out.VolumePluginDir = in.VolumePluginDir
|
out.VolumePluginDir = in.VolumePluginDir
|
||||||
out.CloudProvider = in.CloudProvider
|
out.CloudProvider = in.CloudProvider
|
||||||
out.CloudConfigFile = in.CloudConfigFile
|
out.CloudConfigFile = in.CloudConfigFile
|
||||||
|
@ -239,6 +239,8 @@ 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.CNIConfDir = in.CNIConfDir
|
||||||
|
out.CNIBinDir = in.CNIBinDir
|
||||||
out.NetworkPluginMTU = in.NetworkPluginMTU
|
out.NetworkPluginMTU = in.NetworkPluginMTU
|
||||||
out.VolumePluginDir = in.VolumePluginDir
|
out.VolumePluginDir = in.VolumePluginDir
|
||||||
out.CloudProvider = in.CloudProvider
|
out.CloudProvider = in.CloudProvider
|
||||||
|
@ -259,6 +259,8 @@ func DeepCopy_componentconfig_KubeletConfiguration(in interface{}, out interface
|
|||||||
out.NetworkPluginName = in.NetworkPluginName
|
out.NetworkPluginName = in.NetworkPluginName
|
||||||
out.NetworkPluginMTU = in.NetworkPluginMTU
|
out.NetworkPluginMTU = in.NetworkPluginMTU
|
||||||
out.NetworkPluginDir = in.NetworkPluginDir
|
out.NetworkPluginDir = in.NetworkPluginDir
|
||||||
|
out.CNIConfDir = in.CNIConfDir
|
||||||
|
out.CNIBinDir = in.CNIBinDir
|
||||||
out.VolumePluginDir = in.VolumePluginDir
|
out.VolumePluginDir = in.VolumePluginDir
|
||||||
out.CloudProvider = in.CloudProvider
|
out.CloudProvider = in.CloudProvider
|
||||||
out.CloudConfigFile = in.CloudConfigFile
|
out.CloudConfigFile = in.CloudConfigFile
|
||||||
|
@ -52,6 +52,7 @@ type cniNetworkPlugin struct {
|
|||||||
execer utilexec.Interface
|
execer utilexec.Interface
|
||||||
nsenterPath string
|
nsenterPath string
|
||||||
pluginDir string
|
pluginDir string
|
||||||
|
binDir string
|
||||||
vendorCNIDirPrefix string
|
vendorCNIDirPrefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,12 +62,16 @@ type cniNetwork struct {
|
|||||||
CNIConfig libcni.CNI
|
CNIConfig libcni.CNI
|
||||||
}
|
}
|
||||||
|
|
||||||
func probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir, vendorCNIDirPrefix string) []network.NetworkPlugin {
|
func probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir, binDir, vendorCNIDirPrefix string) []network.NetworkPlugin {
|
||||||
|
if binDir == "" {
|
||||||
|
binDir = DefaultCNIDir
|
||||||
|
}
|
||||||
plugin := &cniNetworkPlugin{
|
plugin := &cniNetworkPlugin{
|
||||||
defaultNetwork: nil,
|
defaultNetwork: nil,
|
||||||
loNetwork: getLoNetwork(vendorCNIDirPrefix),
|
loNetwork: getLoNetwork(binDir, vendorCNIDirPrefix),
|
||||||
execer: utilexec.New(),
|
execer: utilexec.New(),
|
||||||
pluginDir: pluginDir,
|
pluginDir: pluginDir,
|
||||||
|
binDir: binDir,
|
||||||
vendorCNIDirPrefix: vendorCNIDirPrefix,
|
vendorCNIDirPrefix: vendorCNIDirPrefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,11 +80,11 @@ func probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir, vendorCNIDirPrefix str
|
|||||||
return []network.NetworkPlugin{plugin}
|
return []network.NetworkPlugin{plugin}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProbeNetworkPlugins(pluginDir string) []network.NetworkPlugin {
|
func ProbeNetworkPlugins(pluginDir, binDir string) []network.NetworkPlugin {
|
||||||
return probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir, "")
|
return probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir, binDir, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultCNINetwork(pluginDir, vendorCNIDirPrefix string) (*cniNetwork, error) {
|
func getDefaultCNINetwork(pluginDir, binDir, vendorCNIDirPrefix string) (*cniNetwork, error) {
|
||||||
if pluginDir == "" {
|
if pluginDir == "" {
|
||||||
pluginDir = DefaultNetDir
|
pluginDir = DefaultNetDir
|
||||||
}
|
}
|
||||||
@ -101,7 +106,7 @@ func getDefaultCNINetwork(pluginDir, vendorCNIDirPrefix string) (*cniNetwork, er
|
|||||||
// Search for vendor-specific plugins as well as default plugins in the CNI codebase.
|
// Search for vendor-specific plugins as well as default plugins in the CNI codebase.
|
||||||
vendorDir := vendorCNIDir(vendorCNIDirPrefix, conf.Network.Type)
|
vendorDir := vendorCNIDir(vendorCNIDirPrefix, conf.Network.Type)
|
||||||
cninet := &libcni.CNIConfig{
|
cninet := &libcni.CNIConfig{
|
||||||
Path: []string{DefaultCNIDir, vendorDir},
|
Path: []string{binDir, vendorDir},
|
||||||
}
|
}
|
||||||
network := &cniNetwork{name: conf.Network.Name, NetworkConfig: conf, CNIConfig: cninet}
|
network := &cniNetwork{name: conf.Network.Name, NetworkConfig: conf, CNIConfig: cninet}
|
||||||
return network, nil
|
return network, nil
|
||||||
@ -113,7 +118,7 @@ func vendorCNIDir(prefix, pluginType string) string {
|
|||||||
return fmt.Sprintf(VendorCNIDirTemplate, prefix, pluginType)
|
return fmt.Sprintf(VendorCNIDirTemplate, prefix, pluginType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLoNetwork(vendorDirPrefix string) *cniNetwork {
|
func getLoNetwork(binDir, vendorDirPrefix string) *cniNetwork {
|
||||||
loConfig, err := libcni.ConfFromBytes([]byte(`{
|
loConfig, err := libcni.ConfFromBytes([]byte(`{
|
||||||
"cniVersion": "0.1.0",
|
"cniVersion": "0.1.0",
|
||||||
"name": "cni-loopback",
|
"name": "cni-loopback",
|
||||||
@ -125,7 +130,7 @@ func getLoNetwork(vendorDirPrefix string) *cniNetwork {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cninet := &libcni.CNIConfig{
|
cninet := &libcni.CNIConfig{
|
||||||
Path: []string{vendorCNIDir(vendorDirPrefix, loConfig.Network.Type), DefaultCNIDir},
|
Path: []string{vendorCNIDir(vendorDirPrefix, loConfig.Network.Type), binDir},
|
||||||
}
|
}
|
||||||
loNetwork := &cniNetwork{
|
loNetwork := &cniNetwork{
|
||||||
name: "lo",
|
name: "lo",
|
||||||
@ -153,7 +158,7 @@ func (plugin *cniNetworkPlugin) Init(host network.Host, hairpinMode componentcon
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) syncNetworkConfig() {
|
func (plugin *cniNetworkPlugin) syncNetworkConfig() {
|
||||||
network, err := getDefaultCNINetwork(plugin.pluginDir, plugin.vendorCNIDirPrefix)
|
network, err := getDefaultCNINetwork(plugin.pluginDir, plugin.binDir, plugin.vendorCNIDirPrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("error updating cni config: %s", err)
|
glog.Errorf("error updating cni config: %s", err)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user