Skip to content

Commit 2cf2c2a

Browse files
committed
Pod watch: keep it low volume
Addressing PR #1214 comments: bubbling up all (ingress backing) pods events to main reconcile loop might trigger an excessive AWS API calls volume. Let's keep that pod watch noise to the minimum requiered for readiness gates: catching changes in `ContainerReady`.
1 parent 2872d85 commit 2cf2c2a

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

internal/ingress/backend/endpoint.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,10 @@ func (resolver *endpointResolver) resolveIP(ingress *extensions.Ingress, backend
182182
continue
183183
}
184184

185-
// check if all containers are ready
186-
for _, condition := range pod.Status.Conditions {
187-
if condition.Type == api.ContainersReady {
188-
if condition.Status == api.ConditionTrue {
189-
addresses = append(addresses, epAddr)
190-
}
191-
break
192-
}
185+
if IsPodSuitableAsIPTarget(pod) {
186+
addresses = append(addresses, epAddr)
193187
}
188+
194189
}
195190
for _, epAddr := range addresses {
196191
result = append(result, &elbv2.TargetDescription{
@@ -226,6 +221,17 @@ func IsNodeSuitableAsTrafficProxy(node *corev1.Node) bool {
226221
return false
227222
}
228223

224+
// IsPodSuitableAsIPTarget check whether pod is suitable as a TargetGroup's target
225+
// (currently tested: are all pod's containers ready?).
226+
func IsPodSuitableAsIPTarget(pod *corev1.Pod) bool {
227+
for _, condition := range pod.Status.Conditions {
228+
if condition.Type == api.ContainersReady {
229+
return condition.Status == api.ConditionTrue
230+
}
231+
}
232+
return false
233+
}
234+
229235
// findServiceAndPort returns the service & servicePort by name
230236
func findServiceAndPort(store store.Storer, namespace string, serviceName string, servicePort intstr.IntOrString) (*corev1.Service, *corev1.ServicePort, error) {
231237
serviceKey := namespace + "/" + serviceName

internal/ingress/controller/handlers/pod.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package handlers
22

33
import (
44
"context"
5-
"reflect"
65

76
"github.com/golang/glog"
87
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/alb/tg"
98
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/ingress/annotations/class"
9+
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/ingress/backend"
1010
corev1 "k8s.io/api/core/v1"
1111
extensions "k8s.io/api/extensions/v1beta1"
1212
"k8s.io/apimachinery/pkg/types"
@@ -27,14 +27,17 @@ type EnqueueRequestsForPodsEvent struct {
2727

2828
// Create is called in response to an create event - e.g. Pod Creation.
2929
func (h *EnqueueRequestsForPodsEvent) Create(e event.CreateEvent, queue workqueue.RateLimitingInterface) {
30-
h.enqueueImpactedIngresses(e.Object.(*corev1.Pod), queue)
3130
}
3231

3332
// Update is called in response to an update event - e.g. Pod Updated.
3433
func (h *EnqueueRequestsForPodsEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
3534
podOld := e.ObjectOld.(*corev1.Pod)
3635
podNew := e.ObjectNew.(*corev1.Pod)
37-
if !reflect.DeepEqual(podOld, podNew) {
36+
37+
// we only enqueue reconcile events for pods whose containers changed state
38+
// (ContainersReady vs not ContainersReady).
39+
if backend.IsPodSuitableAsIPTarget(podNew) != backend.IsPodSuitableAsIPTarget(podOld) {
40+
// ... and only for pods referenced by an endpoint backing an ingress:
3841
h.enqueueImpactedIngresses(podNew, queue)
3942
}
4043
}
@@ -96,6 +99,7 @@ func (h *EnqueueRequestsForPodsEvent) enqueueImpactedIngresses(pod *corev1.Pod,
9699
Name: ingress.Name,
97100
},
98101
})
102+
break
99103
}
100104
}
101105
}

0 commit comments

Comments
 (0)