Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions docs/agents/ARCHITECTURE-GATEWAY.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,24 @@ that converges this node's whole gateway engine:
as its
own `<node>/Programmed` condition (`Programmed`, `BackendsUnresolved`,
`LoadFailed`, `InvalidRule`, or `NoServedVIP` for an IPv4-only rule, with
the error or the unresolved backends in the message), and, for a rule
with an IPv4 VIP, a `<node>/IPv4Served` condition: `True` with reason
the error or the unresolved backends in the message), a
`<node>/Advertised` condition (`advertisedCondition`: `True` with
`Advertised` once the node published the rule's `BGPAdvertisement`s and
`galactic-router` reports each one `Advertised` for its current
generation (`uninstalledAdvertisements`), or `False` with
`NotProgrammed`, `NoRouter`, `AdvertisementFailed` or
`AdvertisementPending`, so a rule's publish failure is on the rule and not
only on the node's `NetworkGateway`; a status write that changes whether
one of its advertisements is installed wakes the pass, `installedChanged`),
and, for a rule with an IPv4 VIP, a
`<node>/IPv4Served` condition: `True` with reason
`Advertised`, or `False` with `NotAdvertised` (loaded over Bound backends
but the route not published), `BindingsNotBound` (loaded, no backend
Bound), `Unsupported` (switch off), `NoBackend`, `MultipleVIPs` or
`NotLoaded` (the rule as a whole is not loaded). The first three mean
loaded (`ipv4LoadedReasons`), and `galactic-router` writes a rule's IPv4
bindings only while some node reports one of them. Every pass also
removes the `Programmed` and `IPv4Served` conditions of any node no
removes the `Programmed`, `Advertised` and `IPv4Served` conditions of any node no
`NetworkGateway` in the namespace targets (`departedGatewayNodes`,
`removeDepartedNodeConditions`), so a node that left without its
conditions being cleared cannot keep a loaded reason, and with it the
Expand All @@ -326,7 +335,23 @@ that converges this node's whole gateway engine:
`NetworkService` status is shared by every gateway node while loading
is per node; a node writes it only when it changes, and a
departing, deleted, or disabled node's conditions are removed with its
advertisements. The `NetworkGateway`'s `EngineDegraded` message
advertisements. `NetworkServiceReconciler` then rolls every node's
conditions up into rule-wide ones, `Programmed`, `Advertised`,
`BackendsReady`, `IPv4Served` (only on a rule with an IPv4 VIP) and
`Ready` (`summaryConditions`,
`internal/controller/networkservice_summary.go`), so a client such as the
tenant-facing API reads one rule and never `NetworkGateway` (#708). Only
gateway nodes reporting a `Programmed` condition for the current
generation count, since a node that has not reported advertises nothing.
`Ready` reads `IPv4Served` only for a rule with no IPv6 VIP, so a rule
whose IPv6 VIP serves is not reported down on gateways with IPv4 VIPs
off. The summary is re-read uncached (`APIReader`), so it computes from
the write that triggered it.
A failing summary takes the reason every failing node shares, or a
generic one when they differ. Every input is shared state, so every
gateway node computes the same summary and writes it only when it
changes; `clearNodeRuleConditions` recomputes it too, for the last
gateway node to leave. The `NetworkGateway`'s `EngineDegraded` message
lists every failed rule. Every rule
advertisement carries a `networkRuleLabel` label and a plain (not
controller, no `blockOwnerDeletion`) owner reference to its
Expand Down
86 changes: 73 additions & 13 deletions docs/gateway/configuration.md

Large diffs are not rendered by default.

204 changes: 172 additions & 32 deletions internal/controller/networkgateway_controller.go

Large diffs are not rendered by default.

98 changes: 97 additions & 1 deletion internal/controller/networkgateway_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/client/interceptor"
"sigs.k8s.io/controller-runtime/pkg/event"

cloudv1alpha1 "go.datum.net/galactic/api/cloud/v1alpha1"
bgpv1alpha1 "go.datum.net/galactic/api/network/v1alpha1"
Expand Down Expand Up @@ -192,6 +193,24 @@ func assertRuleProgrammed(t *testing.T, c client.Client, status metav1.Condition
}
}

// assertRuleAdvertised fails the test unless testNodeGWA's Advertised
// condition on testRuleName has the given status and reason.
func assertRuleAdvertised(t *testing.T, c client.Client, status metav1.ConditionStatus, reason string) {
t.Helper()
rule := &bgpv1alpha1.NetworkService{}
if err := c.Get(context.Background(), testRuleKey(testRuleName), rule); err != nil {
t.Fatalf("get NetworkService %s: %v", testRuleName, err)
}
cond := meta.FindStatusCondition(rule.Status.Conditions, advertisedConditionType(testNodeGWA))
if cond == nil {
t.Fatalf("NetworkService %s has no %s condition", testRuleName, advertisedConditionType(testNodeGWA))
}
if cond.Status != status || cond.Reason != reason {
t.Errorf("NetworkService %s %s = %s/%s, want %s/%s",
testRuleName, cond.Type, cond.Status, cond.Reason, status, reason)
}
}

func TestNetworkGatewayReconciler_SkipsNonMatchingNode(t *testing.T) {
scheme := newRuleTestScheme(t)
gw := newTestGateway(testNodeGWA)
Expand Down Expand Up @@ -742,6 +761,7 @@ func TestNetworkGatewayReconciler_SkipsBGPAdvertisementWiringWithoutRouter(t *te
if len(advList.Items) != 1 {
t.Fatalf("expected only the pre-seeded backend BGPAdvertisement, got %d", len(advList.Items))
}
assertRuleAdvertised(t, fakeClient, metav1.ConditionFalse, reasonNoRouter)
}

// TestNetworkGatewayReconciler_CreatesBGPAdvertisement covers the anycast
Expand Down Expand Up @@ -904,6 +924,10 @@ func TestNetworkGatewayReconciler_AdvertisementFailureSurfaces(t *testing.T) {
if !strings.Contains(cond.Message, testRuleName) {
t.Errorf("Ready message = %q, want it to name the failing NetworkService %q", cond.Message, testRuleName)
}
// The failure is on the rule too, so a reader of the rule alone sees it
// (#708).
assertRuleProgrammed(t, fakeClient, metav1.ConditionTrue, reasonProgrammed)
assertRuleAdvertised(t, fakeClient, metav1.ConditionFalse, reasonAdvertisementFailed)
}

// TestNetworkGatewayReconciler_ReportsEngineHealthyOnCleanPass is the
Expand All @@ -919,7 +943,7 @@ func TestNetworkGatewayReconciler_ReportsEngineHealthyOnCleanPass(t *testing.T)
acceptRule(rule)

fakeClient := newIndexedClientBuilder(scheme).
WithStatusSubresource(&bgpv1alpha1.NetworkGateway{}, &bgpv1alpha1.NetworkService{}).
WithStatusSubresource(&bgpv1alpha1.NetworkGateway{}, &bgpv1alpha1.NetworkService{}, &bgpv1alpha1.BGPAdvertisement{}).
WithObjects(gwA, router, backendRouter, backendAdv, backendVRF, newBackendAttachment("vpc-1"), rule).
Build()

Expand All @@ -944,6 +968,72 @@ func TestNetworkGatewayReconciler_ReportsEngineHealthyOnCleanPass(t *testing.T)
t.Errorf("Ready reason = %q, want %q", cond.Reason, reasonEngineHealthy)
}
assertRuleProgrammed(t, fakeClient, metav1.ConditionTrue, reasonProgrammed)
// Published, but no galactic-router has reported the route advertised.
assertRuleAdvertised(t, fakeClient, metav1.ConditionFalse, reasonAdvertisementPending)

markAdvertised(t, fakeClient, testRuleAdv)
if _, err := r.Reconcile(context.Background(), req); err != nil {
t.Fatalf("second Reconcile: unexpected error: %v", err)
}
assertRuleAdvertised(t, fakeClient, metav1.ConditionTrue, reasonAdvertised)
}

// markAdvertised sets the named BGPAdvertisement's Advertised condition True
// for its current generation, as galactic-router does once GoBGP carries it.
func markAdvertised(t *testing.T, c client.Client, name string) {
t.Helper()
adv := &bgpv1alpha1.BGPAdvertisement{}
if err := c.Get(context.Background(), testRuleKey(name), adv); err != nil {
t.Fatalf("get BGPAdvertisement %s: %v", name, err)
}
meta.SetStatusCondition(&adv.Status.Conditions, metav1.Condition{
Type: ConditionAdvertised, Status: metav1.ConditionTrue, Reason: reasonAdvertised,
ObservedGeneration: adv.Generation,
})
if err := c.Status().Update(context.Background(), adv); err != nil {
t.Fatalf("update BGPAdvertisement %s status: %v", name, err)
}
}

// TestBackendAdvertisementPredicate_RuleAdvertisementInstalled checks a
// status write that changes whether a rule advertisement is installed wakes
// the gateway, and one that changes nothing else does not.
func TestBackendAdvertisementPredicate_RuleAdvertisementInstalled(t *testing.T) {
old := newNodeAdvertisement(testRuleName, testNodeGWA, "v6")
old.Generation = 2
installed := old.DeepCopy()
meta.SetStatusCondition(&installed.Status.Conditions, metav1.Condition{
Type: ConditionAdvertised, Status: metav1.ConditionTrue, Reason: reasonAdvertised, ObservedGeneration: 2,
})
stale := old.DeepCopy()
meta.SetStatusCondition(&stale.Status.Conditions, metav1.Condition{
Type: ConditionAdvertised, Status: metav1.ConditionTrue, Reason: reasonAdvertised, ObservedGeneration: 1,
})
backend := newAdvertisement("backend")
backendInstalled := backend.DeepCopy()
meta.SetStatusCondition(&backendInstalled.Status.Conditions, metav1.Condition{
Type: ConditionAdvertised, Status: metav1.ConditionTrue, Reason: reasonAdvertised,
})

p := backendAdvertisementPredicate()
tests := []struct {
name string
old, new client.Object
want bool
}{
{"rule advertisement installed", old, installed, true},
{"rule advertisement withdrawn", installed, old, true},
{"installed for an older generation only", old, stale, false},
{"unrelated status write", installed, installed.DeepCopy(), false},
{"backend advertisement status", backend, backendInstalled, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := p.Update(event.UpdateEvent{ObjectOld: tt.old, ObjectNew: tt.new}); got != tt.want {
t.Errorf("Update = %v, want %v", got, tt.want)
}
})
}
}

// errLoadQuota is the load failure the #712 regression tests make the fake
Expand Down Expand Up @@ -1491,6 +1581,9 @@ func TestNetworkGatewayReconciler_ClearsDepartedNodeProgrammedCondition(t *testi
meta.SetStatusCondition(&rule.Status.Conditions, metav1.Condition{
Type: programmedConditionType(node), Status: metav1.ConditionTrue, Reason: reasonProgrammed,
})
meta.SetStatusCondition(&rule.Status.Conditions, metav1.Condition{
Type: advertisedConditionType(node), Status: metav1.ConditionTrue, Reason: reasonAdvertised,
})
}

fakeClient := newIndexedClientBuilder(scheme).
Expand All @@ -1511,6 +1604,9 @@ func TestNetworkGatewayReconciler_ClearsDepartedNodeProgrammedCondition(t *testi
if meta.FindStatusCondition(got.Status.Conditions, programmedConditionType(testNodeGWB)) != nil {
t.Errorf("departed node %s's condition is still on NetworkService %s", testNodeGWB, testRuleName)
}
if meta.FindStatusCondition(got.Status.Conditions, advertisedConditionType(testNodeGWB)) != nil {
t.Errorf("departed node %s's Advertised condition is still on NetworkService %s", testNodeGWB, testRuleName)
}
if meta.FindStatusCondition(got.Status.Conditions, programmedConditionType(testNodeGWA)) == nil {
t.Errorf("surviving node %s's condition was removed from NetworkService %s", testNodeGWA, testRuleName)
}
Expand Down
11 changes: 8 additions & 3 deletions internal/controller/networkservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ func gatewayNodeLabelValue(nodeName string) string {

// NetworkServiceReconciler owns the per-object NetworkService lifecycle that
// NetworkGatewayReconciler's aggregate, list-driven loop is the wrong place
// for: setting the Accepted condition once gateway nodes exist, and the
// finalizer-guarded teardown ordering on deletion.
// for: setting the Accepted condition once gateway nodes exist, the
// rule-wide summary conditions (summaryConditions), and the finalizer-guarded
// teardown ordering on deletion.
//
// That is a deliberate divergence from the no-op reconcilers elsewhere here,
// which exist only as watch sources. Those objects have no per-object lifecycle
Expand All @@ -110,7 +111,8 @@ type NetworkServiceReconciler struct {
// again after it found an advertisement its cache had missed.
const staleAdvertisementRequeue = time.Second

// Reconcile reconciles one NetworkService's finalizer and Accepted condition.
// Reconcile reconciles one NetworkService's finalizer, Accepted condition and
// summary conditions.
// Engine convergence and advertisement wiring for accepted rules happen in
// NetworkGatewayReconciler, which watches NetworkService and re-lists on every
// change, so this reconciler never touches the gateway engine.
Expand Down Expand Up @@ -146,6 +148,9 @@ func (r *NetworkServiceReconciler) Reconcile(ctx context.Context, req ctrl.Reque
if err := r.updateAcceptedCondition(ctx, rule); err != nil {
return ctrl.Result{}, fmt.Errorf("update Accepted condition for NetworkService %s: %w", req.NamespacedName, err)
}
if err := updateSummaryConditions(ctx, r.Client, r.APIReader, req.NamespacedName); err != nil {
return ctrl.Result{}, fmt.Errorf("update summary conditions for NetworkService %s: %w", req.NamespacedName, err)
}

return ctrl.Result{}, nil
}
Expand Down
Loading
Loading