@@ -13,6 +13,7 @@ import (
13
13
14
14
sdnapi "github.com/openshift/origin/pkg/sdn/api"
15
15
"github.com/openshift/origin/pkg/sdn/plugin/cniserver"
16
+ "github.com/openshift/origin/pkg/util/ovs"
16
17
17
18
"github.com/golang/glog"
18
19
@@ -190,21 +191,12 @@ func (m *podManager) ipamDel(id string) error {
190
191
return nil
191
192
}
192
193
193
- func ( m * podManager ) ensureOvsPort ( hostVeth string ) (int , error ) {
194
- return m . ovs .AddPort (hostVeth , - 1 )
194
+ func ensureOvsPort ( ovsif * ovs. Interface , hostVeth string ) (int , error ) {
195
+ return ovsif .AddPort (hostVeth , - 1 )
195
196
}
196
197
197
- func (m * podManager ) setupPodFlows (ofport int , podIP , podMac , namespace string ) error {
198
- vnid := uint32 (0 )
199
- if m .multitenant {
200
- var err error
201
- vnid , err = m .vnids .GetVNID (namespace )
202
- if err != nil {
203
- return err
204
- }
205
- }
206
-
207
- otx := m .ovs .NewTransaction ()
198
+ func setupPodFlows (ovsif * ovs.Interface , ofport int , podIP , podMac string , vnid uint32 ) error {
199
+ otx := ovsif .NewTransaction ()
208
200
209
201
// ARP/IP traffic from container
210
202
otx .AddFlow ("table=2, priority=100, in_port=%d, arp, nw_src=%s, arp_sha=%s, actions=load:%d->NXM_NX_REG0[], goto_table:5" , ofport , podIP , podMac , vnid )
@@ -224,7 +216,7 @@ func (m *podManager) setupPodFlows(ofport int, podIP, podMac, namespace string)
224
216
return otx .EndTransaction ()
225
217
}
226
218
227
- func ( m * podManager ) setupPodBandwidth ( pod * kapi.Pod , hostVeth string ) error {
219
+ func setupPodBandwidth ( ovsif * ovs. Interface , pod * kapi.Pod , hostVeth string ) error {
228
220
podIngress , podEgress , err := kbandwidth .ExtractPodBandwidthResources (pod .Annotations )
229
221
if err != nil {
230
222
return fmt .Errorf ("failed to parse pod bandwidth: %v" , err )
@@ -243,17 +235,17 @@ func (m *podManager) setupPodBandwidth(pod *kapi.Pod, hostVeth string) error {
243
235
}
244
236
245
237
if ovsEgress > 0 {
246
- qos , err := m . ovs .Create ("qos" , "type=linux-htb" , fmt .Sprintf ("other-config:max-rate=%d" , ovsEgress ))
238
+ qos , err := ovsif .Create ("qos" , "type=linux-htb" , fmt .Sprintf ("other-config:max-rate=%d" , ovsEgress ))
247
239
if err != nil {
248
240
return err
249
241
}
250
- err = m . ovs .Set ("port" , hostVeth , fmt .Sprintf ("qos=%s" , qos ))
242
+ err = ovsif .Set ("port" , hostVeth , fmt .Sprintf ("qos=%s" , qos ))
251
243
if err != nil {
252
244
return err
253
245
}
254
246
}
255
247
if ovsIngress > 0 {
256
- err := m . ovs .Set ("interface" , hostVeth , fmt .Sprintf ("ingress_policing_rate=%d" , ovsIngress ))
248
+ err := ovsif .Set ("interface" , hostVeth , fmt .Sprintf ("ingress_policing_rate=%d" , ovsIngress ))
257
249
if err != nil {
258
250
return err
259
251
}
@@ -262,25 +254,25 @@ func (m *podManager) setupPodBandwidth(pod *kapi.Pod, hostVeth string) error {
262
254
return nil
263
255
}
264
256
265
- func ( m * podManager ) cleanupPodFlows ( podIP string ) error {
266
- otx := m . ovs .NewTransaction ()
257
+ func cleanupPodFlows ( ovsif * ovs. Interface , podIP string ) error {
258
+ otx := ovsif .NewTransaction ()
267
259
otx .DeleteFlows ("ip, nw_dst=%s" , podIP )
268
260
otx .DeleteFlows ("ip, nw_src=%s" , podIP )
269
261
otx .DeleteFlows ("arp, nw_dst=%s" , podIP )
270
262
otx .DeleteFlows ("arp, nw_src=%s" , podIP )
271
263
return otx .EndTransaction ()
272
264
}
273
265
274
- func ( m * podManager ) cleanupPodBandwidth ( hostVeth string ) error {
275
- qos , err := m . ovs .Get ("port" , hostVeth , "qos" )
266
+ func cleanupPodBandwidth ( ovsif * ovs. Interface , hostVeth string ) error {
267
+ qos , err := ovsif .Get ("port" , hostVeth , "qos" )
276
268
if err != nil || qos == "[]" {
277
269
return err
278
270
}
279
- err = m . ovs .Clear ("port" , hostVeth , "qos" )
271
+ err = ovsif .Clear ("port" , hostVeth , "qos" )
280
272
if err != nil {
281
273
return err
282
274
}
283
- return m . ovs .Destroy ("qos" , qos )
275
+ return ovsif .Destroy ("qos" , qos )
284
276
}
285
277
286
278
func vnidToString (vnid uint32 ) string {
@@ -448,18 +440,23 @@ func (m *podManager) setup(req *cniserver.PodRequest) (*cnitypes.Result, *kubeho
448
440
return nil , nil , err
449
441
}
450
442
443
+ vnid , err := m .getVNID (req .PodNamespace )
444
+ if err != nil {
445
+ return nil , nil , err
446
+ }
447
+
451
448
if err := maybeAddMacvlan (pod , req .Netns ); err != nil {
452
449
return nil , nil , err
453
450
}
454
451
455
- ofport , err := m . ensureOvsPort (hostVethName )
452
+ ofport , err := ensureOvsPort (m . ovs , hostVethName )
456
453
if err != nil {
457
454
return nil , nil , err
458
455
}
459
- if err := m . setupPodFlows (ofport , podIP .String (), contVethMac , req . PodNamespace ); err != nil {
456
+ if err := setupPodFlows (m . ovs , ofport , podIP .String (), contVethMac , vnid ); err != nil {
460
457
return nil , nil , err
461
458
}
462
- if err := m . setupPodBandwidth (pod , hostVethName ); err != nil {
459
+ if err := setupPodBandwidth (m . ovs , pod , hostVethName ); err != nil {
463
460
return nil , nil , err
464
461
}
465
462
@@ -497,21 +494,25 @@ func (m *podManager) update(req *cniserver.PodRequest) error {
497
494
if err != nil {
498
495
return err
499
496
}
497
+ vnid , err := m .getVNID (req .PodNamespace )
498
+ if err != nil {
499
+ return err
500
+ }
500
501
501
- ofport , err := m . ensureOvsPort (hostVethName )
502
+ ofport , err := ensureOvsPort (m . ovs , hostVethName )
502
503
if err != nil {
503
504
return err
504
505
}
505
- if err := m . cleanupPodFlows (podIP ); err != nil {
506
+ if err := cleanupPodFlows (m . ovs , podIP ); err != nil {
506
507
return err
507
508
}
508
- if err := m . setupPodFlows (ofport , podIP , contVethMac , req . PodNamespace ); err != nil {
509
+ if err := setupPodFlows (m . ovs , ofport , podIP , contVethMac , vnid ); err != nil {
509
510
return err
510
511
}
511
- if err := m . cleanupPodBandwidth (hostVethName ); err != nil {
512
+ if err := cleanupPodBandwidth (m . ovs , hostVethName ); err != nil {
512
513
return err
513
514
}
514
- if err := m . setupPodBandwidth (pod , hostVethName ); err != nil {
515
+ if err := setupPodBandwidth (m . ovs , pod , hostVethName ); err != nil {
515
516
return err
516
517
}
517
518
@@ -536,10 +537,10 @@ func (m *podManager) teardown(req *cniserver.PodRequest) error {
536
537
return err
537
538
}
538
539
539
- if err := m . cleanupPodFlows (podIP ); err != nil {
540
+ if err := cleanupPodFlows (m . ovs , podIP ); err != nil {
540
541
errList = append (errList , err )
541
542
}
542
- if err := m . cleanupPodBandwidth (hostVethName ); err != nil {
543
+ if err := cleanupPodBandwidth (m . ovs , hostVethName ); err != nil {
543
544
errList = append (errList , err )
544
545
}
545
546
if err := m .ovs .DeletePort (hostVethName ); err != nil {
0 commit comments