Skip to content

Commit 2e17d6b

Browse files
authored
fix(ingress): comparing status enhancement (#503)
Signed-off-by: Dario Tranchitella <[email protected]>
1 parent 00356d8 commit 2e17d6b

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

internal/resources/k8s_ingress_resource.go

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,49 @@ func (r *KubernetesIngressResource) ShouldStatusBeUpdated(_ context.Context, tcp
3030
case tcp.Spec.ControlPlane.Ingress == nil && tcp.Status.Kubernetes.Ingress == nil:
3131
// No update in case of no ingress in spec, neither in status.
3232
return false
33-
case tcp.Spec.ControlPlane.Ingress != nil && tcp.Status.Kubernetes.Ingress == nil,
34-
// Must be updated when TCP is using an Ingress, and status is not tracking it
35-
// or
36-
// Must be updated when the status is referring to an Ingress, although spec doesn't.
37-
tcp.Spec.ControlPlane.Ingress == nil && tcp.Status.Kubernetes.Ingress != nil:
33+
case tcp.Spec.ControlPlane.Ingress != nil && tcp.Status.Kubernetes.Ingress == nil, // TCP is using an Ingress, Status not tracking it
34+
tcp.Spec.ControlPlane.Ingress == nil && tcp.Status.Kubernetes.Ingress != nil: // Status tracks an Ingress, Spec doesn't
3835
return true
39-
case len(r.resource.Status.LoadBalancer.Ingress) > 0 && tcp.Status.Kubernetes.Ingress == nil || tcp.Status.Kubernetes.Ingress.LoadBalancer.Ingress == nil:
40-
// Must be updated since missing the Ingress status
41-
return true
42-
case r.resource.Status.LoadBalancer.Ingress[0].IP != tcp.Status.Kubernetes.Ingress.LoadBalancer.Ingress[0].IP:
43-
// Must bne updated, Ingress load balancer IP is slightly different
36+
case len(tcp.Status.Kubernetes.Ingress.IngressStatus.LoadBalancer.Ingress) != len(r.resource.Status.LoadBalancer.Ingress):
37+
// Mismatch count of tracked LoadBalancer Ingress
4438
return true
4539
default:
46-
return tcp.Status.Kubernetes.Ingress.Name != r.resource.GetName() || tcp.Status.Kubernetes.Ingress.Namespace != r.resource.GetNamespace()
40+
statusIngress := tcp.Status.Kubernetes.Ingress.IngressStatus.LoadBalancer.Ingress
41+
42+
for i, ingress := range r.resource.Status.LoadBalancer.Ingress {
43+
if ingress.IP != statusIngress[i].IP {
44+
return true
45+
}
46+
47+
if len(ingress.Ports) != len(statusIngress[i].Ports) {
48+
return true
49+
}
50+
51+
for p, port := range ingress.Ports {
52+
if port.Port != statusIngress[i].Ports[p].Port {
53+
return true
54+
}
55+
56+
if port.Protocol != statusIngress[i].Ports[p].Protocol {
57+
return true
58+
}
59+
60+
if port.Error == nil && statusIngress[i].Ports[p].Error != nil ||
61+
port.Error != nil && statusIngress[i].Ports[p].Error == nil {
62+
return true
63+
}
64+
65+
if port.Error == nil && statusIngress[i].Ports[p].Error == nil {
66+
continue
67+
}
68+
69+
if *port.Error != *statusIngress[i].Ports[p].Error {
70+
return true
71+
}
72+
}
73+
}
74+
75+
return false
4776
}
4877
}
4978

0 commit comments

Comments
 (0)