mirror of https://github.com/k3s-io/k3s
kubenet: accept a list of CNI binary plugin paths
parent
69ac723b78
commit
ee2ea223e7
|
@ -119,7 +119,7 @@ func ProbeNetworkPlugins(cniConfDir, cniBinDir string) []network.NetworkPlugin {
|
||||||
|
|
||||||
// for each existing plugin, add to the list
|
// for each existing plugin, add to the list
|
||||||
allPlugins = append(allPlugins, cni.ProbeNetworkPlugins(cniConfDir, []string{cniBinDir})...)
|
allPlugins = append(allPlugins, cni.ProbeNetworkPlugins(cniConfDir, []string{cniBinDir})...)
|
||||||
allPlugins = append(allPlugins, kubenet.NewPlugin(cniBinDir))
|
allPlugins = append(allPlugins, kubenet.NewPlugin([]string{cniBinDir}))
|
||||||
|
|
||||||
return allPlugins
|
return allPlugins
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ const (
|
||||||
defaultIPAMDir = "/var/lib/cni/networks"
|
defaultIPAMDir = "/var/lib/cni/networks"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CNI plugins required by kubenet in /opt/cni/bin or vendor directory
|
// CNI plugins required by kubenet in /opt/cni/bin or user-specified directory
|
||||||
var requiredCNIPlugins = [...]string{"bridge", "host-local", "loopback"}
|
var requiredCNIPlugins = [...]string{"bridge", "host-local", "loopback"}
|
||||||
|
|
||||||
type kubenetNetworkPlugin struct {
|
type kubenetNetworkPlugin struct {
|
||||||
|
@ -91,15 +91,15 @@ type kubenetNetworkPlugin struct {
|
||||||
iptables utiliptables.Interface
|
iptables utiliptables.Interface
|
||||||
sysctl utilsysctl.Interface
|
sysctl utilsysctl.Interface
|
||||||
ebtables utilebtables.Interface
|
ebtables utilebtables.Interface
|
||||||
// vendorDir is passed by kubelet cni-bin-dir parameter.
|
// binDirs is passed by kubelet cni-bin-dir parameter.
|
||||||
// kubenet will search for cni binaries in DefaultCNIDir first, then continue to vendorDir.
|
// kubenet will search for CNI binaries in DefaultCNIDir first, then continue to binDirs.
|
||||||
vendorDir string
|
binDirs []string
|
||||||
nonMasqueradeCIDR string
|
nonMasqueradeCIDR string
|
||||||
podCidr string
|
podCidr string
|
||||||
gateway net.IP
|
gateway net.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPlugin(networkPluginDir string) network.NetworkPlugin {
|
func NewPlugin(networkPluginDirs []string) network.NetworkPlugin {
|
||||||
protocol := utiliptables.ProtocolIpv4
|
protocol := utiliptables.ProtocolIpv4
|
||||||
execer := utilexec.New()
|
execer := utilexec.New()
|
||||||
dbus := utildbus.New()
|
dbus := utildbus.New()
|
||||||
|
@ -110,7 +110,7 @@ func NewPlugin(networkPluginDir string) network.NetworkPlugin {
|
||||||
execer: utilexec.New(),
|
execer: utilexec.New(),
|
||||||
iptables: iptInterface,
|
iptables: iptInterface,
|
||||||
sysctl: sysctl,
|
sysctl: sysctl,
|
||||||
vendorDir: networkPluginDir,
|
binDirs: append([]string{DefaultCNIDir}, networkPluginDirs...),
|
||||||
hostportSyncer: hostport.NewHostportSyncer(iptInterface),
|
hostportSyncer: hostport.NewHostportSyncer(iptInterface),
|
||||||
hostportManager: hostport.NewHostportManager(iptInterface),
|
hostportManager: hostport.NewHostportManager(iptInterface),
|
||||||
nonMasqueradeCIDR: "10.0.0.0/8",
|
nonMasqueradeCIDR: "10.0.0.0/8",
|
||||||
|
@ -121,9 +121,7 @@ func (plugin *kubenetNetworkPlugin) Init(host network.Host, hairpinMode kubeletc
|
||||||
plugin.host = host
|
plugin.host = host
|
||||||
plugin.hairpinMode = hairpinMode
|
plugin.hairpinMode = hairpinMode
|
||||||
plugin.nonMasqueradeCIDR = nonMasqueradeCIDR
|
plugin.nonMasqueradeCIDR = nonMasqueradeCIDR
|
||||||
plugin.cniConfig = &libcni.CNIConfig{
|
plugin.cniConfig = &libcni.CNIConfig{Path: plugin.binDirs}
|
||||||
Path: []string{DefaultCNIDir, plugin.vendorDir},
|
|
||||||
}
|
|
||||||
|
|
||||||
if mtu == network.UseDefaultMTU {
|
if mtu == network.UseDefaultMTU {
|
||||||
if link, err := findMinMTU(); err == nil {
|
if link, err := findMinMTU(); err == nil {
|
||||||
|
@ -564,22 +562,24 @@ func (plugin *kubenetNetworkPlugin) Status() error {
|
||||||
return fmt.Errorf("Kubenet does not have netConfig. This is most likely due to lack of PodCIDR")
|
return fmt.Errorf("Kubenet does not have netConfig. This is most likely due to lack of PodCIDR")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !plugin.checkCNIPlugin() {
|
if !plugin.checkRequiredCNIPlugins() {
|
||||||
return fmt.Errorf("could not locate kubenet required CNI plugins %v at %q or %q", requiredCNIPlugins, DefaultCNIDir, plugin.vendorDir)
|
return fmt.Errorf("could not locate kubenet required CNI plugins %v at %q or %q", requiredCNIPlugins, plugin.binDirs)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkCNIPlugin returns if all kubenet required cni plugins can be found at /opt/cni/bin or user specified NetworkPluginDir.
|
// checkRequiredCNIPlugins returns if all kubenet required cni plugins can be found at /opt/cni/bin or user specified NetworkPluginDir.
|
||||||
func (plugin *kubenetNetworkPlugin) checkCNIPlugin() bool {
|
func (plugin *kubenetNetworkPlugin) checkRequiredCNIPlugins() bool {
|
||||||
if plugin.checkCNIPluginInDir(DefaultCNIDir) || plugin.checkCNIPluginInDir(plugin.vendorDir) {
|
for _, dir := range plugin.binDirs {
|
||||||
return true
|
if plugin.checkRequiredCNIPluginsInOneDir(dir) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkCNIPluginInDir returns if all required cni plugins are placed in dir
|
// checkRequiredCNIPluginsInOneDir returns true if all required cni plugins are placed in dir
|
||||||
func (plugin *kubenetNetworkPlugin) checkCNIPluginInDir(dir string) bool {
|
func (plugin *kubenetNetworkPlugin) checkRequiredCNIPluginsInOneDir(dir string) bool {
|
||||||
files, err := ioutil.ReadDir(dir)
|
files, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue