Skip to content

refactor(kubeclient): consolidate duplicate code#6076

Merged
k8s-ci-robot merged 15 commits intokubernetes-sigs:masterfrom
gofogo:chore-kubeconfig
Jan 28, 2026
Merged

refactor(kubeclient): consolidate duplicate code#6076
k8s-ci-robot merged 15 commits intokubernetes-sigs:masterfrom
gofogo:chore-kubeconfig

Conversation

@ivankatliarchuk
Copy link
Copy Markdown
Member

@ivankatliarchuk ivankatliarchuk commented Jan 2, 2026

What does it do ?

Create a new pkg/kubeclient package to consolidate duplicate Kubernetes client creation logic, add metrics instrumentation to the events controller, and use the.

tested here #6099. all works without issues

  1. New centralized package pkg/client/config.go
    • added tests
  2. Removed duplicate code from:
    • source/store.go
    • pkg/events/controller.go
  3. Events client now uses shared clientset

How kube client created and shared with different packages

flowchart TD
    A[externaldns.Config] -->|passed to| B[source.NewClientGenerator]
    B -->|creates| C[SingletonClientGenerator]

    C -->|used by| D[buildController]
    C -->|used by| E[buildSource]

    D -->|calls| F[clientGen.EventsClient]
    F -->|returns| G[EventsV1Interface]
    G -->|passed to| H[events.NewEventController]

    E -->|calls| I[source.ByNames]
    I -->|calls| J[clientGen.KubeClient]
    J -->|returns| K[kubernetes.Interface]
    K -->|used by| L[Sources<br/>Service/Ingress/etc]

    subgraph "Shared Client"
        C
        M[clientGen.KubeClient] -->|creates once| N[kubernetes.Clientset]
        F2[clientGen.EventsClient] -->|delegates to| N
        N -->|.EventsV1| G2[EventsV1Interface]

        style N fill:#99ccff
    end

    style C fill:#ffcc99
    style H fill:#99ff99
    style L fill:#99ff99
Loading

Follow-up

  • better test coverate
  • support events for all sources

Motivation

Currently event generator and source have 2 distinct clients. As a result rate limiting not working as it should on clusters with large ~50k records.

  • Eliminates 3 copies of the same REST config/client creation logic
  • Shared connection pool: Events client now shares HTTP transport and rate limiter with other K8s clients, preventing independent rate limit exhaustion
  • Consistent instrumentation: All clients now guaranteed to have the same Prometheus metrics wrapper
  • Future changes to kube client config (timeouts, TLS, etc.) only need one update

Work relates to

More

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

Follow up:

…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
@k8s-ci-robot k8s-ci-robot added the controller Issues or PRs related to the controller label Jan 2, 2026
@k8s-ci-robot k8s-ci-robot added source size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 2, 2026
@ivankatliarchuk ivankatliarchuk marked this pull request as draft January 2, 2026 10:03
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 2, 2026
@ivankatliarchuk ivankatliarchuk changed the title refactore(kubeclient): consolidate duplicate code to ensure consisten… refactore(kubeclient): consolidate duplicate code Jan 2, 2026
@coveralls
Copy link
Copy Markdown

coveralls commented Jan 2, 2026

Pull Request Test Coverage Report for Build 21311701509

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 473 unchanged lines in 23 files lost coverage.
  • Overall coverage increased (+0.06%) to 79.129%

Files with Coverage Reduction New Missed Lines %
fake.go 1 96.23%
annotations/processors.go 2 97.26%
zonefinder.go 3 90.0%
events/types.go 9 90.44%
execute.go 9 59.94%
node.go 9 90.24%
controller.go 9 92.56%
events/controller.go 10 77.33%
crd.go 10 66.45%
gen/docs/sources/main.go 13 81.7%
Totals Coverage Status
Change from base Build 21060483362: 0.06%
Covered Lines: 16030
Relevant Lines: 20258

💛 - Coveralls

…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 2, 2026
…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
@mloiseleur mloiseleur changed the title refactore(kubeclient): consolidate duplicate code refactor(kubeclient): consolidate duplicate code Jan 2, 2026
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 11, 2026
…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
@ivankatliarchuk ivankatliarchuk marked this pull request as ready for review January 11, 2026 01:17
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 11, 2026
@k8s-ci-robot k8s-ci-robot requested a review from szuecs January 11, 2026 01:17
Copy link
Copy Markdown
Contributor

@vflaux vflaux left a comment

Choose a reason for hiding this comment

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

Just small nitpicks, but LGTM.

…t client creation

Co-authored-by: vflaux <38909103+vflaux@users.noreply.github.com>
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 16, 2026
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 16, 2026
…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
return client, nil
}

func GetRestConfig1(kubeConfig, apiServerURL string) (*rest.Config, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not used but I assume it's related to the TODO of GetRestConfig?
https://github.com/gofogo/k8s-sigs-external-dns-fork/blob/22008dc0327142b1e717b38c945edd0604692216/pkg/client/config.go#L40

Was this committed by mistake?

Copy link
Copy Markdown
Member Author

@ivankatliarchuk ivankatliarchuk Jan 24, 2026

Choose a reason for hiding this comment

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

Yep. Removed. The code works at least on my setups, just not sure what the potential edge cases are

…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
…t client creation

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
@ivankatliarchuk
Copy link
Copy Markdown
Member Author

Hola @vflaux. Is there anything left or we are good to go?

@vflaux
Copy link
Copy Markdown
Contributor

vflaux commented Jan 28, 2026

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 28, 2026
@ivankatliarchuk
Copy link
Copy Markdown
Member Author

/approve

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ivankatliarchuk

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

The pull request process is described here

Details 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 Jan 28, 2026
@k8s-ci-robot k8s-ci-robot merged commit 8e89808 into kubernetes-sigs:master Jan 28, 2026
18 checks passed
@ivankatliarchuk ivankatliarchuk deleted the chore-kubeconfig branch January 28, 2026 21:39
ivankatliarchuk added a commit to gofogo/k8s-sigs-external-dns-fork that referenced this pull request Jan 28, 2026
* master:
  chore(cloudflare): improve tests (kubernetes-sigs#6150)
  refactor(kubeclient): consolidate duplicate code (kubernetes-sigs#6076)
  remove call to get latest kubectl (kubernetes-sigs#6148)
  refactor(aws): extract and restructure alias-handling logic to enable safe upcoming fixes (kubernetes-sigs#6021)
ivankatliarchuk added a commit to gofogo/k8s-sigs-external-dns-fork that referenced this pull request Feb 1, 2026
…_total

* master:
  chore(deps): bump mkdocs-git-revision-date-localized-plugin (kubernetes-sigs#6161)
  fix(annotations): initialize annotation keys at declaration time (kubernetes-sigs#6159)
  chore(linter): unused params and functions linter (kubernetes-sigs#6142)
  docs(fqdn): use correct arguments order in FQDN Templating custom functions (kubernetes-sigs#6144)
  chore(cloudflare): improve tests (kubernetes-sigs#6150)
  refactor(kubeclient): consolidate duplicate code (kubernetes-sigs#6076)
  remove call to get latest kubectl (kubernetes-sigs#6148)
  refactor(aws): extract and restructure alias-handling logic to enable safe upcoming fixes (kubernetes-sigs#6021)
  feat(pihole): deprecate v5 API support (kubernetes-sigs#6123)
  chore(cloudflare): move custom hostnames logic to dedicated files (kubernetes-sigs#6114)
  chore(provider): zone cache provider interface (kubernetes-sigs#6120)
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. controller Issues or PRs related to the controller 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.

4 participants