Skip to content

Commit c854216

Browse files
committed
Have multiple egress IP ovscontroller methods rather than one confusing one
1 parent bbadc22 commit c854216

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

pkg/network/node/egressip.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (eip *egressIPWatcher) maybeAddEgressIP(egressIP string) {
194194
ns.assignedIP = egressIP
195195
ns.nodeIP = nodeIP
196196

197-
err := eip.oc.UpdateNamespaceEgressRules(ns.vnid, ns.nodeIP, mark)
197+
err := eip.oc.SetNamespaceEgressViaEgressIP(ns.vnid, ns.nodeIP, mark)
198198
if err != nil {
199199
utilruntime.HandleError(fmt.Errorf("Error updating Namespace egress rules: %v", err))
200200
}
@@ -224,10 +224,10 @@ func (eip *egressIPWatcher) deleteEgressIP(egressIP string) {
224224
var err error
225225
if ns.requestedIP == "" {
226226
// Namespace no longer wants EgressIP
227-
err = eip.oc.UpdateNamespaceEgressRules(ns.vnid, "", "")
227+
err = eip.oc.SetNamespaceEgressNormal(ns.vnid)
228228
} else {
229229
// Namespace still wants EgressIP but no node provides it
230-
err = eip.oc.UpdateNamespaceEgressRules(ns.vnid, "", mark)
230+
err = eip.oc.SetNamespaceEgressDropped(ns.vnid)
231231
}
232232
if err != nil {
233233
utilruntime.HandleError(fmt.Errorf("Error updating Namespace egress rules: %v", err))

pkg/network/node/ovscontroller.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -686,23 +686,31 @@ func (oc *ovsController) ensureTunMAC() error {
686686
return nil
687687
}
688688

689-
func (oc *ovsController) UpdateNamespaceEgressRules(vnid uint32, nodeIP, mark string) error {
689+
func (oc *ovsController) SetNamespaceEgressNormal(vnid uint32) error {
690690
otx := oc.ovs.NewTransaction()
691691
otx.DeleteFlows("table=100, reg0=%d", vnid)
692+
return otx.EndTransaction()
693+
}
692694

693-
if mark == "" {
694-
// Namespace no longer has an EgressIP; no VNID-specific rules needed
695-
} else if nodeIP == "" {
696-
// Namespace has Egress IP, but it is unavailable, so drop egress traffic
695+
func (oc *ovsController) SetNamespaceEgressDropped(vnid uint32) error {
696+
otx := oc.ovs.NewTransaction()
697+
otx.DeleteFlows("table=100, reg0=%d", vnid)
698+
otx.AddFlow("table=100, priority=100, reg0=%d, actions=drop", vnid)
699+
return otx.EndTransaction()
700+
}
701+
702+
func (oc *ovsController) SetNamespaceEgressViaEgressIP(vnid uint32, nodeIP, mark string) error {
703+
otx := oc.ovs.NewTransaction()
704+
otx.DeleteFlows("table=100, reg0=%d", vnid)
705+
if nodeIP == "" {
706+
// Namespace wants egress IP, but no node hosts it, so drop
697707
otx.AddFlow("table=100, priority=100, reg0=%d, actions=drop", vnid)
698708
} else if nodeIP == oc.localIP {
699-
// Local Egress IP
700709
if err := oc.ensureTunMAC(); err != nil {
701710
return err
702711
}
703712
otx.AddFlow("table=100, priority=100, reg0=%d, ip, actions=set_field:%s->eth_dst,set_field:%s->pkt_mark,goto_table:101", vnid, oc.tunMAC, mark)
704713
} else {
705-
// Remote Egress IP; send via VXLAN
706714
otx.AddFlow("table=100, priority=100, reg0=%d, ip, actions=move:NXM_NX_REG0[]->NXM_NX_TUN_ID[0..31],set_field:%s->tun_dst,output:1", vnid, nodeIP)
707715
}
708716
return otx.EndTransaction()

0 commit comments

Comments
 (0)