-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(source): use transformers in pod informers to reduce memory footprint #5596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |
|
||
log "github.com/sirupsen/logrus" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
|
||
kubeinformers "k8s.io/client-go/informers" | ||
|
@@ -76,6 +77,40 @@ func NewPodSource( | |
} | ||
|
||
_, _ = podInformer.Informer().AddEventHandler(informers.DefaultEventHandler()) | ||
|
||
if fqdnTemplate == "" { | ||
// Transformer is used to reduce the memory usage of the informer. | ||
// The pod informer will otherwise store a full in-memory, go-typed copy of all pod schemas in the cluster. | ||
// If watchList is not used it will not prevent memory bursts on the initial informer sync. | ||
// When fqdnTemplate is used the entire pod needs to be provided to the rendering call, but the informer itself becomes unneeded. | ||
podInformer.Informer().SetTransform(func(i interface{}) (interface{}, error) { | ||
pod, ok := i.(*corev1.Pod) | ||
if !ok { | ||
return nil, fmt.Errorf("object is not a pod") | ||
} | ||
if pod.UID == "" { | ||
// Pod was already transformed and we must be idempotent. | ||
return pod, nil | ||
} | ||
return &corev1.Pod{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
// Name/namespace must always be kept for the informer to work. | ||
Name: pod.Name, | ||
Namespace: pod.Namespace, | ||
// Used by the controller. This includes non-external-dns prefixed annotations. | ||
Annotations: pod.Annotations, | ||
|
||
}, | ||
Spec: corev1.PodSpec{ | ||
HostNetwork: pod.Spec.HostNetwork, | ||
NodeName: pod.Spec.NodeName, | ||
}, | ||
Status: corev1.PodStatus{ | ||
PodIP: pod.Status.PodIP, | ||
}, | ||
}, nil | ||
}) | ||
} | ||
|
||
_, _ = nodeInformer.Informer().AddEventHandler(informers.DefaultEventHandler()) | ||
|
||
informerFactory.Start(ctx.Done()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth to rebase with master branch. This most likely not going to behave correctly in cases when
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me rebase and assess what we need to store