Skip to content

Commit 59b2b62

Browse files
committed
sdn: disable hostport handling when CRIO is used
This is a workaround because CRIO's CNI driver has different hostport behavior than Kubernetes' CNI driver. Kube leaves all hostport handling to the CNI plugin itself, while CRIO does hostport handling internally, leading to duplicate work if the plugin also handles hostports. For now, detect the runtime based on socket path and disable openshift-sdn hostport handling if the runtime is CRIO. The real fix for this is to add hostport handling to Kube's CNI driver, but in the "split" mode discussed upstream where kube's CNI driver handles the port reservations on the host, while the plugin handles the actual iptables rules. CRIO should be converted to this scheme as well, and plugins will indicate with capabilities in the CNI JSON whether they support this scheme or not. At that point we can remove this hack and just have openshift-sdn advertise portmapping support via the CNI JSON.
1 parent 9bee56c commit 59b2b62

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

pkg/cmd/server/kubernetes/network/sdn_linux.go

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package network
22

33
import (
4+
"strings"
5+
46
"k8s.io/kubernetes/pkg/apis/componentconfig"
57
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
68
kinternalinformers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
@@ -22,6 +24,11 @@ func NewSDNInterfaces(options configapi.NodeConfig, originClient *osclient.Clien
2224
}
2325
}
2426

27+
// dockershim + kube CNI driver delegates hostport handling to plugins,
28+
// while CRI-O handles hostports itself. Thus we need to disable the
29+
// SDN's hostport handling when run under CRI-O.
30+
enableHostports := !strings.Contains(runtimeEndpoint, "crio")
31+
2532
node, err := sdnnode.New(&sdnnode.OsdnNodeConfig{
2633
PluginName: options.NetworkConfig.NetworkPluginName,
2734
Hostname: options.NodeName,
@@ -33,6 +40,7 @@ func NewSDNInterfaces(options configapi.NodeConfig, originClient *osclient.Clien
3340
KubeInformers: internalKubeInformers,
3441
IPTablesSyncPeriod: proxyconfig.IPTables.SyncPeriod.Duration,
3542
ProxyMode: proxyconfig.Mode,
43+
EnableHostports: enableHostports,
3644
})
3745
if err != nil {
3846
return nil, nil, err

pkg/network/node/node.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type OsdnNodeConfig struct {
7070
SelfIP string
7171
RuntimeEndpoint string
7272
MTU uint32
73+
EnableHostports bool
7374

7475
OSClient *osclient.Client
7576
KClient kclientset.Interface
@@ -178,7 +179,7 @@ func New(c *OsdnNodeConfig) (network.NodeInterface, error) {
178179
kClient: c.KClient,
179180
osClient: c.OSClient,
180181
oc: oc,
181-
podManager: newPodManager(c.KClient, policy, c.MTU, oc),
182+
podManager: newPodManager(c.KClient, policy, c.MTU, oc, c.EnableHostports),
182183
localIP: c.SelfIP,
183184
hostName: c.Hostname,
184185
useConnTrack: useConnTrack,

pkg/network/node/pod.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,23 @@ type podManager struct {
6767
mtu uint32
6868
ovs *ovsController
6969

70+
enableHostports bool
71+
7072
// Things only accessed through the processCNIRequests() goroutine
7173
// and thus can be set from Start()
7274
ipamConfig []byte
7375
hostportSyncer kubehostport.HostportSyncer
7476
}
7577

7678
// Creates a new live podManager; used by node code0
77-
func newPodManager(kClient kclientset.Interface, policy osdnPolicy, mtu uint32, ovs *ovsController) *podManager {
79+
func newPodManager(kClient kclientset.Interface, policy osdnPolicy, mtu uint32, ovs *ovsController, enableHostports bool) *podManager {
7880
pm := newDefaultPodManager()
7981
pm.kClient = kClient
8082
pm.policy = policy
8183
pm.mtu = mtu
8284
pm.podHandler = pm
8385
pm.ovs = ovs
86+
pm.enableHostports = enableHostports
8487
return pm
8588
}
8689

@@ -150,7 +153,9 @@ func getIPAMConfig(clusterNetwork *net.IPNet, localSubnet string) ([]byte, error
150153

151154
// Start the CNI server and start processing requests from it
152155
func (m *podManager) Start(socketPath string, localSubnetCIDR string, clusterNetwork *net.IPNet) error {
153-
m.hostportSyncer = kubehostport.NewHostportSyncer()
156+
if m.enableHostports {
157+
m.hostportSyncer = kubehostport.NewHostportSyncer()
158+
}
154159

155160
var err error
156161
if m.ipamConfig, err = getIPAMConfig(clusterNetwork, localSubnetCIDR); err != nil {
@@ -499,8 +504,10 @@ func (m *podManager) setup(req *cniserver.PodRequest) (cnitypes.Result, *running
499504
defer func() {
500505
if !success {
501506
m.ipamDel(req.SandboxID)
502-
if err := m.hostportSyncer.SyncHostports(Tun0, m.getRunningPods()); err != nil {
503-
glog.Warningf("failed syncing hostports: %v", err)
507+
if m.hostportSyncer != nil {
508+
if err := m.hostportSyncer.SyncHostports(Tun0, m.getRunningPods()); err != nil {
509+
glog.Warningf("failed syncing hostports: %v", err)
510+
}
504511
}
505512
}
506513
}()
@@ -511,8 +518,10 @@ func (m *podManager) setup(req *cniserver.PodRequest) (cnitypes.Result, *running
511518
return nil, nil, err
512519
}
513520
podPortMapping := kubehostport.ConstructPodPortMapping(&v1Pod, podIP)
514-
if err := m.hostportSyncer.OpenPodHostportsAndSync(podPortMapping, Tun0, m.getRunningPods()); err != nil {
515-
return nil, nil, err
521+
if m.hostportSyncer != nil {
522+
if err := m.hostportSyncer.OpenPodHostportsAndSync(podPortMapping, Tun0, m.getRunningPods()); err != nil {
523+
return nil, nil, err
524+
}
516525
}
517526

518527
var hostVethName, contVethMac string
@@ -631,8 +640,10 @@ func (m *podManager) teardown(req *cniserver.PodRequest) error {
631640
errList = append(errList, err)
632641
}
633642

634-
if err := m.hostportSyncer.SyncHostports(Tun0, m.getRunningPods()); err != nil {
635-
errList = append(errList, err)
643+
if m.hostportSyncer != nil {
644+
if err := m.hostportSyncer.SyncHostports(Tun0, m.getRunningPods()); err != nil {
645+
errList = append(errList, err)
646+
}
636647
}
637648

638649
return kerrors.NewAggregate(errList)

0 commit comments

Comments
 (0)