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
12 changes: 11 additions & 1 deletion cmd/galactic-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type options struct {
edgeIngressIDs []string
edgeIngressPrefix string
edgeVIPPrefixes []string
edgeWithdrawDelay time.Duration
}

func main() {
Expand Down Expand Up @@ -132,6 +133,10 @@ func newRootCommand() *cobra.Command {
f.StringVar(&o.edgeIngressPrefix, "edge-ingress-prefix", "",
"Cell role with --edge: IPv6 unique local prefix, /64 or shorter, from which each ingress gVPC takes a /64; "+
"required with --edge-ingress-identity")
f.DurationVar(&o.edgeWithdrawDelay, "edge-listener-withdraw-delay", edgelistener.DefaultWithdrawDelay,
"Cell role with --edge: how long a refused or deleted EdgeListener's backend /128s outlive its "+
"NetworkServices, covering the gateway's drain delay plus BGP convergence; it must exceed the gateway "+
"drain delay")
f.StringSliceVar(&o.edgeVIPPrefixes, "edge-listener-vip-prefixes", nil,
"Cell role with --edge: comma-separated IPv6 and IPv4 prefixes of the cell's gateway VIPs; an EdgeListener "+
"address outside them is refused with AddressOutsidePool, as is every address when none are given")
Expand Down Expand Up @@ -238,13 +243,18 @@ func setupListeners(mgr ctrl.Manager, o *options) error {
if len(identities) > 0 && !prefix.IsValid() {
return errors.New("--edge-ingress-prefix is required with --edge-ingress-identity")
}
if o.edgeWithdrawDelay <= edgelistener.GatewayDrainDelay {
return fmt.Errorf("--edge-listener-withdraw-delay %s must exceed the gateway drain delay %s",
o.edgeWithdrawDelay, edgelistener.GatewayDrainDelay)
}
vips, err := edgelistener.ParseVIPPrefixes(o.edgeVIPPrefixes)
if err != nil {
return fmt.Errorf("--edge-listener-vip-prefixes: %w", err)
}
if err := edgelistener.Setup(mgr, edgelistener.Config{
Namespace: galactic.SystemNamespace, Identities: identities, IngressPrefix: prefix, VIPPrefixes: vips,
MaxSkew: o.edgeMaxSkew, LeaseDuration: timing.Params.Duration, Events: mgr.GetEventRecorder("galactic-controller"),
MaxSkew: o.edgeMaxSkew, LeaseDuration: timing.Params.Duration,
WithdrawDelay: o.edgeWithdrawDelay, Events: mgr.GetEventRecorder("galactic-controller"),
}); err != nil {
return fmt.Errorf("set up edge listeners: %w", err)
}
Expand Down
27 changes: 23 additions & 4 deletions config/galactic-edge/controller-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,11 @@ subjects:
# Public listeners, all in the gateway namespace: one ingress gVPC per
# provider holding PublicListener, created with its fabric identifier in
# status and deleted once its provider may no longer hold a listener and no
# EdgeService references it, and each EdgeListener's status. Kubernetes RBAC
# cannot scope a create by name, so the Role covers every VPC in the
# namespace, though core writes only those labelled
# galactic.datumapis.com/edge-ingress.
# EdgeService references it; each EdgeListener's status and finalizer; and
# the listener's NetworkServices. Kubernetes RBAC cannot scope a create by
# name, so the Role covers every VPC and NetworkService in the namespace,
# though core writes only the VPCs labelled galactic.datumapis.com/edge-ingress
# and the NetworkServices an EdgeListener controls.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand All @@ -178,6 +179,24 @@ rules:
- apiGroups: [galactic.datumapis.com]
resources: [edgelisteners/status]
verbs: [patch]
# The finalizer that holds a deleted listener until its NetworkServices
# and /128 advertisements are gone, and the annotation recording when its
# services went, both written by merge patch.
- apiGroups: [galactic.datumapis.com]
resources: [edgelisteners]
verbs: [patch]
# Each NetworkService's owner reference to its listener blocks the
# listener's deletion, which OwnerReferencesPermissionEnforcement allows
# only with update on the listener's finalizers.
- apiGroups: [galactic.datumapis.com]
resources: [edgelisteners/finalizers]
verbs: [update]
# One NetworkService per port of each accepted listener. The
# galactic-edge-controller-listener-services policy (policies.yaml) limits
# these writes to listener services.
- apiGroups: [galactic.datumapis.com]
resources: [networkservices]
verbs: [create, update, delete]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
Expand Down
39 changes: 39 additions & 0 deletions config/galactic-edge/policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,42 @@ metadata:
spec:
policyName: galactic-edge-listener-namespace
validationActions: [Deny]
---
# galactic-controller writes NetworkServices in the gateway namespace only
# for EdgeListeners: Kubernetes RBAC cannot scope its Role there by label,
# so this policy holds it to services that name a listener and carry the
# listener label, before and after the write.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: galactic-edge-controller-listener-services
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: [galactic.datumapis.com]
apiVersions: ["*"]
operations: [CREATE, UPDATE, DELETE]
resources: [networkservices]
matchConditions:
- name: controller
expression: request.userInfo.username == 'system:serviceaccount:galactic-system:galactic-controller'
validations:
- expression: >-
request.operation == 'DELETE' ||
(has(object.spec.edgeListenerRef) && has(object.metadata.labels) &&
'galactic.datumapis.com/edge-listener' in object.metadata.labels)
message: galactic-controller writes only NetworkServices that name an EdgeListener and carry its label
- expression: >-
request.operation == 'CREATE' ||
(has(oldObject.spec.edgeListenerRef) && has(oldObject.metadata.labels) &&
'galactic.datumapis.com/edge-listener' in oldObject.metadata.labels)
message: galactic-controller changes or deletes only NetworkServices that name an EdgeListener and carry its label
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: galactic-edge-controller-listener-services
spec:
policyName: galactic-edge-controller-listener-services
validationActions: [Deny]
34 changes: 24 additions & 10 deletions docs/controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ Logging takes `--log-level` (`LOG_LEVEL`) and the standard `--zap-*` flags; see

## Cell flags

| Flag | Default | Meaning |
| ------------------------------ | ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--webhook-port` | `9443` | Admission webhook listener |
| `--webhook-cert-dir` | `/tmp/k8s-webhook-server/serving-certs` | Directory containing `tls.crt` and `tls.key` |
| `--controller-username` | `system:serviceaccount:<namespace>:galactic-controller` | Identity allowed to write the reserved default policy |
| `--edge` | `false` | Enable Edge attachment, route and public listener controllers after their CRDs and admission prerequisites are installed |
| `--edge-max-skew` | `2s` | Maximum assumed clock error; must match `galactic-edge --max-skew` |
| `--edge-ingress-identity` | none | With `--edge`: `<provider>=<identity>`, the decimal fabric VPC identity of a provider's ingress gVPC. Repeat it or separate entries with commas. A provider that holds `PublicListener` without one gets no ingress gVPC, and an Event on the `EdgeProvider` says so. An identity another VPC already holds is not recorded: the ingress gVPC reports `Ready` False with reason `IdentityInUse` |
| `--edge-ingress-prefix` | none | With `--edge`: IPv6 unique local prefix, `/64` or shorter, from which each ingress gVPC takes a `/64`. Required with `--edge-ingress-identity` |
| `--edge-listener-vip-prefixes` | none | With `--edge`: comma-separated IPv6 and IPv4 prefixes of the cell's gateway VIPs. An `EdgeListener` address outside them is refused with `AddressOutsidePool`, as is every address when none are given |
| Flag | Default | Meaning |
| -------------------------------- | ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--webhook-port` | `9443` | Admission webhook listener |
| `--webhook-cert-dir` | `/tmp/k8s-webhook-server/serving-certs` | Directory containing `tls.crt` and `tls.key` |
| `--controller-username` | `system:serviceaccount:<namespace>:galactic-controller` | Identity allowed to write the reserved default policy |
| `--edge` | `false` | Enable Edge attachment, route and public listener controllers after their CRDs and admission prerequisites are installed |
| `--edge-max-skew` | `2s` | Maximum assumed clock error; must match `galactic-edge --max-skew` |
| `--edge-ingress-identity` | none | With `--edge`: `<provider>=<identity>`, the decimal fabric VPC identity of a provider's ingress gVPC. Repeat it or separate entries with commas. A provider that holds `PublicListener` without one gets no ingress gVPC, and an Event on the `EdgeProvider` says so. An identity another VPC already holds is not recorded: the ingress gVPC reports `Ready` False with reason `IdentityInUse` |
| `--edge-ingress-prefix` | none | With `--edge`: IPv6 unique local prefix, `/64` or shorter, from which each ingress gVPC takes a `/64`. Required with `--edge-ingress-identity` |
| `--edge-listener-vip-prefixes` | none | With `--edge`: comma-separated IPv6 and IPv4 prefixes of the cell's gateway VIPs. An `EdgeListener` address outside them is refused with `AddressOutsidePool`, as is every address when none are given |
| `--edge-listener-withdraw-delay` | `30s` | With `--edge`: how long a refused or deleted `EdgeListener`'s backend `/128`s outlive its `NetworkService`s. It covers the gateway's drain delay (5 s) plus BGP convergence and must exceed the drain delay; the controller refuses to start otherwise |

### Installing the cell role

Expand All @@ -54,6 +55,19 @@ Admission fails closed. Deploy the webhook with its serving Deployment, and keep

For `--edge`, first install the Edge prerequisites in `config/galactic-edge/` and its node agent on eligible nodes. Apply the bundle's CRDs (`config/crd/`) and `config/galactic-edge/`, with its RBAC, before rolling out a controller image that serves public listeners: without the `EdgeListener` CRD the controller logs that it does not start the listener controllers and runs the rest, and without the RBAC its caches cannot sync. A deleting attachment is held until the node reports `Released` or the node is removed. See [Edge troubleshooting](../edge/troubleshooting.md) and the [provider contract](../edge/provider-contract.md) for ownership and timing requirements.

### Rolling back the cell role

Rolling `galactic-controller` back below the version that adds the listener controllers leaves every `EdgeListener` with core's `galactic.datumapis.com/edge-listener` finalizer, which nothing then removes, so a listener deleted after the rollback stays deleting. Delete the listener's `NetworkService`s, wait until they are gone and then the withdraw delay (30 s by default) more, delete its backend `/128` advertisements, and only then clear the finalizer by hand, for example:

```sh
kubectl -n galactic-system delete networkservices -l galactic.datumapis.com/edge-listener=<listener-uid>
kubectl -n galactic-system delete bgpadvertisements -l galactic.datumapis.com/edge-listener=<listener-uid>
kubectl -n galactic-system patch edgelistener <listener-name> --type=json \
-p '[{"op":"remove","path":"/metadata/finalizers"}]'
```

The listener's ingress gVPC (`edge-ingress-<provider>`) and the `galactic-edge-controller-listener-services` policy are left in place; remove them with the bundle that added them.

### Pod-interface injection

The pod webhook admits a pod labelled `networking.datumapis.com/inject-interfaces=true` only when its controlling `Instance` has a bound `NetworkInterface` for every declared interface. Each one needs a NetworkAttachmentDefinition of the same name that belongs to that instance. The definition, its `VPCAttachment` and its `NetworkInterface` are named after the interface slot, so a replacement instance of the same name can find its predecessor's objects until garbage collection removes them. A pod wired from those objects attaches under the previous attachment identifier and is never reported `Programmed`.
Expand Down
Loading
Loading