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: 12 additions & 0 deletions changelog/unreleased/1001-port-pools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Port pools for servers behind one public address

`operator.portPools` defines ranges of ports on a shared endpoint, such as a
relay or an edge that forwards ports, and the templates whose servers draw
from each. Every such server gets a contiguous block of Service ports of its
own, kept for its life, even when the pool later shrinks, and shown by the new
`PortAllocation` condition. Servers whose games send no hostname no longer
need their ports set by hand behind one address. A full pool never takes
ports from a server that has them: new servers wait, and template updates
that need more ports wait on the current version. See
[Port pools](../../docs/networking.md#port-pools).
[PR #1001](https://github.com/GameplanePanel/Gameplane/pull/1001)
7 changes: 7 additions & 0 deletions charts/gameplane/templates/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@ spec:
{{- end }}
- --address-manager={{ .Values.operator.addressManager }}
- --metallb-namespace={{ .Values.operator.metalLBNamespace | default "metallb-system" }}
{{- range .Values.operator.portPools }}
- --port-pool={{ .name }}={{ .ports }}
{{- $pool := .name }}
{{- range .templates }}
- --port-pool-template={{ . }}={{ $pool }}
{{- end }}
{{- end }}
- --zap-log-level={{ .Values.operator.logLevel }}
{{- if .Values.operator.localModules.enabled }}
- --module-local-root={{ .Values.operator.localModules.mountPath }}
Expand Down
15 changes: 15 additions & 0 deletions charts/gameplane/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ operator:
# MetalLB event. "metallb-system" is MetalLB's own install convention, not
# a contract, hence configurable.
metalLBNamespace: metallb-system
# Port pools: ranges of Service ports on one shared public endpoint, such
# as a relay or an edge that forwards ports to the cluster, for games whose
# clients send no hostname and so need ports of their own behind one
# address. Every server of a listed template gets a contiguous block of the
# pool, one port per advertised port, recorded in its
# gameplane.local/pool-ports annotation and kept for the server's life. A
# (protocol, port) pair goes to one server, whatever its template. Servers'
# explicit servicePort overrides are reserved too, and refused when another
# server holds the port. Shrinking a range leaves existing servers their
# ports; keep forwarding them. A template draws from at most one pool. See docs/networking.md#port-pools. Example:
# portPools:
# - name: edge
# ports: "2456-2499"
# templates: [valheim, factorio]
portPools: []
# Tunnel provider images: relay binaries wrapped in OCI images for reaching
# players through relay services when the cluster has no public IP or port-
# forwarding. Each wraps a third-party relay binary (frpc, tailscaled, playit)
Expand Down
8 changes: 8 additions & 0 deletions deploy/kind/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ EOF
# CI or dev installs reach the project provider (spec 022 R17).
# The legacy fixtures exercise Hostport, in-pod capture and root init.
# The restricted-workloads bucket upgrades this same installation to PSA.
# The port pool serves TestGameServer_PortPool* (port_pool_e2e_test.go).
helm upgrade --install gameplane "${CHART_DIR}" \
--namespace gameplane-system --create-namespace \
--set "image.registry=gameplane-test" \
Expand All @@ -435,6 +436,13 @@ EOF
--set "api.oidc.roleMappings.admin[0]=gameplane-e2e-oidc-admins" \
--set "operator.leaderElect=false" \
--set "operator.addressManager=metallb" \
--set "operator.portPools[0].name=e2e-pool" \
--set "operator.portPools[0].ports=31000-31005" \
--set "operator.portPools[0].templates[0]=e2e-portpool-a" \
--set "operator.portPools[0].templates[1]=e2e-portpool-b" \
--set "operator.portPools[1].name=e2e-pool-serving" \
--set "operator.portPools[1].ports=31010-31012" \
--set "operator.portPools[1].templates[0]=e2e-portpool-c" \
--set "operator.gameDataStorage.storageClassName=gameplane-e2e-install-default" \
--set "defaultModuleSource.enabled=false" \
--set "api.telemetry.receiver.enabled=true" \
Expand Down
6 changes: 6 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ Top-level knobs (see `values.yaml` for the full list):

Any other value fails the operator at startup. The operator never writes the
deprecated `service.spec.loadBalancerIP`.
- `operator.portPools` — port pools: ranges of ports on one shared public
endpoint, each with the templates whose servers draw from it
(`[{name: edge, ports: "2456-2499", templates: [valheim, factorio]}]`).
Each server gets a contiguous block, kept for its life. Use it when servers
are reached through a relay or an edge that forwards ports, as games whose
clients send no hostname must be. See [Networking](networking.md#port-pools).
- `capture.enabled` — the optional network packet capture sidecar [optional] for GameServers
(default `false`). When enabled cluster-wide, admins can opt individual GameServers
into live AF_PACKET capture with BPF filtering and download PCAPNG files. Captures
Expand Down
58 changes: 58 additions & 0 deletions docs/networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,64 @@ configured address manager; a Service of another class is outside that
manager's control, so leave them unset with a class of another
implementation.

## Port Pools

Some installs reach every game server through one public address, a relay
or an edge that forwards a range of ports to the cluster's load balancer.
Games whose clients send the hostname they connect to (Minecraft Java) can
share a port behind a router that picks the server by name, but most games
send no hostname, so behind one address each server needs ports of its own.
A port pool hands them out.

A pool is a range of ports on one shared endpoint. Name it for the endpoint,
and list the templates whose servers draw from it, with the Helm value
`operator.portPools`:

```yaml
operator:
portPools:
- name: edge
ports: "2456-2499"
templates: [valheim, factorio]
```

Every server of those templates then gets a contiguous block of the pool, one
port per advertised port, in template order: the first Valheim server
2456-2457, a Factorio server next 2458, the next Valheim server 2459-2460.
The pool decides who shares: a port goes to one server whatever its
template, and ports are reserved per protocol, so TCP 2456 and UDP 2456 are
two ports. A template draws from at most one pool.

The operator records each server's ports in its `gameplane.local/pool-ports`
annotation and keeps them for the server's life, so players' saved addresses
keep working. The Service publishes those ports and forwards them to the
game's own, and `status.endpoints` and the dashboard show them. Relays (frp,
Tailscale, Playit) forward to those ports too. The `PortAllocation`
condition lists them.

A server's explicit `spec.networking.portOverrides[].servicePort` is
reserved too, so the pool never hands it to another server. An override that
names a port another server already holds is refused: the server reports
`PortAllocation` `ServicePortConflict` and keeps the ports it had.

When no block is free, a new server reports `PoolExhausted` and gets no
Service or address until a block frees up, for example when a server is deleted. A
server that already has ports keeps them, and keeps working, sleeping and
waking, while a change it needs waits (`ChangePending`). A template update
that needs other ports reserves them before the server is restarted for it;
when the pool can't, the server stays on its current version and reports
`RolloutPending`. Servers that wait check again every 30 seconds, and their
games keep running.

Forward the whole range at the relay or edge, to the cluster's load
balancer. When you shrink a pool, existing servers keep their ports, even
ones outside the new range, and report `AllocatedOutsideRange` with those
ports. Keep forwarding them until you move those servers. New servers, and
servers that need new ports, for example for a template update, are given
ports from the smaller range. Removing a template from its pool returns its servers
to the template's ports. The full rules, including template revisions and
recovery, are in [spec 036](../specs/036-port-pools/spec.md).

## Related

- [`install.md`](install.md) — Helm chart values for `operator.addressManager` and cluster prerequisites.
Expand Down
32 changes: 32 additions & 0 deletions i18n/locales/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,38 @@
"defaultMessage": "Module translations could not be stored.",
"description": "LocalesValid condition on a GameTemplate when the translations ConfigMap could not be written. The message holds the English error."
},
"condition.portallocation.allocated": {
"defaultMessage": "Ports {ports} assigned from port pool ''{pool}''.",
"description": "PortAllocation condition once a server has Service ports from its port pool. ports lists them as port/protocol."
},
"condition.portallocation.allocatedoutsiderange": {
"defaultMessage": "Ports {ports} assigned from port pool ''{pool}''. Ports {outside} are outside the pool's range and stay in use until the server is moved; keep forwarding them.",
"description": "PortAllocation condition when the pool shrank and the server keeps ports outside the new range. outside lists them as port/protocol."
},
"condition.portallocation.changepending": {
"defaultMessage": "Port pool ''{pool}'' has no free block of {count} ports for the requested change, so the server keeps ports {ports} until one frees up.",
"description": "PortAllocation condition when a change to the server's ports waits for pool capacity. count is how many pooled ports the change needs."
},
"condition.portallocation.poolexhausted": {
"defaultMessage": "Port pool ''{pool}'' has no free block of {count} ports for this server, so it has no Service until a block frees up.",
"description": "PortAllocation condition when the server's port pool is full. count is how many ports the server needs."
},
"condition.portallocation.rolloutpending": {
"defaultMessage": "The template update waits for {count} free ports in port pool ''{pool}''; the server keeps its current revision on ports {ports}.",
"description": "PortAllocation condition when a template revision needs other ports and the pool can't reserve them yet."
},
"condition.portallocation.rolloutportconflict": {
"defaultMessage": "The template update waits for Service port {port}, held by {holder} in port pool ''{pool}''; the server keeps its current revision on ports {ports}.",
"description": "PortAllocation condition when a template revision's servicePort override names a port another server holds. holder is that server as namespace/name."
},
"condition.portallocation.serviceportconflict": {
"defaultMessage": "Service port {port} is held by {holder} in port pool ''{pool}'', so the server keeps ports {ports} until it is free.",
"description": "PortAllocation condition when a servicePort override names a port another server holds. holder is that server as namespace/name; ports are the ones the server keeps."
},
"condition.portallocation.serviceportconflictunpublished": {
"defaultMessage": "Service port {port} is held by {holder} in port pool ''{pool}'', so the server has no Service until it is free.",
"description": "PortAllocation condition when a servicePort override names a port another server holds and the server has no ports yet. holder is that server as namespace/name."
},
"condition.progressing.containercreating": {
"defaultMessage": "Creating the container.",
"description": "Progressing detail while the kubelet creates the container."
Expand Down
7 changes: 7 additions & 0 deletions operator/api/v1alpha1/gameserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ const (
// volume (e.g. a permission error on a subdirectory it doesn't own).
// Absent once a wipe has succeeded and been acked.
GameServerConditionDataWipe = "DataWipe"

// GameServerConditionPortAllocation reports the Service ports a server
// holds in its template's port pool (operator --port-pool): True with
// Reason "Allocated", or False with Reason "PoolExhausted" when the pool
// has no free block, in which case the server has no Service. Absent
// when the template draws from no pool.
GameServerConditionPortAllocation = "PortAllocation"
)

// GameServerSpec is the desired state of a single game server instance.
Expand Down
14 changes: 14 additions & 0 deletions operator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ func main() {
gameIngressFromCIDR cidrListFlag
probeIngressPolicy bool
probeIngressFromCIDR cidrListFlag
portPoolFlags cidrListFlag
portPoolTemplateFlags cidrListFlag
gameDataStorageClass string
captureEnabled bool
restrictedWorkloads bool
Expand Down Expand Up @@ -304,6 +306,12 @@ func main() {
flag.BoolVar(&probeIngressPolicy, "probe-ingress-policy", false,
"Reconcile a per-GameServer NetworkPolicy admitting kubelet probes to the game container's "+
"probe ports only. When false, the operator ensures the policy is absent.")
flag.Var(&portPoolFlags, "port-pool",
"A port pool, <pool>=<first>-<last>: a range of Service ports on one shared endpoint, such as a "+
"relay or port-forwarding edge, that its servers share without collisions. Repeatable.")
flag.Var(&portPoolTemplateFlags, "port-pool-template",
"<template>=<pool>: the template's servers get Service ports from the pool, a contiguous block "+
"each. Repeatable; a template draws from at most one pool.")
flag.Var(&probeIngressFromCIDR, "probe-ingress-from-cidr",
"Kubelet source CIDR admitted by the probe NetworkPolicy. Repeatable. Defaults to "+
"10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 and 169.254.0.0/16 when not supplied.")
Expand Down Expand Up @@ -441,6 +449,11 @@ func main() {
setupLog.Error(err, "invalid --address-manager value")
os.Exit(1)
}
portPools, err := controller.ParsePortPools(portPoolFlags, portPoolTemplateFlags)
if err != nil {
setupLog.Error(err, "invalid --port-pool value")
os.Exit(1)
}

// Games are meant to be publicly reachable, so an unset
// --game-ingress-from-cidr defaults to wide-open rather than an empty
Expand Down Expand Up @@ -543,6 +556,7 @@ func main() {
Clientset: kubernetes.NewForConfigOrDie(mgr.GetConfig()),
},
AddressManager: addressManager,
PortPools: portPools,
MetalLBNamespace: metalLBNamespace,
GameIngressPolicyEnabled: gameIngressPolicy,
GameIngressFromCIDRs: gameIngressFromCIDR,
Expand Down
9 changes: 9 additions & 0 deletions operator/hack/condition-ids/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ var rows = []row{
{types: []string{"Healthy"}, reason: "Failed", english: "The server failed.", description: "Healthy condition when the server has failed."},
{types: []string{"Healthy"}, reason: "Unknown", english: "The state of the server is not known yet.", description: "Healthy condition before the operator has observed the server."},

// GameServer: PortAllocation (port pools, spec 036)
{types: []string{"PortAllocation"}, reason: "Allocated", english: "Ports {ports} assigned from port pool ''{pool}''.", description: "PortAllocation condition once a server has Service ports from its port pool. ports lists them as port/protocol."},
{types: []string{"PortAllocation"}, reason: "PoolExhausted", english: "Port pool ''{pool}'' has no free block of {count} ports for this server, so it has no Service until a block frees up.", description: "PortAllocation condition when the server's port pool is full. count is how many ports the server needs."},
{types: []string{"PortAllocation"}, reason: "AllocatedOutsideRange", english: "Ports {ports} assigned from port pool ''{pool}''. Ports {outside} are outside the pool's range and stay in use until the server is moved; keep forwarding them.", description: "PortAllocation condition when the pool shrank and the server keeps ports outside the new range. outside lists them as port/protocol."},
{types: []string{"PortAllocation"}, reason: "ServicePortConflict", english: "Service port {port} is held by {holder} in port pool ''{pool}'', so the server keeps ports {ports} until it is free.", description: "PortAllocation condition when a servicePort override names a port another server holds. holder is that server as namespace/name; ports are the ones the server keeps."},
{types: []string{"PortAllocation"}, reason: "ServicePortConflictUnpublished", english: "Service port {port} is held by {holder} in port pool ''{pool}'', so the server has no Service until it is free.", description: "PortAllocation condition when a servicePort override names a port another server holds and the server has no ports yet. holder is that server as namespace/name."},
{types: []string{"PortAllocation"}, reason: "ChangePending", english: "Port pool ''{pool}'' has no free block of {count} ports for the requested change, so the server keeps ports {ports} until one frees up.", description: "PortAllocation condition when a change to the server's ports waits for pool capacity. count is how many pooled ports the change needs."},
{types: []string{"PortAllocation"}, reason: "RolloutPending", english: "The template update waits for {count} free ports in port pool ''{pool}''; the server keeps its current revision on ports {ports}.", description: "PortAllocation condition when a template revision needs other ports and the pool can't reserve them yet."},
{types: []string{"PortAllocation"}, reason: "RolloutPortConflict", english: "The template update waits for Service port {port}, held by {holder} in port pool ''{pool}''; the server keeps its current revision on ports {ports}.", description: "PortAllocation condition when a template revision's servicePort override names a port another server holds. holder is that server as namespace/name."},
// GameServer: AddressAssignment ($REQ is the request phrase, see reqExpr)
{types: []string{"AddressAssignment"}, reason: "IgnoredForExposureMode", english: "Requested $REQ is ignored: it applies only to the LoadBalancer expose mode, and this server is exposed as ''{expose}''.", description: "AddressAssignment condition when an address or pool is requested for a server that is not exposed as a LoadBalancer. expose is the current expose mode."},
{types: []string{"AddressAssignment"}, reason: "InvalidAddress", english: "The requested address ''{address}'' is not a valid IP address.", description: "AddressAssignment condition when the requested address does not parse."},
Expand Down
20 changes: 20 additions & 0 deletions operator/internal/controller/gameserver_condition_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type conditionArgsInput struct {
tunnelPlan tunnelPlan
playitErr string // errMsg from validatePlayitEndpoints ("" when none)
idleSchedErr error
ports portAllocation
}

// deriveConditionArgs walks gs.Status.Conditions and returns the new map (nil when empty).
Expand Down Expand Up @@ -83,6 +84,25 @@ func conditionArgsFor(gs *gameplanev1alpha1.GameServer, cond *metav1.Condition,
if cond.Reason == "ValidationFailed" {
return map[string]string{"details": in.playitErr}
}
case gameplanev1alpha1.GameServerConditionPortAllocation:
args := map[string]string{
"pool": in.ports.pool,
"ports": poolPortsSummary(in.ports.record.entries),
"count": strconv.Itoa(int(in.ports.needed)),
}
switch cond.Reason {
case portReasonAllocated, portReasonExhausted, portReasonChangePending, portReasonRollout:
case portReasonOutsideRange:
args["outside"] = poolPortsSummary(in.ports.outside)
case portReasonConflict, portReasonConflictNoSvc, portReasonRolloutPort:
if in.ports.conflict == nil {
return nil
}
args["port"], args["holder"] = in.ports.conflict.String(), in.ports.conflict.holder
default:
return nil
}
return args
case "IdleScheduleInvalid":
if cond.Reason == "WakeWindowUnparseable" && in.idleSchedErr != nil {
return map[string]string{"details": in.idleSchedErr.Error()}
Expand Down
Loading
Loading