@@ -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 () {
@@ -1118,39 +1126,42 @@ func (c *EgressController) syncEgress(egressName string) error {
1118
1126
}()
1119
1127
1120
1128
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 )
1129
+ strictEnforcement := egress .Spec .StrictEnforcement
1130
+ if strictEnforcement || egressNodeAvailability (egress ) {
1131
+ // Install SNAT flows for desired Pods.
1132
+ for pod := range pods {
1133
+ eState .pods .Insert (pod )
1134
+ stalePods .Delete (pod )
1135
+
1136
+ // If the Egress is not the effective one for the Pod, do nothing.
1137
+ if ! c .bindPodEgress (pod , egressName ) {
1138
+ continue
1139
+ }
1125
1140
1126
- // If the Egress is not the effective one for the Pod, do nothing.
1127
- if ! c .bindPodEgress (pod , egressName ) {
1128
- continue
1129
- }
1141
+ // Get the Pod's openflow port.
1142
+ parts := strings .Split (pod , "/" )
1143
+ podNamespace , podName := parts [0 ], parts [1 ]
1144
+ ifaces := c .ifaceStore .GetContainerInterfacesByPod (podName , podNamespace )
1145
+ if len (ifaces ) == 0 {
1146
+ klog .Infof ("Interfaces of Pod %s/%s not found" , podNamespace , podName )
1147
+ continue
1148
+ }
1130
1149
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
1150
+ ofPort := ifaces [0 ].OFPort
1151
+ if eState .ofPorts .Has (ofPort ) {
1152
+ staleOFPorts .Delete (ofPort )
1153
+ continue
1154
+ }
1155
+ if err := c .ofClient .InstallPodSNATFlows (uint32 (ofPort ), egressIP , mark ); err != nil {
1156
+ return err
1157
+ }
1158
+ eState .ofPorts .Insert (ofPort )
1138
1159
}
1139
1160
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 {
1161
+ // Uninstall SNAT flows for stale Pods.
1162
+ if err := c .uninstallPodFlows (egressName , eState , staleOFPorts , stalePods ); err != nil {
1146
1163
return err
1147
1164
}
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
1165
}
1155
1166
return nil
1156
1167
}
0 commit comments