-
Notifications
You must be signed in to change notification settings - Fork 1
feat(gateway): reconcile tenant VRF egress default routes #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
privateip
wants to merge
1
commit into
feat/865-egress-phase-c
Choose a base branch
from
feat/865-egress-phase-d
base: feat/865-egress-phase-c
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -282,6 +282,14 @@ func runCmd(cfg *config.RouterConfig) error { | |
| } | ||
| }() | ||
|
|
||
| // Register EgressRoute controller and start its ticker goroutine | ||
| // (datum-cloud/enhancements#865, design plan §4.4/§7.1) -- extracted | ||
| // to its own function to keep this function's own cyclomatic | ||
| // complexity down (gocyclo), not for any reuse reason. | ||
| if err := startEgressRouteController(ctx, mgr, cfg, nodeName); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := mgr.Start(ctx); err != nil { | ||
| return fmt.Errorf("manager exited: %w", err) | ||
| } | ||
|
|
@@ -296,6 +304,52 @@ func runCmd(cfg *config.RouterConfig) error { | |
| return nil | ||
| } | ||
|
|
||
| // startEgressRouteController registers controller.EgressRouteReconciler and | ||
| // starts its ticker goroutine, reconciling tenant VRF ::/0 default routes | ||
| // toward each VPC's assigned gateway egress_sid (datum-cloud/ | ||
| // enhancements#865, design plan §4.4/§7.1). Mirrors the GC ticker in | ||
| // runCmd exactly (including waiting for cache sync first, so the initial | ||
| // pass doesn't see an empty NetworkEgressPolicy list and remove every live | ||
| // egress route) -- reuses cfg.GCNamespace (both scan the same namespace's | ||
| // CRDs) but its own separate interval, see DefaultRouterEgressRouteInterval's | ||
| // doc comment for why. | ||
| func startEgressRouteController( | ||
| ctx context.Context, mgr ctrl.Manager, cfg *config.RouterConfig, nodeName string, | ||
| ) error { | ||
| rec := &controller.EgressRouteReconciler{ | ||
| Client: mgr.GetClient(), | ||
| Scheme: mgr.GetScheme(), | ||
| Namespace: cfg.GCNamespace, | ||
| NodeName: nodeName, | ||
| Interval: cfg.EgressRouteInterval, | ||
| } | ||
| if err := rec.SetupWithManager(mgr); err != nil { | ||
| return fmt.Errorf("setup EgressRoute controller: %w", err) | ||
| } | ||
|
|
||
| go func() { | ||
| ticker := time.NewTicker(cfg.EgressRouteInterval) | ||
| defer ticker.Stop() | ||
|
|
||
| if !mgr.GetCache().WaitForCacheSync(ctx) { | ||
| log.Printf("EgressRoute: cache sync failed, skipping initial pass") | ||
| return | ||
| } | ||
| rec.RunOnce(ctx) | ||
|
|
||
| for { | ||
| select { | ||
| case <-ctx.Done(): | ||
| return | ||
| case <-ticker.C: | ||
| rec.RunOnce(ctx) | ||
| } | ||
| } | ||
| }() | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // newRootCommand builds the root cobra command with all flags and the | ||
| // application startup logic. | ||
| func newRootCommand() *cobra.Command { | ||
|
|
@@ -344,6 +398,9 @@ func newRootCommand() *cobra.Command { | |
| cmd.Flags().DurationP("gc-interval", "", | ||
| config.DefaultRouterGCInterval, | ||
| "Cleanup interval") | ||
| cmd.Flags().DurationP("egress-route-interval", "", | ||
| config.DefaultRouterEgressRouteInterval, | ||
| "Egress default-route reconcile interval (datum-cloud/enhancements#865)") | ||
|
Comment on lines
+401
to
+403
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The link to an enhancement here is a little odd. |
||
| cmd.Flags().Bool("webhook-enabled", false, | ||
| "Enable the NetworkRule admission webhook (requires TLS cert material; see config/webhook/)") | ||
| cmd.Flags().IntP("webhook-port", "", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright 2026 Datum Cloud, Inc. | ||
| // | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| package controller | ||
|
|
||
| import ( | ||
| "context" | ||
| "log/slog" | ||
| "time" | ||
|
|
||
| "k8s.io/apimachinery/pkg/runtime" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| "go.datum.net/galactic/internal/egressroute" | ||
| ) | ||
|
|
||
| // EgressRouteReconciler runs periodic egress default-route reconciliation | ||
| // on this compute node (datum-cloud/enhancements#865, design plan | ||
| // §4.4/§7.1) — the ticker-driven wrapper around internal/egressroute.Run, | ||
| // mirroring GCReconciler's own split between a thin, time-driven | ||
| // controller here and the real logic in a sibling non-controller package | ||
| // (internal/gc). Unlike NetworkGatewayReconciler/NetworkEgressPolicyReconciler | ||
| // (gateway-node-scoped, registered from cmd/galactic-gateway), this runs | ||
| // from cmd/galactic-router's tenant-role process: it needs to see every | ||
| // compute node's own local VRF state, not just gateway nodes', and | ||
| // galactic-router (tenant role) already runs on every node that could have | ||
| // one. | ||
| // | ||
| // Time-driven, not object-driven, for the same reason GCReconciler is: a | ||
| // newly-created local VRF interface is pure kernel state with no | ||
| // corresponding Kubernetes watch event to react to, so this can only ever | ||
| // notice it on a periodic sweep, not a reactive one. | ||
| type EgressRouteReconciler struct { | ||
| client.Client | ||
| Scheme *runtime.Scheme | ||
| Namespace string | ||
| NodeName string | ||
| Interval time.Duration | ||
| } | ||
|
|
||
| // slogAdapter adapts log/slog's package-level functions to | ||
| // egressroute.Logger, matching GCReconciler's own choice of slog over | ||
| // logr.Logger for this package's plain log lines (see gc_controller.go's | ||
| // identical use of slog.Info/slog.Error at its own call sites). | ||
| type slogAdapter struct{} | ||
|
|
||
| func (slogAdapter) Info(msg string, keysAndValues ...any) { slog.Info(msg, keysAndValues...) } | ||
| func (slogAdapter) Error(err error, msg string, keysAndValues ...any) { | ||
| slog.Error(msg, append([]any{"err", err}, keysAndValues...)...) | ||
| } | ||
|
|
||
| // Reconcile runs an egress-route pass at the configured interval. It does | ||
| // not watch any Kubernetes resources — it is purely time-driven, same as | ||
| // GCReconciler.Reconcile. | ||
| func (r *EgressRouteReconciler) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) { | ||
| if r.Namespace == "" { | ||
| slog.Debug("EgressRoute: namespace not configured, skipping") | ||
| return ctrl.Result{RequeueAfter: r.Interval}, nil | ||
| } | ||
|
|
||
| result := r.RunOnce(ctx) | ||
| if result.Errors > 0 { | ||
| slog.Info("EgressRoute: completed with errors", | ||
| "routesInstalled", result.RoutesInstalled, "routesRemoved", result.RoutesRemoved, "errors", result.Errors) | ||
| } else if result.RoutesInstalled > 0 || result.RoutesRemoved > 0 { | ||
| slog.Info("EgressRoute: reconcile complete", | ||
| "routesInstalled", result.RoutesInstalled, "routesRemoved", result.RoutesRemoved) | ||
| } | ||
|
|
||
| return ctrl.Result{RequeueAfter: r.Interval}, nil | ||
| } | ||
|
|
||
| // SetupWithManager registers the EgressRouteReconciler with the manager. | ||
| // Like GCReconciler, it is started by a ticker goroutine launched from | ||
| // root.go where the manager's context is available. | ||
| func (r *EgressRouteReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
| if r.Interval == 0 { | ||
| r.Interval = 5 * time.Minute | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // RunOnce runs a single egress-route reconcile pass in the given context. | ||
| // This is the public API for triggering it from outside the reconciler | ||
| // (e.g. root.go's ticker goroutine), mirroring GCReconciler.RunGC. | ||
| func (r *EgressRouteReconciler) RunOnce(ctx context.Context) egressroute.Result { | ||
| return egressroute.Run(ctx, r.Client, r.Namespace, r.NodeName, slogAdapter{}) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why's this use a separate ticker process for reconciling things instead of leveraging the normal controller runtime behavior?