@@ -153,7 +153,7 @@ func (r *groupReconciler) reconcile(ctx context.Context, req reconcile.Request)
153153 return ctrlerrors .NewErrorWithMetrics (controllerName , "add_group_finalizer_error" , err , r .metricsCollector )
154154 }
155155
156- _ , lb , frontendNlb , err := r .buildAndDeployModel (ctx , ingGroup )
156+ _ , lb , frontendNlb , listenerPorts , err := r .buildAndDeployModel (ctx , ingGroup )
157157 if err != nil {
158158 return err
159159 }
@@ -173,7 +173,7 @@ func (r *groupReconciler) reconcile(ctx context.Context, req reconcile.Request)
173173 return
174174 }
175175 }
176- statusErr = r .updateIngressGroupStatus (ctx , ingGroup , lbDNS , frontendNlbDNS )
176+ statusErr = r .updateIngressGroupStatus (ctx , ingGroup , lbDNS , frontendNlbDNS , listenerPorts )
177177 if statusErr != nil {
178178 r .recordIngressGroupEvent (ctx , ingGroup , corev1 .EventTypeWarning , k8s .IngressEventReasonFailedUpdateStatus ,
179179 fmt .Sprintf ("Failed update status due to %v" , statusErr ))
@@ -200,25 +200,26 @@ func (r *groupReconciler) reconcile(ctx context.Context, req reconcile.Request)
200200 return nil
201201}
202202
203- func (r * groupReconciler ) buildAndDeployModel (ctx context.Context , ingGroup ingress.Group ) (core.Stack , * elbv2model.LoadBalancer , * elbv2model.LoadBalancer , error ) {
203+ func (r * groupReconciler ) buildAndDeployModel (ctx context.Context , ingGroup ingress.Group ) (core.Stack , * elbv2model.LoadBalancer , * elbv2model.LoadBalancer , [] int32 , error ) {
204204 var stack core.Stack
205205 var lb * elbv2model.LoadBalancer
206206 var secrets []types.NamespacedName
207207 var backendSGRequired bool
208208 var err error
209209 var frontendNlb * elbv2model.LoadBalancer
210+ var listenerPorts []int32
210211 buildModelFn := func () {
211- stack , lb , secrets , backendSGRequired , frontendNlb , err = r .modelBuilder .Build (ctx , ingGroup , r .metricsCollector )
212+ stack , lb , secrets , backendSGRequired , frontendNlb , listenerPorts , err = r .modelBuilder .Build (ctx , ingGroup , r .metricsCollector )
212213 }
213214 r .metricsCollector .ObserveControllerReconcileLatency (controllerName , "build_model" , buildModelFn )
214215 if err != nil {
215216 r .recordIngressGroupEvent (ctx , ingGroup , corev1 .EventTypeWarning , k8s .IngressEventReasonFailedBuildModel , fmt .Sprintf ("Failed build model due to %v" , err ))
216- return nil , nil , nil , ctrlerrors .NewErrorWithMetrics (controllerName , "build_model_error" , err , r .metricsCollector )
217+ return nil , nil , nil , nil , ctrlerrors .NewErrorWithMetrics (controllerName , "build_model_error" , err , r .metricsCollector )
217218 }
218219 stackJSON , err := r .stackMarshaller .Marshal (stack )
219220 if err != nil {
220221 r .recordIngressGroupEvent (ctx , ingGroup , corev1 .EventTypeWarning , k8s .IngressEventReasonFailedBuildModel , fmt .Sprintf ("Failed build model due to %v" , err ))
221- return nil , nil , nil , err
222+ return nil , nil , nil , nil , err
222223 }
223224 r .logger .Info ("successfully built model" , "model" , stackJSON )
224225
@@ -229,10 +230,10 @@ func (r *groupReconciler) buildAndDeployModel(ctx context.Context, ingGroup ingr
229230 if err != nil {
230231 var requeueNeededAfter * ctrlerrors.RequeueNeededAfter
231232 if errors .As (err , & requeueNeededAfter ) {
232- return nil , nil , nil , err
233+ return nil , nil , nil , nil , err
233234 }
234235 r .recordIngressGroupEvent (ctx , ingGroup , corev1 .EventTypeWarning , k8s .IngressEventReasonFailedDeployModel , fmt .Sprintf ("Failed deploy model due to %v" , err ))
235- return nil , nil , nil , ctrlerrors .NewErrorWithMetrics (controllerName , "deploy_model_error" , err , r .metricsCollector )
236+ return nil , nil , nil , nil , ctrlerrors .NewErrorWithMetrics (controllerName , "deploy_model_error" , err , r .metricsCollector )
236237 }
237238 r .logger .Info ("successfully deployed model" , "ingressGroup" , ingGroup .ID )
238239 r .secretsManager .MonitorSecrets (ingGroup .ID .String (), secrets )
@@ -242,9 +243,9 @@ func (r *groupReconciler) buildAndDeployModel(ctx context.Context, ingGroup ingr
242243 inactiveResources = append (inactiveResources , k8s .ToSliceOfNamespacedNames (ingGroup .Members )... )
243244 }
244245 if err := r .backendSGProvider .Release (ctx , networkingpkg .ResourceTypeIngress , inactiveResources ); err != nil {
245- return nil , nil , nil , ctrlerrors .NewErrorWithMetrics (controllerName , "release_auto_generated_backend_sg_error" , err , r .metricsCollector )
246+ return nil , nil , nil , nil , ctrlerrors .NewErrorWithMetrics (controllerName , "release_auto_generated_backend_sg_error" , err , r .metricsCollector )
246247 }
247- return stack , lb , frontendNlb , nil
248+ return stack , lb , frontendNlb , listenerPorts , nil
248249}
249250
250251func (r * groupReconciler ) recordIngressGroupEvent (_ context.Context , ingGroup ingress.Group , eventType string , reason string , message string ) {
@@ -253,25 +254,35 @@ func (r *groupReconciler) recordIngressGroupEvent(_ context.Context, ingGroup in
253254 }
254255}
255256
256- func (r * groupReconciler ) updateIngressGroupStatus (ctx context.Context , ingGroup ingress.Group , lbDNS string , frontendNLBDNS string ) error {
257+ func (r * groupReconciler ) updateIngressGroupStatus (ctx context.Context , ingGroup ingress.Group , lbDNS string , frontendNLBDNS string , listenerPorts [] int32 ) error {
257258 for _ , member := range ingGroup .Members {
258- if err := r .updateIngressStatus (ctx , lbDNS , frontendNLBDNS , member .Ing ); err != nil {
259+ if err := r .updateIngressStatus (ctx , lbDNS , frontendNLBDNS , member .Ing , listenerPorts ); err != nil {
259260 return err
260261 }
261262 }
262263 return nil
263264}
264265
265- func (r * groupReconciler ) updateIngressStatus (ctx context.Context , lbDNS string , frontendNlbDNS string , ing * networking.Ingress ) error {
266+ func (r * groupReconciler ) updateIngressStatus (ctx context.Context , lbDNS string , frontendNlbDNS string , ing * networking.Ingress , ports []int32 ) error {
267+ ingressPorts := make ([]networking.IngressPortStatus , len (ports ))
268+ for i , port := range ports {
269+ ingressPorts [i ] = networking.IngressPortStatus {
270+ Port : port ,
271+ }
272+ }
273+
266274 ingOld := ing .DeepCopy ()
267275 if len (ing .Status .LoadBalancer .Ingress ) != 1 ||
268276 ing .Status .LoadBalancer .Ingress [0 ].IP != "" ||
269277 ing .Status .LoadBalancer .Ingress [0 ].Hostname != lbDNS {
270278 ing .Status .LoadBalancer .Ingress = []networking.IngressLoadBalancerIngress {
271279 {
272280 Hostname : lbDNS ,
281+ Ports : ingressPorts ,
273282 },
274283 }
284+ } else if len (ports ) > 0 {
285+ ing .Status .LoadBalancer .Ingress [0 ].Ports = ingressPorts
275286 }
276287
277288 // Ensure frontendNLBDNS is appended if it is not already added
@@ -405,21 +416,56 @@ func isIngressStatusEqual(a, b []networking.IngressLoadBalancerIngress) bool {
405416 return false
406417 }
407418
408- setA := make (map [string ]struct {}, len ( a ) )
409- setB := make (map [string ]struct {}, len ( b ) )
419+ hostnameToPortsA := make (map [string ]map [ int32 ] struct {})
420+ hostnameToPortsB := make (map [string ]map [ int32 ] struct {})
410421
411422 for _ , ingress := range a {
412- setA [ingress .Hostname ] = struct {}{}
423+ if ingress .Hostname == "" {
424+ continue
425+ }
426+
427+ portSet := make (map [int32 ]struct {})
428+ for _ , portStatus := range ingress .Ports {
429+ portSet [portStatus .Port ] = struct {}{}
430+ }
431+ hostnameToPortsA [ingress .Hostname ] = portSet
413432 }
414433
415434 for _ , ingress := range b {
416- setB [ingress .Hostname ] = struct {}{}
435+ if ingress .Hostname == "" {
436+ continue
437+ }
438+
439+ portSet := make (map [int32 ]struct {})
440+ for _ , portStatus := range ingress .Ports {
441+ portSet [portStatus .Port ] = struct {}{}
442+ }
443+ hostnameToPortsB [ingress .Hostname ] = portSet
417444 }
418445
419- for key := range setA {
420- if _ , exists := setB [key ]; ! exists {
446+ // Check if the maps are equal (same hostnames with same ports)
447+ if len (hostnameToPortsA ) != len (hostnameToPortsB ) {
448+ return false
449+ }
450+
451+ // Check if all hostnames in A exist in B with the same ports
452+ for hostname , portsA := range hostnameToPortsA {
453+ portsB , exists := hostnameToPortsB [hostname ]
454+ if ! exists {
455+ return false // Hostname in A doesn't exist in B
456+ }
457+
458+ // Check if port sets are equal (same length and same values)
459+ if len (portsA ) != len (portsB ) {
421460 return false
422461 }
462+
463+ // Check if all ports in A exist in B
464+ for port := range portsA {
465+ if _ , exists := portsB [port ]; ! exists {
466+ return false
467+ }
468+ }
423469 }
424470 return true
425471}
0 commit comments