@@ -88,6 +88,8 @@ var emptyWatch = watch.NewEmptyWatch()
88
88
89
89
var newIPAssigner = ipassigner .NewIPAssigner
90
90
91
+ var egressNodeAvailability = hasEgressNode
92
+
91
93
// egressState keeps the actual state of an Egress that has been realized.
92
94
type egressState struct {
93
95
// The actual egress IP of the Egress. If it's different from the desired IP, there is an update to EgressIP, and we
@@ -989,6 +991,12 @@ func (c *EgressController) updateEgressStatus(egress *crdv1b1.Egress, egressIP s
989
991
return nil
990
992
}
991
993
994
+ func hasEgressNode (egress * crdv1b1.Egress ) bool {
995
+ if egress .Status .EgressNode == "" {
996
+ return false
997
+ }
998
+ return true
999
+ }
992
1000
func (c * EgressController ) syncEgress (egressName string ) error {
993
1001
startTime := time .Now ()
994
1002
defer func () {
@@ -1024,6 +1032,7 @@ func (c *EgressController) syncEgress(egressName string) error {
1024
1032
desiredNode = egressNode
1025
1033
} else {
1026
1034
scheduleErr = err
1035
+ desiredEgressIP = egress .Spec .EgressIP
1027
1036
}
1028
1037
} else {
1029
1038
desiredEgressIP = egress .Spec .EgressIP
@@ -1118,39 +1127,42 @@ func (c *EgressController) syncEgress(egressName string) error {
1118
1127
}()
1119
1128
1120
1129
egressIP := net .ParseIP (eState .egressIP )
1121
- // Install SNAT flows for desired Pods.
1122
- for pod := range pods {
1123
- eState .pods .Insert (pod )
1124
- stalePods .Delete (pod )
1130
+ failurePolicy := egress .Spec .FailurePolicy
1131
+ if failurePolicy == crdv1b1 .FailurePolicyDrop || egressNodeAvailability (egress ) {
1132
+ // Install SNAT flows for desired Pods.
1133
+ for pod := range pods {
1134
+ eState .pods .Insert (pod )
1135
+ stalePods .Delete (pod )
1136
+
1137
+ // If the Egress is not the effective one for the Pod, do nothing.
1138
+ if ! c .bindPodEgress (pod , egressName ) {
1139
+ continue
1140
+ }
1125
1141
1126
- // If the Egress is not the effective one for the Pod, do nothing.
1127
- if ! c .bindPodEgress (pod , egressName ) {
1128
- continue
1129
- }
1142
+ // Get the Pod's openflow port.
1143
+ parts := strings .Split (pod , "/" )
1144
+ podNamespace , podName := parts [0 ], parts [1 ]
1145
+ ifaces := c .ifaceStore .GetContainerInterfacesByPod (podName , podNamespace )
1146
+ if len (ifaces ) == 0 {
1147
+ klog .Infof ("Interfaces of Pod %s/%s not found" , podNamespace , podName )
1148
+ continue
1149
+ }
1130
1150
1131
- // Get the Pod's openflow port.
1132
- parts := strings .Split (pod , "/" )
1133
- podNamespace , podName := parts [0 ], parts [1 ]
1134
- ifaces := c .ifaceStore .GetContainerInterfacesByPod (podName , podNamespace )
1135
- if len (ifaces ) == 0 {
1136
- klog .Infof ("Interfaces of Pod %s/%s not found" , podNamespace , podName )
1137
- continue
1151
+ ofPort := ifaces [0 ].OFPort
1152
+ if eState .ofPorts .Has (ofPort ) {
1153
+ staleOFPorts .Delete (ofPort )
1154
+ continue
1155
+ }
1156
+ if err := c .ofClient .InstallPodSNATFlows (uint32 (ofPort ), egressIP , mark ); err != nil {
1157
+ return err
1158
+ }
1159
+ eState .ofPorts .Insert (ofPort )
1138
1160
}
1139
1161
1140
- ofPort := ifaces [0 ].OFPort
1141
- if eState .ofPorts .Has (ofPort ) {
1142
- staleOFPorts .Delete (ofPort )
1143
- continue
1144
- }
1145
- if err := c .ofClient .InstallPodSNATFlows (uint32 (ofPort ), egressIP , mark ); err != nil {
1162
+ // Uninstall SNAT flows for stale Pods.
1163
+ if err := c .uninstallPodFlows (egressName , eState , staleOFPorts , stalePods ); err != nil {
1146
1164
return err
1147
1165
}
1148
- eState .ofPorts .Insert (ofPort )
1149
- }
1150
-
1151
- // Uninstall SNAT flows for stale Pods.
1152
- if err := c .uninstallPodFlows (egressName , eState , staleOFPorts , stalePods ); err != nil {
1153
- return err
1154
1166
}
1155
1167
return nil
1156
1168
}
0 commit comments