Skip to content

Optimized the Kubernetes API calls. ~97% reduction, removed unused code#69

Merged
EdwardCooke merged 3 commits intomainfrom
ec-optimizeapicalls
Apr 11, 2026
Merged

Optimized the Kubernetes API calls. ~97% reduction, removed unused code#69
EdwardCooke merged 3 commits intomainfrom
ec-optimizeapicalls

Conversation

@EdwardCooke
Copy link
Copy Markdown
Collaborator

The counts are based on

  • 19 ingresses
  • 110 services
  • 114 endpointslices
  • 22 monitored services
  • 21 monitored endpointslices
  • 20 unique hostnames

Results

Original After your changes Remaining
Per full sync ~860+ 7 7
Per event (avg) 3–5 0–1 0–1
Steady state/min ~900+ ~30 ~30

Copilot AI review requested due to automatic review settings April 11, 2026 06:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces Kubernetes API traffic by splitting the cache responsibilities: keeping cluster/hostname cache objects in Kubernetes while moving per-sync/per-event transient data (tracked services, endpoint counts, resource versions) into an in-memory cache, and removing the no-longer-used namespace manager.

Changes:

  • Introduce an in-memory ICache implementation (MemoryCache + BasicCache) and a narrower IKubernetesCache abstraction backed by KubernetesApiCache.
  • Remove INamespaceManager / DefaultNamespaceManager and adjust service registrations + constructors accordingly.
  • Optimize KubernetesApiCache.SynchronizeCachesAsync by reusing already-listed hostname cache objects.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Vecc.K8s.MultiCluster.Api/Vecc.K8s.MultiCluster.Api.csproj Bumps dependencies and adds a caching-related package reference.
src/Vecc.K8s.MultiCluster.Api/Services/INamespaceManager.cs Removes unused namespace manager interface.
src/Vecc.K8s.MultiCluster.Api/Services/IKubernetesCache.cs Adds interface for Kubernetes-backed cache operations.
src/Vecc.K8s.MultiCluster.Api/Services/IBasicCache.cs Adds abstraction over in-memory key/value cache.
src/Vecc.K8s.MultiCluster.Api/Services/Default/KubernetesApiCache.cs Narrows responsibility to Kubernetes persistence + tweaks cache sync logic.
src/Vecc.K8s.MultiCluster.Api/Services/Default/DefaultServiceManager.cs Removes namespace manager dependency from constructor.
src/Vecc.K8s.MultiCluster.Api/Services/Default/DefaultIngressManager.cs Removes namespace manager dependency from constructor.
src/Vecc.K8s.MultiCluster.Api/Services/Default/DefaultHostnameSynchronizer.cs Replaces AutoResetEvent gate with a boolean guard for local sync.
src/Vecc.K8s.MultiCluster.Api/Services/Default/DefaultCache.cs New in-memory ICache implementation wrapping IBasicCache + IKubernetesCache.
src/Vecc.K8s.MultiCluster.Api/Services/Default/DefaultBasicCache.cs New IBasicCache implementation backed by Microsoft.Extensions.Caching.Memory.
src/Vecc.K8s.MultiCluster.Api/Program.cs Registers new caching services and removes namespace manager registration.
src/Vecc.K8s.MultiCluster.Api.Tests/Services/Default/DefaultServiceManagerTests.cs Updates constructor usage after dependency removal.
src/Vecc.K8s.MultiCluster.Api.Tests/Services/Default/DefaultNamespaceManagerTests.cs Removes tests for deleted namespace manager.
src/Vecc.K8s.MultiCluster.Api.Tests/Services/Default/DefaultIngressManagerTests.cs Updates constructor usage after dependency removal.
src/Vecc.K8s.MultiCluster.Api.Tests/Services/Default/DefaultHostnameSynchronizerTests.cs Updates constructor usage after dependency removal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Vecc.K8s.MultiCluster.Api/Services/Default/DefaultCache.cs
Comment thread src/Vecc.K8s.MultiCluster.Api/Services/Default/DefaultCache.cs Outdated
Comment thread src/Vecc.K8s.MultiCluster.Api/Services/Default/DefaultHostnameSynchronizer.cs Outdated
Comment thread src/Vecc.K8s.MultiCluster.Api/Services/Default/KubernetesApiCache.cs Outdated
Comment thread src/Vecc.K8s.MultiCluster.Api/Services/Default/KubernetesApiCache.cs Outdated
Comment thread src/Vecc.K8s.MultiCluster.Api/Vecc.K8s.MultiCluster.Api.csproj Outdated
@EdwardCooke EdwardCooke force-pushed the ec-optimizeapicalls branch from 9f9d7bb to 21bb1a9 Compare April 11, 2026 07:32
@cookew cookew self-requested a review April 11, 2026 11:03
@EdwardCooke EdwardCooke merged commit ed4b22a into main Apr 11, 2026
4 of 5 checks passed
@EdwardCooke EdwardCooke deleted the ec-optimizeapicalls branch April 11, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants