Skip to content

Conversation

ivankatliarchuk
Copy link
Contributor

@ivankatliarchuk ivankatliarchuk commented Jun 2, 2025

What does it do ?

Relates #5243

Motivation

Working with CRD, I found that labels applied in a loop, such as ResourceLabelKey. The flow looks like that

flowchart TD
    A[Start Endpoints Method] --> B[List DNSEndpoints from Informer]
    B --> C{Error?}
    C -- Yes --> Z[Return Error]
    C -- No --> D[Loop over DNSEndpoint Items]
    D --> E[Extract Metadata and TTL]
    E --> F[Loop over Spec.Endpoints]
    F --> G[Convert to endpoint.Endpoint]
    G --> H[Call setResourceLabel]
    H --> I[Loop over Labels to set resource label]
    I --> J[Append to Final Result List]
    J --> K{More Spec.Endpoints?}
    K -- Yes --> F
    K -- No --> L{More DNSEndpoints?}
    L -- Yes --> D
    L -- No --> M[Return Final Result List]
Loading

Let:

  • n = number of DNSEndpoint resources
  • m = average number of .Spec.Endpoints per resource
  • k = average number of Labels in each resource

Then:

  • Outer loop: n

  • Inner loop: m (per .Spec.Endpoints)

  • Nested call: setResourceLabel includes another loop of k

  • Overall time complexity:
    O(n * m + n * k)

With this tweak, reducing time complexity to O(n * m). Not a massive gain, but still.

follow-up:

  • review other sources, seems like not every source is setting ResourceLabelKey or setting them in a loop.
  • other sources not testing where or not ResourceLabelKey is set for generated endpoints

More

  • Yes, this PR title follows Conventional Commits
  • Yes, I added unit tests
  • Yes, I updated end user documentation accordingly

switch to more efficient string slicer

Screenshot 2025-06-02 at 09 24 26

@k8s-ci-robot k8s-ci-robot requested review from mloiseleur and szuecs June 2, 2025 08:39
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 2, 2025
@ivankatliarchuk ivankatliarchuk changed the title chore(source/crd): add labels without looping over chore(source/crd): add ep labels without looping over Jun 2, 2025
@mloiseleur mloiseleur changed the title chore(source/crd): add ep labels without looping over chore(source/crd): optimize endpoint labels without looping over Jun 3, 2025
Copy link
Collaborator

@mloiseleur mloiseleur left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 3, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mloiseleur

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 3, 2025
@k8s-ci-robot k8s-ci-robot merged commit 00fde1e into kubernetes-sigs:master Jun 3, 2025
14 checks passed
@ivankatliarchuk ivankatliarchuk deleted the chore-source-labels branch June 3, 2025 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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