mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
teach kubenet to use hostport_manager
This commit is contained in:
parent
bd05e1af2b
commit
be9eca6b51
@ -39,6 +39,7 @@ go_library(
|
|||||||
"//pkg/kubelet/leaky:go_default_library",
|
"//pkg/kubelet/leaky:go_default_library",
|
||||||
"//pkg/kubelet/network:go_default_library",
|
"//pkg/kubelet/network:go_default_library",
|
||||||
"//pkg/kubelet/network/cni:go_default_library",
|
"//pkg/kubelet/network/cni:go_default_library",
|
||||||
|
"//pkg/kubelet/network/hostport:go_default_library",
|
||||||
"//pkg/kubelet/network/kubenet:go_default_library",
|
"//pkg/kubelet/network/kubenet:go_default_library",
|
||||||
"//pkg/kubelet/qos:go_default_library",
|
"//pkg/kubelet/qos:go_default_library",
|
||||||
"//pkg/kubelet/server/streaming:go_default_library",
|
"//pkg/kubelet/server/streaming:go_default_library",
|
||||||
|
@ -20,6 +20,7 @@ go_library(
|
|||||||
"//pkg/apis/componentconfig:go_default_library",
|
"//pkg/apis/componentconfig:go_default_library",
|
||||||
"//pkg/client/clientset_generated/clientset:go_default_library",
|
"//pkg/client/clientset_generated/clientset:go_default_library",
|
||||||
"//pkg/kubelet/container:go_default_library",
|
"//pkg/kubelet/container:go_default_library",
|
||||||
|
"//pkg/kubelet/network/hostport:go_default_library",
|
||||||
"//pkg/util/exec:go_default_library",
|
"//pkg/util/exec:go_default_library",
|
||||||
"//pkg/util/sysctl:go_default_library",
|
"//pkg/util/sysctl:go_default_library",
|
||||||
"//vendor:github.com/golang/glog",
|
"//vendor:github.com/golang/glog",
|
||||||
|
@ -37,6 +37,7 @@ go_test(
|
|||||||
"//pkg/kubelet/container/testing:go_default_library",
|
"//pkg/kubelet/container/testing:go_default_library",
|
||||||
"//pkg/kubelet/network:go_default_library",
|
"//pkg/kubelet/network:go_default_library",
|
||||||
"//pkg/kubelet/network/cni/testing:go_default_library",
|
"//pkg/kubelet/network/cni/testing:go_default_library",
|
||||||
|
"//pkg/kubelet/network/testing:go_default_library",
|
||||||
"//pkg/util/exec:go_default_library",
|
"//pkg/util/exec:go_default_library",
|
||||||
"//vendor:github.com/containernetworking/cni/pkg/types",
|
"//vendor:github.com/containernetworking/cni/pkg/types",
|
||||||
"//vendor:github.com/stretchr/testify/mock",
|
"//vendor:github.com/stretchr/testify/mock",
|
||||||
|
@ -89,7 +89,11 @@ type kubenetNetworkPlugin struct {
|
|||||||
execer utilexec.Interface
|
execer utilexec.Interface
|
||||||
nsenterPath string
|
nsenterPath string
|
||||||
hairpinMode componentconfig.HairpinMode
|
hairpinMode componentconfig.HairpinMode
|
||||||
|
// kubenet can use either hostportSyncer and hostportManager to implement hostports
|
||||||
|
// Currently, if network host supports legacy features, hostportSyncer will be used,
|
||||||
|
// otherwise, hostportManager will be used.
|
||||||
hostportSyncer hostport.HostportSyncer
|
hostportSyncer hostport.HostportSyncer
|
||||||
|
hostportManager hostport.HostPortManager
|
||||||
iptables utiliptables.Interface
|
iptables utiliptables.Interface
|
||||||
sysctl utilsysctl.Interface
|
sysctl utilsysctl.Interface
|
||||||
ebtables utilebtables.Interface
|
ebtables utilebtables.Interface
|
||||||
@ -114,6 +118,7 @@ func NewPlugin(networkPluginDir string) network.NetworkPlugin {
|
|||||||
sysctl: sysctl,
|
sysctl: sysctl,
|
||||||
vendorDir: networkPluginDir,
|
vendorDir: networkPluginDir,
|
||||||
hostportSyncer: hostport.NewHostportSyncer(),
|
hostportSyncer: hostport.NewHostportSyncer(),
|
||||||
|
hostportManager: hostport.NewHostportManager(),
|
||||||
nonMasqueradeCIDR: "10.0.0.0/8",
|
nonMasqueradeCIDR: "10.0.0.0/8",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -356,10 +361,7 @@ func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kube
|
|||||||
|
|
||||||
// The host can choose to not support "legacy" features. The remote
|
// The host can choose to not support "legacy" features. The remote
|
||||||
// shim doesn't support it (#35457), but the kubelet does.
|
// shim doesn't support it (#35457), but the kubelet does.
|
||||||
if !plugin.host.SupportsLegacyFeatures() {
|
if plugin.host.SupportsLegacyFeatures() {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// The first SetUpPod call creates the bridge; get a shaper for the sake of
|
// The first SetUpPod call creates the bridge; get a shaper for the sake of
|
||||||
// initialization
|
// initialization
|
||||||
shaper := plugin.shaper()
|
shaper := plugin.shaper()
|
||||||
@ -384,7 +386,23 @@ func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kube
|
|||||||
if err := plugin.hostportSyncer.OpenPodHostportsAndSync(newPodPortMapping, BridgeName, activePodPortMapping); err != nil {
|
if err := plugin.hostportSyncer.OpenPodHostportsAndSync(newPodPortMapping, BridgeName, activePodPortMapping); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
portMappings, err := plugin.host.GetPodPortMappings(id.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if portMappings != nil && len(portMappings) > 0 {
|
||||||
|
if err := plugin.hostportManager.Add(id.ID, &hostport.PodPortMapping{
|
||||||
|
Namespace: namespace,
|
||||||
|
Name: name,
|
||||||
|
PortMappings: portMappings,
|
||||||
|
IP: ip4,
|
||||||
|
HostNetwork: false,
|
||||||
|
}, BridgeName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,10 +485,7 @@ func (plugin *kubenetNetworkPlugin) teardown(namespace string, name string, id k
|
|||||||
|
|
||||||
// The host can choose to not support "legacy" features. The remote
|
// The host can choose to not support "legacy" features. The remote
|
||||||
// shim doesn't support it (#35457), but the kubelet does.
|
// shim doesn't support it (#35457), but the kubelet does.
|
||||||
if !plugin.host.SupportsLegacyFeatures() {
|
if plugin.host.SupportsLegacyFeatures() {
|
||||||
return utilerrors.NewAggregate(errList)
|
|
||||||
}
|
|
||||||
|
|
||||||
activePodPortMapping, err := plugin.getPodPortMapping()
|
activePodPortMapping, err := plugin.getPodPortMapping()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = plugin.hostportSyncer.SyncHostports(BridgeName, activePodPortMapping)
|
err = plugin.hostportSyncer.SyncHostports(BridgeName, activePodPortMapping)
|
||||||
@ -478,7 +493,21 @@ func (plugin *kubenetNetworkPlugin) teardown(namespace string, name string, id k
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
errList = append(errList, err)
|
errList = append(errList, err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
portMappings, err := plugin.host.GetPodPortMappings(id.ID)
|
||||||
|
if err != nil {
|
||||||
|
errList = append(errList, err)
|
||||||
|
} else if portMappings != nil && len(portMappings) > 0 {
|
||||||
|
if err = plugin.hostportManager.Remove(id.ID, &hostport.PodPortMapping{
|
||||||
|
Namespace: namespace,
|
||||||
|
Name: name,
|
||||||
|
PortMappings: portMappings,
|
||||||
|
HostNetwork: false,
|
||||||
|
}); err != nil {
|
||||||
|
errList = append(errList, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return utilerrors.NewAggregate(errList)
|
return utilerrors.NewAggregate(errList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ go_library(
|
|||||||
"//pkg/client/clientset_generated/clientset:go_default_library",
|
"//pkg/client/clientset_generated/clientset:go_default_library",
|
||||||
"//pkg/kubelet/container:go_default_library",
|
"//pkg/kubelet/container:go_default_library",
|
||||||
"//pkg/kubelet/container/testing:go_default_library",
|
"//pkg/kubelet/container/testing:go_default_library",
|
||||||
|
"//pkg/kubelet/network/hostport:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user