Skip to content

feat: 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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

valerian-roche
Copy link
Contributor

@valerian-roche valerian-roche commented Jul 1, 2025

What does it do ?

This PR adds transformers to the pod informers in the pod and service sources to reduce the resulting memory footprint.

Motivation

As described in the issue, the pod informers currently lead to a large memory usage of the external-dns pods. As the controller only requires a few specific fields we can leverage transformers in the informers to greatly reduce the footprint.
In our environment this reduces the average memory usage by ~10 times, and once using watch list (disabled by default) and the next client-go release, we now have a peak memory usage 10 times smaller, greatly reducing our controller footprint.

This PR does not enable watchlist (but I'll raise a PR to optionally do so) as it is currently not really valuable without a fix in the next release of client-go.

More

  • Yes, this PR title follows Conventional Commits
  • Yes, I added unit tests
  • Yes, I updated end user documentation accordingly Not applicable, this change is purely technical within the informer

Refs: #5595

@k8s-ci-robot k8s-ci-robot requested a review from mloiseleur July 1, 2025 23:12
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 1, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @valerian-roche!

It looks like this is your first PR to kubernetes-sigs/external-dns 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/external-dns has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @valerian-roche. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 1, 2025
@ivankatliarchuk
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 2, 2025
Copy link
Contributor

@ivankatliarchuk ivankatliarchuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a PR open #5583. Not yet merged, as w8 for confirmation.

I think is going to be quite nice to move transfromers under source/informers/transformers.go file. We could identify some cool patterns and parity acros sources.

source/pod.go Outdated
// 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.
podInformer.Informer().SetTransform(func(i interface{}) (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how this is going to work with FQDN template, we could do some pre-processing and attach it as a field ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look at what is needed here.

Copy link
Contributor Author

@valerian-roche valerian-roche Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code I think the informer can be fully split:

  • when fqdnTemplate is unset this change will be used
  • when fqdnTemplate is set we actually do not need the pods at all, only informer events and we can drop even more content. I will update this PR to not use the transformer when the template is set for now.

@valerian-roche
Copy link
Contributor Author

There is a PR open #5583. Not yet merged, as w8 for confirmation.

I think is going to be quite nice to move transfromers under source/informers/transformers.go file. We could identify some cool patterns and parity acros sources.

The shared transformers are an interesting question as each source may use different parts of the pod. I can add one that's the superset (it will still drop a lot of the blueprint) but I'm unsure how this will evolve long term

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from ivankatliarchuk. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Add a transformer to the pods informer of the pod and service sources.

Refs: kubernetes-sigs#5595

Signed-off-by: Valerian Roche <valerian.roche@datadoghq.com>
Copy link
Contributor

@ivankatliarchuk ivankatliarchuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably missing evidences that there is a memory reduction. Rest looks quite nice, going to apply similar transfomers elsewhere soon

Name: pod.Name,
Namespace: pod.Namespace,
// Used by the controller. This includes non-external-dns prefixed annotations.
Annotations: pod.Annotations,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need annotation kubectl.kubernetes.io/last-applied-configuration? Just a question, not a big deal

// 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.
Copy link
Contributor

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

  1. annotationFilter is present
  2. labelSelector is present

@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants