Skip to content

TargetLoader + TargetReconciler architecture#52

Open
denyost wants to merge 92 commits into
mainfrom
feature/limit-target-loading
Open

TargetLoader + TargetReconciler architecture#52
denyost wants to merge 92 commits into
mainfrom
feature/limit-target-loading

Conversation

@denyost
Copy link
Copy Markdown
Collaborator

@denyost denyost commented Apr 17, 2026

Introduces per target channel buffering with options for a snapshot- or event-based discovery approach. It also introduces a generic registry that is being used to communicate between the apiserver (webhook) and the message processor.

Core

  • internal/controller/discovery/core/message_interface.go: Discovery messages such as DiscoveryEvent and DiscoverySnapshot become typed unions.
  • internal/controller/discovery/core/types.go: Adjusted types to support the DiscoveryMessage abstraction (e.g., DiscoveredTarget, DiscoverySnapshot, DiscoveryEvent, EventAction).

Loaders

  • internal/controller/discovery/loaders/utils: Implements helper functions specific to loaders (like send.go).

Discovery

  • internal/controller/discovery/const.go: holds labels used in context with Kubernetes.
  • internal/controller/discovery/registry.go: A generic implementation of a registry providing functions like NewRegistry, Register and Unregister
  • internal/controller/discovery/loaders.go: Creates the specific loader based on the configured Spec within TargetSource.
  • internal/controller/discovery/message_processor.go: Updated to use the new DiscoveryMessage interface; handles both DiscoverySnapshot and DiscoveryEvent via type assertion/dispatch.
    • Improved error handling and context cancelation.
    • Interacts with internal/controller/discovery/client.go, which interacts with Kubernetes.

Controller wiring & refactor

  • internal/controller/targetsource_controller.go: Reconciler refactor to improve clarity.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 17, 2026

Deploying gnmic-operator with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3280229
Status: ✅  Deploy successful!
Preview URL: https://84bbb1ef.gnmic-operator2.pages.dev
Branch Preview URL: https://feature-limit-target-loading.gnmic-operator2.pages.dev

View logs

@denyost denyost changed the title limit target loading feature/limit target loading Apr 22, 2026
@denyost denyost added the enhancement New feature or request label Apr 24, 2026
@Janooski Janooski marked this pull request as draft April 30, 2026 18:11
@mcdillson mcdillson marked this pull request as ready for review May 4, 2026 17:28
@mcdillson mcdillson requested a review from karimra May 4, 2026 17:29
@denyost
Copy link
Copy Markdown
Collaborator Author

denyost commented May 6, 2026

@karimra can you please review this PR and merge if ok.

Comment thread internal/controller/discovery/message_processor.go
cleanup := func() {
cancel()
r.DiscoveryRegistry.Unregister(key)
close(targetChannel)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you should not close the channel here. cleanup is called by 2 different goroutines when they exist (that's panic closing of a closed channel) and if you enable push, any inflight webhook will send into a closed channel.

Copy link
Copy Markdown
Collaborator Author

@denyost denyost May 13, 2026

Choose a reason for hiding this comment

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

fix:

  • removed close(targetChannel) -> now only context cancellation is used
  • cleanup function is no longer called in the loader goroutine -> context cancellation and registry cleanup are now triggered only when the processor can no longer handle messages or when the loader configuration was invalid

// Delete buffered events that will be current with new snapshot
m.deferredEvents = nil

m.collectSnapshot(chunk, logger)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ignored error

)

// NewLoader creates a loader by name
func NewLoader(cfg core.CommonLoaderConfig, spec *gnmicv1alpha1.TargetSourceSpec) (core.Loader, core.CommonLoaderConfig, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this function doesn't need to return the config it received.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fix: resolved pointer and return smells

  • In NewLoader, the decision whether to accept webhook pushes has to be persisted in the registry
  • Since the registry lives in the targetsource_controller, a pointer is used to update its configuration directly instead of returning it
  • This allows the API endpoint to check if pushes from a given TargetSource should be accepted

Comment thread internal/controller/discovery/loaders.go Outdated
@denyost denyost requested a review from karimra May 13, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants