Skip to content

Commit

Permalink
Pod watch: keep it low volume
Browse files Browse the repository at this point in the history
Addressing PR kubernetes-sigs#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`.
  • Loading branch information
bpineau committed Apr 10, 2020
1 parent 878b9ac commit cb5e850
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
22 changes: 14 additions & 8 deletions internal/ingress/backend/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,10 @@ func (resolver *endpointResolver) resolveIP(ingress *extensions.Ingress, backend
continue
}

// check if all containers are ready
for _, condition := range pod.Status.Conditions {
if condition.Type == api.ContainersReady {
if condition.Status == api.ConditionTrue {
addresses = append(addresses, epAddr)
}
break
}
if IsPodSuitableAsIPTarget(pod) {
addresses = append(addresses, epAddr)
}

}
for _, epAddr := range addresses {
result = append(result, &elbv2.TargetDescription{
Expand Down Expand Up @@ -226,6 +221,17 @@ func IsNodeSuitableAsTrafficProxy(node *corev1.Node) bool {
return false
}

// IsPodSuitableAsIPTarget check whether pod is suitable as a TargetGroup's target
// (currently tested: are all pod's containers ready?).
func IsPodSuitableAsIPTarget(pod *corev1.Pod) bool {
for _, condition := range pod.Status.Conditions {
if condition.Type == api.ContainersReady {
return condition.Status == api.ConditionTrue
}
}
return false
}

// findServiceAndPort returns the service & servicePort by name
func findServiceAndPort(store store.Storer, namespace string, serviceName string, servicePort intstr.IntOrString) (*corev1.Service, *corev1.ServicePort, error) {
serviceKey := namespace + "/" + serviceName
Expand Down
10 changes: 7 additions & 3 deletions internal/ingress/controller/handlers/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package handlers

import (
"context"
"reflect"

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

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

// Update is called in response to an update event - e.g. Pod Updated.
func (h *EnqueueRequestsForPodsEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
podOld := e.ObjectOld.(*corev1.Pod)
podNew := e.ObjectNew.(*corev1.Pod)
if !reflect.DeepEqual(podOld, podNew) {

// we only enqueue reconcile events for pods whose containers changed state
// (ContainersReady vs not ContainersReady).
if backend.IsPodSuitableAsIPTarget(podNew) != backend.IsPodSuitableAsIPTarget(podOld) {
// ... and only for pods referenced by an endpoint backing an ingress:
h.enqueueImpactedIngresses(podNew, queue)
}
}
Expand Down Expand Up @@ -96,6 +99,7 @@ func (h *EnqueueRequestsForPodsEvent) enqueueImpactedIngresses(pod *corev1.Pod,
Name: ingress.Name,
},
})
break
}
}
}
Expand Down

0 comments on commit cb5e850

Please sign in to comment.