Skip to content

Commit 5787a1c

Browse files
committed
podManager simplification
Since the CNI_UPDATE code no longer needs a runningPod object, just return the changed vnid from update() instead, so we don't need to call ovs.GetOFPort() again.
1 parent 015dead commit 5787a1c

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

pkg/sdn/plugin/pod.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
type podHandler interface {
2424
setup(req *cniserver.PodRequest) (*cnitypes.Result, *runningPod, error)
25-
update(req *cniserver.PodRequest) (*runningPod, error)
25+
update(req *cniserver.PodRequest) (uint32, error)
2626
teardown(req *cniserver.PodRequest) error
2727
}
2828

@@ -259,9 +259,11 @@ func (m *podManager) processRequest(request *cniserver.PodRequest) *cniserver.Po
259259
result.Err = err
260260
}
261261
case cniserver.CNI_UPDATE:
262-
runningPod, err := m.podHandler.update(request)
262+
vnid, err := m.podHandler.update(request)
263263
if err == nil {
264-
m.runningPods[pk] = runningPod
264+
if runningPod, exists := m.runningPods[pk]; exists {
265+
runningPod.vnid = vnid
266+
}
265267
}
266268
result.Err = err
267269
case cniserver.CNI_DEL:

pkg/sdn/plugin/pod_linux.go

+8-20
Original file line numberDiff line numberDiff line change
@@ -466,51 +466,39 @@ func (m *podManager) getContainerNetnsPath(id string) (string, error) {
466466
}
467467

468468
// Update OVS flows when something (like the pod's namespace VNID) changes
469-
func (m *podManager) update(req *cniserver.PodRequest) (*runningPod, error) {
469+
func (m *podManager) update(req *cniserver.PodRequest) (uint32, error) {
470470
// Updates may come at startup and thus we may not have the pod's
471471
// netns from kubelet (since kubelet doesn't have UPDATE actions).
472472
// Read the missing netns from the pod's file.
473473
if req.Netns == "" {
474474
netns, err := m.getContainerNetnsPath(req.ContainerId)
475475
if err != nil {
476-
return nil, err
476+
return 0, err
477477
}
478478
req.Netns = netns
479479
}
480480

481-
podConfig, pod, err := m.getPodConfig(req)
481+
podConfig, _, err := m.getPodConfig(req)
482482
if err != nil {
483-
return nil, err
483+
return 0, err
484484
}
485485

486486
hostVethName, contVethMac, podIP, err := getVethInfo(req.Netns, podInterfaceName)
487487
if err != nil {
488-
return nil, err
488+
return 0, err
489489
}
490490

491491
vnidStr := vnidToString(podConfig.vnid)
492492
out, err := exec.Command(sdnScript, updateCmd, hostVethName, contVethMac, podIP, vnidStr, podConfig.ingressBandwidth, podConfig.egressBandwidth).CombinedOutput()
493493
glog.V(5).Infof("UpdatePod network plugin output: %s, %v", string(out), err)
494494

495495
if isScriptError(err) {
496-
return nil, fmt.Errorf("error running network update script: %s", getScriptError(out))
496+
return 0, fmt.Errorf("error running network update script: %s", getScriptError(out))
497497
} else if err != nil {
498-
return nil, err
498+
return 0, err
499499
}
500500

501-
ofport, err := m.ovs.GetOFPort(hostVethName)
502-
if err != nil {
503-
return nil, err
504-
}
505-
506-
return &runningPod{
507-
activePod: &kubehostport.ActivePod{
508-
Pod: pod,
509-
IP: net.ParseIP(podIP),
510-
},
511-
vnid: podConfig.vnid,
512-
ofport: ofport,
513-
}, nil
501+
return podConfig.vnid, nil
514502
}
515503

516504
// Clean up all pod networking (clear OVS flows, release IPAM lease, remove host/container veth)

pkg/sdn/plugin/pod_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ func (pt *podTester) setup(req *cniserver.PodRequest) (*cnitypes.Result, *runnin
146146
return result, fakeRunningPod(req.PodNamespace, req.PodName, ip), nil
147147
}
148148

149-
func (pt *podTester) update(req *cniserver.PodRequest) (*runningPod, error) {
149+
func (pt *podTester) update(req *cniserver.PodRequest) (uint32, error) {
150150
pod, err := pt.getExpectedPod(req.PodNamespace, req.PodName, req.Command)
151151
if err != nil {
152-
return nil, err
152+
return 0, err
153153
}
154154
pod.updated += 1
155-
return fakeRunningPod(req.PodNamespace, req.PodName, net.ParseIP(pod.cidr)), nil
155+
return 0, nil
156156
}
157157

158158
func (pt *podTester) teardown(req *cniserver.PodRequest) error {

0 commit comments

Comments
 (0)