mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
kubelet/kubenet: simplify getting nsenter path
This commit is contained in:
parent
a657d0587b
commit
e47d020cb6
@ -95,6 +95,7 @@ func NewPlugin(networkPluginDir string) network.NetworkPlugin {
|
|||||||
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) error {
|
||||||
plugin.host = host
|
plugin.host = host
|
||||||
plugin.hairpinMode = hairpinMode
|
plugin.hairpinMode = hairpinMode
|
||||||
|
plugin.nonMasqueradeCIDR = nonMasqueradeCIDR
|
||||||
plugin.cniConfig = &libcni.CNIConfig{
|
plugin.cniConfig = &libcni.CNIConfig{
|
||||||
Path: []string{DefaultCNIDir, plugin.vendorDir},
|
Path: []string{DefaultCNIDir, plugin.vendorDir},
|
||||||
}
|
}
|
||||||
@ -127,7 +128,11 @@ func (plugin *kubenetNetworkPlugin) Init(host network.Host, hairpinMode componen
|
|||||||
return fmt.Errorf("Failed to generate loopback config: %v", err)
|
return fmt.Errorf("Failed to generate loopback config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.nonMasqueradeCIDR = nonMasqueradeCIDR
|
plugin.nsenterPath, err = plugin.execer.LookPath("nsenter")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to find nsenter binary: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Need to SNAT outbound traffic from cluster
|
// Need to SNAT outbound traffic from cluster
|
||||||
if err = plugin.ensureMasqRule(); err != nil {
|
if err = plugin.ensureMasqRule(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -463,11 +468,7 @@ func (plugin *kubenetNetworkPlugin) GetPodNetworkStatus(namespace string, name s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Kubenet failed to retrieve network namespace path: %v", err)
|
return nil, fmt.Errorf("Kubenet failed to retrieve network namespace path: %v", err)
|
||||||
}
|
}
|
||||||
nsenterPath, err := plugin.getNsenterPath()
|
ip, err := network.GetPodIP(plugin.execer, plugin.nsenterPath, netnsPath, network.DefaultInterfaceName)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ip, err := network.GetPodIP(plugin.execer, nsenterPath, netnsPath, network.DefaultInterfaceName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -556,17 +557,6 @@ func (plugin *kubenetNetworkPlugin) delContainerFromNetwork(config *libcni.Netwo
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *kubenetNetworkPlugin) getNsenterPath() (string, error) {
|
|
||||||
if plugin.nsenterPath == "" {
|
|
||||||
nsenterPath, err := plugin.execer.LookPath("nsenter")
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
plugin.nsenterPath = nsenterPath
|
|
||||||
}
|
|
||||||
return plugin.nsenterPath, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// shaper retrieves the bandwidth shaper and, if it hasn't been fetched before,
|
// shaper retrieves the bandwidth shaper and, if it hasn't been fetched before,
|
||||||
// initializes it and ensures the bridge is appropriately configured
|
// initializes it and ensures the bridge is appropriately configured
|
||||||
// This function should only be called while holding the `plugin.mu` lock
|
// This function should only be called while holding the `plugin.mu` lock
|
||||||
|
Loading…
Reference in New Issue
Block a user