Skip to content

refactor(informers): unify cache sync functions using generics#6102

Merged
k8s-ci-robot merged 1 commit intokubernetes-sigs:masterfrom
gofogo:refactore-cache-sync
Jan 15, 2026
Merged

refactor(informers): unify cache sync functions using generics#6102
k8s-ci-robot merged 1 commit intokubernetes-sigs:masterfrom
gofogo:refactore-cache-sync

Conversation

@ivankatliarchuk
Copy link
Copy Markdown
Member

@ivankatliarchuk ivankatliarchuk commented Jan 11, 2026

What does it do ?

  • WaitForCacheSync and WaitForDynamicCacheSync unified into a single generic waitForCacheSync[K comparable] function.
  • Changed from awkward "failed to sync %v: %w with timeout %s" to "failed to sync %v after %s: %w" - putting the timeout context before the wrapped error.
  • Replaced wait.NeverStop with ctx.Done() for informer factories, allowing proper context-based cancellation
  • line timeout := defaultRequestTimeout * time.Second noted the current timeout behavior for future consideration.

Something to consider for future.
Found this PR 60c649b#diff-cf68f602fa7c20e5341f3b83054df68ade1586a144b1eae5347e0ac47096d3aa

So in past it was something like

	// wait for the local cache to be populated.
	err = poll(time.Second, 60*time.Second, func() (bool, error) {
		return serviceInformer.Informer().HasSynced() &&
			endpointsInformer.Informer().HasSynced() &&
			podInformer.Informer().HasSynced() &&
			nodeInformer.Informer().HasSynced(), nil
	})
	if err != nil {
		return nil, fmt.Errorf("failed to sync cache: %v", err)

	}

It's basically very historycall.

What is wrong with current timeout := defaultRequestTimeout * time.Second Ignores the caller's context deadline: The function receives a ctx but then creates a new timeout, effectively overriding whatever deadline the caller may have set. If the caller passed a context with a 30s timeout, this function ignores it and waits 60s anyway.

As we supporint context correctly now #6049

We could remove internal timeout entirely - let caller control it. This needs testing

 func waitForCacheSync[K comparable](ctx context.Context, waitFunc func(<-chan struct{}) map[K]bool) error {
      for typ, done := range waitFunc(ctx.Done()) {
          if !done {
              return fmt.Errorf("failed to sync %v: %w", typ, ctx.Err())
          }
      }
      return nil
  }

Motivation

Close #6038

No more work is required for #6038, my understanind when this changes released kubernetes-sigs/gateway-api#4376 we should have al ready and fixed.

More

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

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
@k8s-ci-robot k8s-ci-robot requested a review from vflaux January 11, 2026 17:31
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 11, 2026
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 20899119574

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 28 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.005%) to 78.973%

Files with Coverage Reduction New Missed Lines %
informers/informers.go 2 90.0%
gateway.go 26 85.98%
Totals Coverage Status
Change from base Build 20892650297: 0.005%
Covered Lines: 15955
Relevant Lines: 20203

💛 - Coveralls

@mloiseleur
Copy link
Copy Markdown
Collaborator

/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 15, 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 15, 2026
@k8s-ci-robot k8s-ci-robot merged commit 3356639 into kubernetes-sigs:master Jan 15, 2026
20 checks passed
@ivankatliarchuk ivankatliarchuk deleted the refactore-cache-sync branch January 16, 2026 08:38
ivankatliarchuk added a commit to gofogo/k8s-sigs-external-dns-fork that referenced this pull request Jan 16, 2026
* master: (25 commits)
  feat(event): standardize event messages and add resource kind lookup for events (kubernetes-sigs#6101)
  refactor(informers): unify cache sync functions using generics (kubernetes-sigs#6102)
  fix(fqdn): support kind and api version (kubernetes-sigs#6097)
  test(fqdn): cover sources without any fqdn tests (kubernetes-sigs#6094)
  chore(tools): CRD generation script moved and add validation workflow (kubernetes-sigs#6079)
  fix(metrics): add CNAME to known record types (kubernetes-sigs#6115)
  chore(cloudflare): migrate customhostname to v5 (kubernetes-sigs#5891)
  test(provider/exoscale): improved the test coverage for exoscale provider from 62.8% to 80.4%  (kubernetes-sigs#6112)
  feat(source): gateway api hostname source annotation (kubernetes-sigs#5959)
  test: cover pkg/events/fake package (kubernetes-sigs#6096)
  refactor(controller): controller no longer responsible for SingletonClientGenerator creation (kubernetes-sigs#6077)
  refactor(source): standardize FQDN template accross sources (kubernetes-sigs#6093)
  feat(coredns): rename ownerId and ownedBy to owner (kubernetes-sigs#6032)
  docs: fix typo in README (The are → There are) (kubernetes-sigs#6095)
  refactor(aws): abstract provider-specific boolean parsing (kubernetes-sigs#6078)
  refactor(api): deduplicate addKnownTypes (kubernetes-sigs#6087)
  fix(api): rollback changes for omitempty (kubernetes-sigs#6086)
  chore(deps): bump renovatebot/github-action (kubernetes-sigs#6080)
  fix(aws): enable AWS API validation for routing policies without setIdentifier (kubernetes-sigs#6082)
  chore(aws): document and test behavior for ALB and NLB (kubernetes-sigs#6063)
  ...
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/M Denotes a PR that changes 30-99 lines, ignoring generated files. source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests hang after upgrading to client-go v0.34.x / v0.35.x due to informer and watch lifecycle changes

4 participants