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
4 changes: 2 additions & 2 deletions config/galactic-edge/controller-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ subjects:
name: galactic-controller
namespace: galactic-system
---
# Route publication: one BGPAdvertisement per accepted route, written only
# where the cell's BGP objects live.
# Publication: one BGPAdvertisement per accepted route and per serving
# listener attachment, written only where the cell's BGP objects live.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand Down
10 changes: 6 additions & 4 deletions docs/edge/provider-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ The advertisement names that node's router, the VRF's ID and export route target

`galactic-router` advertises an edge route's advertisement only while the forwarding gate it names is open on its node: the named host link is the edge link of the named address and holds an unexpired gate for exactly the prefix. It reads the gate from the pinned map whenever it builds its desired state, and polls it every 250 ms so a deadline passing withdraws the prefix with no API event. Without the pinned map it advertises none, and opens the map again at most every second until it can read it. An advertisement it leaves out is reported `Advertised` False with reason `GateClosed`. Publication never widens what the gate allows: a prefix whose gate closes is withdrawn locally even if core is cut off and still publishes it.

An attachment's own address is not published. Workloads of the gVPC on the attachment's node reach the address, and every prefix whose gate is open on the attachment's link, through local entries `galactic-edge` keeps in the uSID datapath (see [Shared, written by existing components](#shared-written-by-existing-components)). The entry for a prefix stays while its route is accepted on the node and not released, whether or not the gate is open, so a closed gate drops that traffic on the node instead of sending it to the gVPC's egress shards. Workloads on other nodes reach only published prefixes. A provider that must be reachable at its address from other nodes claims an `EdgeRoute` for the address's `/128`, which the conflict check allows for the holder's own address. That route is gated and published like any other, and adds no host route, since the link's own route already carries the address.
An attachment's own address is not published, except a serving listener attachment's (see [Public listener](#public-listener)). Workloads of the gVPC on the attachment's node reach the address, and every prefix whose gate is open on the attachment's link, through local entries `galactic-edge` keeps in the uSID datapath (see [Shared, written by existing components](#shared-written-by-existing-components)). The entry for a prefix stays while its route is accepted on the node and not released, whether or not the gate is open, so a closed gate drops that traffic on the node instead of sending it to the gVPC's egress shards. Workloads on other nodes reach only published prefixes. A provider that must be reachable at its address from other nodes claims an `EdgeRoute` for the address's `/128`, which the conflict check allows for the holder's own address. That route is gated and published like any other, and adds no host route, since the link's own route already carries the address.

Core's write access to `BGPAdvertisement` is a Role in `galactic-system`. Kubernetes RBAC cannot scope it by label, so the Role covers every advertisement there, though core reads and writes only those labeled `galactic.datumapis.com/edge-route`.
Core's write access to `BGPAdvertisement` is a Role in `galactic-system`. Kubernetes RBAC cannot scope it by label, so the Role covers every advertisement there, though core reads and writes only those labeled `galactic.datumapis.com/edge-route` or `galactic.datumapis.com/edge-listener`.

### Reaping

Expand All @@ -301,7 +301,7 @@ A drain stops new routes and attachments for its scope at once. Forwarding conti

### Public listener

Core (`internal/edge/listener`) keeps one ingress gVPC per approved provider that lists `PublicListener/v1`: the VPC `edge-ingress-<provider>` in `galactic-system`, labelled `galactic.datumapis.com/edge-ingress`. Its `/64` comes from `galactic-controller --edge-ingress-prefix`, and its fabric identifier, `status.vpc`, from the provider's `--edge-ingress-identity`. A provider without an identity gets no gVPC, and core records an `IngressIdentityMissing` Event on its `EdgeProvider`. Neither the `/64` nor the identifier moves once recorded: a changed identity is reported as `Ready` False with reason `IdentityMismatch` on the VPC and is not applied. Core deletes the gVPC once its provider may no longer hold a listener, no `EdgeService` references it and no `NetworkService` names its identifier. A provider the prefix has no free `/64` for is retried every minute. A VPC of that name with a controller, such as one NSO adopted for a `NetworkContext` of the same name, is not core's, and core neither trusts nor writes it.
Core (`internal/edge/listener`) keeps one ingress gVPC per approved provider that lists `PublicListener/v1`: the VPC `edge-ingress-<provider>` in `galactic-system`, labelled `galactic.datumapis.com/edge-ingress`. Its `/64` comes from `galactic-controller --edge-ingress-prefix`, and its fabric identifier, `status.vpc`, from the provider's `--edge-ingress-identity`. A provider without an identity gets no gVPC, and core records an `IngressIdentityMissing` Event on its `EdgeProvider`. Neither the `/64` nor the identifier moves once recorded: a changed identity is reported as `Ready` False with reason `IdentityMismatch` on the VPC and is not applied. Core deletes the gVPC once its provider may no longer hold a listener, no `EdgeService` references it, no `NetworkService` names its identifier and no listener `/128` is published in it. A provider the prefix has no free `/64` for is retried every minute. A VPC of that name with a controller, such as one NSO adopted for a `NetworkContext` of the same name, is not core's, and core neither trusts nor writes it.

Core accepts an `EdgeListener` only while all of these hold, and otherwise sets `Accepted` False with the reason of the first that fails:

Expand All @@ -314,7 +314,9 @@ Core accepts an `EdgeListener` only while all of these hold, and otherwise sets

A listener refused at its current generation holds neither its service nor its addresses against a newer one, but its `NetworkService`s claim their addresses against newer listeners until they are gone. A newer listener's `NetworkService`s never claim against an older one, so an older listener that becomes admissible takes its addresses back, and the newer one refuses itself and withdraws.

The listener's backends, in `status.backends`, are the attachments made against its `EdgeService`. One is serving while the listener is accepted and the attachment is `Allocated`, `Programmed` and `Ready`, with its node, gVPC, address and host link reported; is `Admitted`, or `Draining` before its `status.drainDeadline`; and its instance is its pod's, on its node, holding its lease, until the Lease's `spec.renewTime` plus its `spec.leaseDurationSeconds` (the cell's lease duration when unset) less the maximum skew. A backend on a node that a `NetworkGateway` in `galactic-system` targets is never serving, since a gateway cannot deliver to its own node. `Programmed` is True with `BackendsReady` while any backend serves, and otherwise False with `LocalBackendsExcluded` when an eligible backend is excluded that way, or `NoBackends`.
The listener's backends, in `status.backends`, are the attachments made against its `EdgeService`. One is serving while the listener is accepted and the attachment is `Allocated`, `Programmed` and `Ready`, with its node, gVPC, address and host link reported; is `Admitted`, or `Draining` before its `status.drainDeadline`; its instance is its pod's, on its node, holding its lease, until the Lease's `spec.renewTime` plus its `spec.leaseDurationSeconds` (the cell's lease duration when unset) less the maximum skew; and its `/128` can be published (see below). A backend on a node that a `NetworkGateway` in `galactic-system` targets is never serving, since a gateway cannot deliver to its own node. `Programmed` is True with `BackendsReady` while any backend serves, and otherwise False with `LocalBackendsExcluded` when an eligible backend is excluded that way, or `NoBackends`.

Core publishes the `/128` of each serving backend's address as a `BGPAdvertisement` in `galactic-system`, named `edge-listener-<attachment UID>`, so the gateways can resolve the backend's uSID. It has the shape of a route's: the router, VRF ID and first export route target of the gVPC's `BGPVRFInstance` on the backend's node, `End.DT46`, and the EVPN address family. It is labelled `galactic.datumapis.com/edge-listener` with the listener's UID, `galactic.datumapis.com/edge-listener-key` with a hash of the listener's namespace and name, and `galactic.datumapis.com/edge-listener-vpc` with the gVPC's identifier, instead of `galactic.datumapis.com/edge-route`, so `galactic-router` advertises it without a forwarding gate, and router GC, finding no netns annotation on it, never reclaims it. A backend whose `BGPVRFInstance` does not exist or names no router or export route target is not serving until it does, and neither is one whose address is not a plain IPv6 address. `Programmed` is not `BackendsReady` while no backend is published, and its message names why each such backend cannot be. A backend in another gVPC than the listener's ingress gVPC never serves. An object at a backend's advertisement name that lacks `galactic.datumapis.com/edge-listener` or the listener's `galactic.datumapis.com/edge-listener-key` is never updated, adopted or withdrawn: the backend does not serve, `Programmed` names it, and core records a `BGPAdvertisementNameTaken` Event. Core withdraws the advertisement, on a precondition of the version read, as soon as the backend stops serving, its attachment goes or its listener is gone.

### Restart and replacement

Expand Down
45 changes: 45 additions & 0 deletions internal/crdnames/crdnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,51 @@ func EdgeAdvertisementName(routeUID string) string {
return "edge-" + routeUID
}

// Labels and annotations of the BGPAdvertisement galactic-controller
// publishes for the /128 of one serving Galactic Edge listener attachment
// (EdgeListenerAdvertisementName). It carries no LabelEdgeRoute, so
// galactic-router advertises it as it does any other advertisement, with no
// forwarding gate, and router GC, finding no netns annotation on it, never
// reclaims it: galactic-controller withdraws it.
const (
// LabelEdgeListener is the listener's metadata.uid. Its presence marks
// the advertisement as a listener attachment's.
LabelEdgeListener = "galactic.datumapis.com/edge-listener"
// LabelEdgeListenerAttachment is the attachment's metadata.uid.
LabelEdgeListenerAttachment = "galactic.datumapis.com/edge-listener-attachment"
// LabelEdgeListenerKey is EdgeListenerKey of the listener's namespace
// and name, which selects every advertisement of a listener by name,
// whichever object of that name it was published for.
LabelEdgeListenerKey = "galactic.datumapis.com/edge-listener-key"
// LabelEdgeListenerVPC is the base62 identifier of the gVPC the
// advertisement is published in.
LabelEdgeListenerVPC = "galactic.datumapis.com/edge-listener-vpc"
// AnnotationEdgeListener is the listener's namespace and name.
AnnotationEdgeListener = "galactic.datumapis.com/edge-listener"
// AnnotationEdgeListenerAttachment is the attachment's namespace and
// name.
AnnotationEdgeListenerAttachment = "galactic.datumapis.com/edge-listener-attachment"
)

// edgeListenerKeyLen is how many hex characters of a SHA-256 EdgeListenerKey
// keeps.
const edgeListenerKeyLen = 32

// EdgeListenerKey returns the value of LabelEdgeListenerKey for the listener
// namespace/name: a hash, since a listener's name may be longer than a label
// value. A reader checks AnnotationEdgeListener as well.
func EdgeListenerKey(namespace, name string) string {
sum := sha256.Sum256([]byte(namespace + "/" + name))
return hex.EncodeToString(sum[:])[:edgeListenerKeyLen]
}

// EdgeListenerAdvertisementName returns the name of the BGPAdvertisement of
// the /128 of the listener attachment with metadata.uid attachmentUID. An
// attachment serves at most one listener, so it has at most one.
func EdgeListenerAdvertisementName(attachmentUID string) string {
return "edge-listener-" + attachmentUID
}

// containerIDLen is how many characters of a container ID appear in an
// annotation key. Kubernetes limits the name part of an annotation key to 63
// bytes, and the longest prefix here is 22 bytes, leaving 41 for the suffix.
Expand Down
22 changes: 22 additions & 0 deletions internal/crdnames/crdnames_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,28 @@ func TestVPCSegmentSharedByBothNames(t *testing.T) {
}
}

// TestEdgeListenerAdvertisementName: a listener attachment's advertisement
// is a valid object name, never a route's, and is not labelled as a route's,
// which galactic-router would advertise only behind a forwarding gate.
func TestEdgeListenerAdvertisementName(t *testing.T) {
const uid = "0f3c9a1e-6b2d-4e8f-9a7c-1d2e3f4a5b6c"
got := EdgeListenerAdvertisementName(uid)
assertValidObjectName(t, "EdgeListenerAdvertisementName", got)
if got == EdgeAdvertisementName(uid) {
t.Errorf("a listener attachment's advertisement shares the name %q of a route's", got)
}
if LabelEdgeListener == LabelEdgeRoute || LabelEdgeListenerAttachment == LabelEdgeRoute {
t.Error("a listener attachment's advertisement carries the edge route label")
}
key := EdgeListenerKey("galactic-system", strings.Repeat("a", 253))
if errs := validation.IsValidLabelValue(key); len(errs) > 0 {
t.Errorf("EdgeListenerKey = %q is not a label value: %v", key, errs)
}
if key == EdgeListenerKey("galactic-system", strings.Repeat("a", 252)) {
t.Error("EdgeListenerKey collides for distinct listeners")
}
}

func assertValidObjectName(t *testing.T, who, name string) {
t.Helper()
if errs := validation.IsDNS1123Subdomain(name); len(errs) > 0 {
Expand Down
34 changes: 34 additions & 0 deletions internal/edge/listener/admit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

bgpv1alpha1 "go.datum.net/galactic/api/network/v1alpha1"
galacticv1alpha1 "go.datum.net/galactic/api/v1alpha1"
"go.datum.net/galactic/internal/crdnames"
"go.datum.net/galactic/internal/edge/admission"
)

Expand Down Expand Up @@ -279,6 +280,8 @@ func TestProgrammed(t *testing.T) {
b := func(eligible, local, serving bool) backend {
return backend{att: eligibleAttachment(), eligible: eligible, local: local, serving: serving}
}
unpublishable := b(true, false, false)
unpublishable.unpublishable = `its address "192.0.2.50" is not a plain IPv6 address`
tests := []struct {
name string
accepted bool
Expand All @@ -295,6 +298,12 @@ func TestProgrammed(t *testing.T) {
galacticv1alpha1.EdgeListenerReasonNoBackends},
{"NotAccepted", false, []backend{b(true, true, false)}, metav1.ConditionFalse,
galacticv1alpha1.EdgeListenerReasonNoBackends},
{"Unpublishable", true, []backend{unpublishable}, metav1.ConditionFalse,
galacticv1alpha1.EdgeListenerReasonNoBackends},
}
if c := programmed(&l, true, []backend{unpublishable}); !strings.Contains(c.Message, "plain IPv6") ||
strings.Contains(c.Message, "BGPVRFInstance") {
t.Errorf("Programmed message for an unpublishable address = %q, want its cause and no VRF", c.Message)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -305,3 +314,28 @@ func TestProgrammed(t *testing.T) {
})
}
}

// TestListenersAdvertisement: only an advertisement carrying the listener
// label and the listener's key is the listener's to update.
func TestListenersAdvertisement(t *testing.T) {
l := listenerAt("public", 1, vip6)
key := crdnames.EdgeListenerKey(gatewayNS, "public")
for _, tt := range []struct {
name string
labels map[string]string
want bool
}{
{"Unlabelled", nil, false},
{"KeyOnly", map[string]string{crdnames.LabelEdgeListenerKey: key}, false},
{"OtherListener", map[string]string{crdnames.LabelEdgeListener: "uid",
crdnames.LabelEdgeListenerKey: crdnames.EdgeListenerKey(gatewayNS, "other")}, false},
{"Ours", map[string]string{crdnames.LabelEdgeListener: "uid", crdnames.LabelEdgeListenerKey: key}, true},
} {
t.Run(tt.name, func(t *testing.T) {
adv := &bgpv1alpha1.BGPAdvertisement{ObjectMeta: metav1.ObjectMeta{Labels: tt.labels}}
if got := listenersAdvertisement(adv, &l); got != tt.want {
t.Errorf("listenersAdvertisement = %v, want %v", got, tt.want)
}
})
}
}
38 changes: 36 additions & 2 deletions internal/edge/listener/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,24 @@ type backend struct {
// local is whether the attachment is on a node that advertises the
// listener's addresses.
local bool
// adv is the advertisement of its /128, nil while its gVPC's VRF on its
// node names no router or export route target.
adv *bgpv1alpha1.BGPAdvertisement
// serving is whether it receives new flows: the listener is accepted,
// and it is eligible and not local.
// it is eligible and not local, and its /128 can be published.
serving bool
// unpublishable is why its /128 cannot be published, when it would
// serve but for that.
unpublishable string
// advertisementTaken is whether that is because another object holds
// its advertisement's name.
advertisementTaken bool
}

// unpublished reports whether b would serve but for its /128, which cannot be
// published yet.
func (b *backend) unpublished(accepted bool) bool {
return accepted && b.eligible && !b.local && !b.serving
}

// status is the backend as the listener's status reports it.
Expand Down Expand Up @@ -106,7 +121,26 @@ func (r *Reconciler) backends(ctx context.Context, l *galacticv1alpha1.EdgeListe
next = deadline
}
b.local = gateways[att.Status.NodeName]
b.serving = b.eligible && !b.local && vpc != "" && att.Status.VPC == vpc
switch {
case !b.eligible || b.local || vpc == "":
case att.Status.VPC != vpc:
b.unpublishable = fmt.Sprintf("it is in gVPC %s, not the listener's %s", att.Status.VPC, vpc)
default:
adv, why, err := r.desiredAdvertisement(ctx, l, att)
if err != nil {
return nil, time.Time{}, err
}
if adv != nil {
taken, err := r.advertisementTaken(ctx, l, adv.Name)
if err != nil {
return nil, time.Time{}, err
}
if taken != "" {
adv, why, b.advertisementTaken = nil, taken, true
}
}
b.adv, b.serving, b.unpublishable = adv, adv != nil, why
}
out = append(out, b)
}
return out, next, nil
Expand Down
5 changes: 3 additions & 2 deletions internal/edge/listener/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Package listener is core's half of the Galactic Edge public listener, run
// by galactic-controller --role=cell --edge. It keeps one ingress gVPC per
// provider that may hold a listener, in the gateway namespace, with a fabric
// identity and a /64 the operator configures. It admits each EdgeListener
// and reports which of its listener attachments serve.
// identity and a /64 the operator configures. It admits each EdgeListener,
// reports which of its listener attachments serve, and publishes the /128
// of each serving attachment.
package listener
Loading
Loading