From 4b549de1ffcff55dc2167806034f9827c4493c64 Mon Sep 17 00:00:00 2001 From: Ben Fulton Date: Mon, 16 Nov 2026 13:40:26 -0500 Subject: [PATCH 1/4] feat(operator): report a LoadBalancer server's hostname as its address spec.networking.hostname is the DNS name advertised for the Service, but the dashboard showed the load balancer's IP, so players were given an address that changes when the IP does, and admins whose load balancer sits behind another hop (a relay, a port-forwarding edge) had no way to show the address players actually use. Once the load balancer has published an address, status.endpoints now carries the hostname with the Service's ports. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Ben Fulton --- changelog/unreleased/hostname-endpoint.md | 7 ++ .../crds/gameplane.local_backups.yaml | 2 +- .../crds/gameplane.local_backupschedules.yaml | 2 +- .../crds/gameplane.local_clusters.yaml | 2 +- .../crds/gameplane.local_gameservers.yaml | 7 +- .../crds/gameplane.local_gametemplates.yaml | 2 +- .../crds/gameplane.local_modules.yaml | 2 +- .../crds/gameplane.local_modulesources.yaml | 2 +- .../crds/gameplane.local_networkcaptures.yaml | 2 +- .../crds/gameplane.local_restores.yaml | 2 +- .../gameplane.local_backups.yaml | 2 +- .../gameplane.local_backupschedules.yaml | 2 +- .../gameplane.local_clusters.yaml | 2 +- .../gameplane.local_gameservers.yaml | 7 +- .../gameplane.local_gametemplates.yaml | 2 +- .../gameplane.local_modules.yaml | 2 +- .../gameplane.local_modulesources.yaml | 2 +- .../gameplane.local_networkcaptures.yaml | 2 +- .../gameplane.local_restores.yaml | 2 +- docs/networking.md | 14 ++++ operator/api/v1alpha1/gameserver_types.go | 5 +- .../crd/gameplane.local_gameservers.yaml | 5 +- .../gameserver_hostname_endpoint_test.go | 64 +++++++++++++++++++ .../internal/controller/gameserver_status.go | 23 ++++++- 24 files changed, 141 insertions(+), 23 deletions(-) create mode 100644 changelog/unreleased/hostname-endpoint.md create mode 100644 operator/internal/controller/gameserver_hostname_endpoint_test.go diff --git a/changelog/unreleased/hostname-endpoint.md b/changelog/unreleased/hostname-endpoint.md new file mode 100644 index 000000000..3816bbb37 --- /dev/null +++ b/changelog/unreleased/hostname-endpoint.md @@ -0,0 +1,7 @@ +# LoadBalancer servers show their hostname as their address + +A LoadBalancer server with `spec.networking.hostname` set now reports that +hostname as its address in `status.endpoints` and the dashboard, once the +load balancer has published an address, in place of the load balancer's IP. +Players see the DNS name they should use. Servers without a hostname, and +ClusterIP or NodePort servers, are unchanged. diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backups.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backups.yaml index 3ffc19740..3df444176 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backups.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backups.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: backups.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backupschedules.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backupschedules.yaml index baa2cd0ea..6575ad78e 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backupschedules.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backupschedules.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: backupschedules.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_clusters.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_clusters.yaml index bf894b0e4..bc1c19c6b 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_clusters.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_clusters.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: clusters.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gameservers.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gameservers.yaml index 842028872..c3623042c 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gameservers.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gameservers.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: gameservers.gameplane.local spec: @@ -1398,7 +1398,10 @@ spec: ingress / external-dns annotations on the Service. Must be an RFC 1123 hostname: dotted labels of 1-63 alphanumeric characters or hyphens, no leading/trailing hyphen, at most 253 characters - total. The operator does not create the DNS record itself. + total. The operator does not create the DNS record itself. On a + LoadBalancer server, once the load balancer has an address, the + hostname is also the address status.endpoints and the dashboard + report, since it is the name players use. maxLength: 253 pattern: ^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*$ type: string diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gametemplates.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gametemplates.yaml index e5f5cd9ea..23e6048c1 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gametemplates.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gametemplates.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: gametemplates.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modules.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modules.yaml index aee445da9..33d404bd0 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modules.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modules.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: modules.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modulesources.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modulesources.yaml index 9339dd748..e1e5dcebc 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modulesources.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modulesources.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: modulesources.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_networkcaptures.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_networkcaptures.yaml index 586891bc2..3bf11ae28 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_networkcaptures.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_networkcaptures.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: networkcaptures.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_restores.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_restores.yaml index 782c4e556..cd1a1884b 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_restores.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_restores.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: restores.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_backups.yaml b/charts/gameplane/crd-manifests/gameplane.local_backups.yaml index 3ffc19740..3df444176 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_backups.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_backups.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: backups.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_backupschedules.yaml b/charts/gameplane/crd-manifests/gameplane.local_backupschedules.yaml index baa2cd0ea..6575ad78e 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_backupschedules.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_backupschedules.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: backupschedules.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_clusters.yaml b/charts/gameplane/crd-manifests/gameplane.local_clusters.yaml index bf894b0e4..bc1c19c6b 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_clusters.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_clusters.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: clusters.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_gameservers.yaml b/charts/gameplane/crd-manifests/gameplane.local_gameservers.yaml index 842028872..c3623042c 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_gameservers.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_gameservers.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: gameservers.gameplane.local spec: @@ -1398,7 +1398,10 @@ spec: ingress / external-dns annotations on the Service. Must be an RFC 1123 hostname: dotted labels of 1-63 alphanumeric characters or hyphens, no leading/trailing hyphen, at most 253 characters - total. The operator does not create the DNS record itself. + total. The operator does not create the DNS record itself. On a + LoadBalancer server, once the load balancer has an address, the + hostname is also the address status.endpoints and the dashboard + report, since it is the name players use. maxLength: 253 pattern: ^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*$ type: string diff --git a/charts/gameplane/crd-manifests/gameplane.local_gametemplates.yaml b/charts/gameplane/crd-manifests/gameplane.local_gametemplates.yaml index e5f5cd9ea..23e6048c1 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_gametemplates.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_gametemplates.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: gametemplates.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_modules.yaml b/charts/gameplane/crd-manifests/gameplane.local_modules.yaml index aee445da9..33d404bd0 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_modules.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_modules.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: modules.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_modulesources.yaml b/charts/gameplane/crd-manifests/gameplane.local_modulesources.yaml index 9339dd748..e1e5dcebc 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_modulesources.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_modulesources.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: modulesources.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_networkcaptures.yaml b/charts/gameplane/crd-manifests/gameplane.local_networkcaptures.yaml index 586891bc2..3bf11ae28 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_networkcaptures.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_networkcaptures.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: networkcaptures.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_restores.yaml b/charts/gameplane/crd-manifests/gameplane.local_restores.yaml index 782c4e556..cd1a1884b 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_restores.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_restores.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: f6d823caf1184485fc5a5cec8ff73668bbf02fbd250b06f24c9139766558b017 + gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 controller-gen.kubebuilder.io/version: v0.22.0 name: restores.gameplane.local spec: diff --git a/docs/networking.md b/docs/networking.md index 39354fe86..783872e42 100644 --- a/docs/networking.md +++ b/docs/networking.md @@ -278,6 +278,20 @@ For this reason, **changing the pool on a live server should be avoided when pos The project's e2e test `TestAddressPool_ChangePoolOnRunningServer` verifies that the pool assignment metadata is updated on the GameServer's status; it does not verify whether the actual IP address remains stable or changes, as this is load-balancer dependent. To determine the exact behavior in your deployment, test the address-change scenario against your specific load-balancer version and pool configuration before relying on it in production. +## A Hostname as the Server's Address + +Set `spec.networking.hostname` to the DNS name players use. The operator +adds it to the Service as an external-dns hint +(`external-dns.alpha.kubernetes.io/hostname`), and on a LoadBalancer server, +once the load balancer has published an address, `status.endpoints` and the +dashboard report the hostname in place of that address, with the Service's +ports. Players then see the name, which keeps working if the load balancer +hands out a new IP. + +The operator doesn't create the DNS record: external-dns does, from the +hint, or you keep one yourself. A ClusterIP or NodePort server keeps +reporting its own address. + ## Related - [`install.md`](install.md) — Helm chart values for `operator.addressManager` and cluster prerequisites. diff --git a/operator/api/v1alpha1/gameserver_types.go b/operator/api/v1alpha1/gameserver_types.go index a83957c11..559f8a22c 100644 --- a/operator/api/v1alpha1/gameserver_types.go +++ b/operator/api/v1alpha1/gameserver_types.go @@ -306,7 +306,10 @@ type GameServerNetworking struct { // ingress / external-dns annotations on the Service. Must be an // RFC 1123 hostname: dotted labels of 1-63 alphanumeric characters // or hyphens, no leading/trailing hyphen, at most 253 characters - // total. The operator does not create the DNS record itself. + // total. The operator does not create the DNS record itself. On a + // LoadBalancer server, once the load balancer has an address, the + // hostname is also the address status.endpoints and the dashboard + // report, since it is the name players use. // +kubebuilder:validation:MaxLength=253 // +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*$` // +optional diff --git a/operator/config/crd/gameplane.local_gameservers.yaml b/operator/config/crd/gameplane.local_gameservers.yaml index 805ab1295..41d136ee3 100644 --- a/operator/config/crd/gameplane.local_gameservers.yaml +++ b/operator/config/crd/gameplane.local_gameservers.yaml @@ -1397,7 +1397,10 @@ spec: ingress / external-dns annotations on the Service. Must be an RFC 1123 hostname: dotted labels of 1-63 alphanumeric characters or hyphens, no leading/trailing hyphen, at most 253 characters - total. The operator does not create the DNS record itself. + total. The operator does not create the DNS record itself. On a + LoadBalancer server, once the load balancer has an address, the + hostname is also the address status.endpoints and the dashboard + report, since it is the name players use. maxLength: 253 pattern: ^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)(\.[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?)*$ type: string diff --git a/operator/internal/controller/gameserver_hostname_endpoint_test.go b/operator/internal/controller/gameserver_hostname_endpoint_test.go new file mode 100644 index 000000000..ad497a9fe --- /dev/null +++ b/operator/internal/controller/gameserver_hostname_endpoint_test.go @@ -0,0 +1,64 @@ +package controller + +import ( + "testing" + + corev1 "k8s.io/api/core/v1" +) + +func udpLBService(ingress ...corev1.LoadBalancerIngress) *corev1.Service { + return &corev1.Service{ + Spec: corev1.ServiceSpec{ + Type: corev1.ServiceTypeLoadBalancer, + ClusterIP: "10.0.0.5", + Ports: []corev1.ServicePort{ + {Name: "game", Port: 2456, Protocol: corev1.ProtocolUDP}, + {Name: "query", Port: 2457, Protocol: corev1.ProtocolUDP}, + }, + }, + Status: corev1.ServiceStatus{LoadBalancer: corev1.LoadBalancerStatus{Ingress: ingress}}, + } +} + +func TestWithAdvertisedHostname_ReplacesTheLoadBalancerAddress(t *testing.T) { + svc := udpLBService(corev1.LoadBalancerIngress{IP: "192.0.2.10"}) + got := withAdvertisedHostname(endpointsFromService(svc, addressPlan{}), svc, "valheim.example.com") + if len(got) != 2 { + t.Fatalf("got %d endpoints, want 2", len(got)) + } + for _, ep := range got { + if ep.Host != "valheim.example.com" { + t.Errorf("%s: host %q, want the hostname", ep.Name, ep.Host) + } + } + if got[1].Port != 2457 { + t.Errorf("ports must be kept: got %d, want 2457", got[1].Port) + } +} + +func TestWithAdvertisedHostname_WaitsForAnAddress(t *testing.T) { + svc := udpLBService() + got := withAdvertisedHostname(endpointsFromService(svc, addressPlan{}), svc, "valheim.example.com") + if got[0].Host != "10.0.0.5" { + t.Errorf("host %q, want the cluster IP while no address is published", got[0].Host) + } +} + +func TestWithAdvertisedHostname_LeavesOtherServicesAlone(t *testing.T) { + for _, svcType := range []corev1.ServiceType{corev1.ServiceTypeClusterIP, corev1.ServiceTypeNodePort} { + svc := udpLBService(corev1.LoadBalancerIngress{IP: "192.0.2.10"}) + svc.Spec.Type = svcType + got := withAdvertisedHostname(endpointsFromService(svc, addressPlan{}), svc, "valheim.example.com") + if got[0].Host == "valheim.example.com" { + t.Errorf("%s: hostname reported, want the Service's own address", svcType) + } + } +} + +func TestWithAdvertisedHostname_NoHostnameIsUnchanged(t *testing.T) { + svc := udpLBService(corev1.LoadBalancerIngress{IP: "192.0.2.10"}) + got := withAdvertisedHostname(endpointsFromService(svc, addressPlan{}), svc, "") + if got[0].Host != "192.0.2.10" { + t.Errorf("host %q, want the load balancer IP", got[0].Host) + } +} diff --git a/operator/internal/controller/gameserver_status.go b/operator/internal/controller/gameserver_status.go index 361697ffa..3240868f8 100644 --- a/operator/internal/controller/gameserver_status.go +++ b/operator/internal/controller/gameserver_status.go @@ -265,7 +265,8 @@ func (r *GameServerReconciler) reconcileStatus( // Endpoints: tunnel endpoints come first (when present) so the dashboard's // Connection card reads the address players actually use. if svcExists { - gs.Status.Endpoints = endpointsFromService(&svc, addrPlan) + gs.Status.Endpoints = withAdvertisedHostname( + endpointsFromService(&svc, addrPlan), &svc, gs.Spec.Networking.Hostname) } else { // A deleted/replacing Service must not preserve a stale tailnet endpoint // when the forwarding deployment has since lost readiness. @@ -1311,6 +1312,26 @@ func loadBalancerAddress(svc *corev1.Service) string { return ing.IP } +// withAdvertisedHostname reports a LoadBalancer server's +// spec.networking.hostname as its address, in place of the load balancer's +// own. The hostname is the DNS name advertised for the Service (through +// external-dns, or a record the admin keeps), so it is the address players +// should use, and a name survives the load balancer handing out a new IP. +// It applies only once the load balancer has published an address, since +// until then the name has nothing to point at, and never to ClusterIP or +// NodePort Services, whose endpoints are not the name's target. +func withAdvertisedHostname( + eps []gameplanev1alpha1.GameServerEndpoint, svc *corev1.Service, hostname string, +) []gameplanev1alpha1.GameServerEndpoint { + if hostname == "" || loadBalancerAddress(svc) == "" { + return eps + } + for i := range eps { + eps[i].Host = hostname + } + return eps +} + // endpointsFromService lists the per-port externally reachable address // for a Service. For ClusterIP we report the cluster IP; for NodePort // we report the Service's declared port (the node IP is left to the API From 7292e10d719f1bae7ab4b32cd00d81e91245c108 Mon Sep 17 00:00:00 2001 From: Ben Fulton Date: Mon, 16 Nov 2026 21:22:03 -0500 Subject: [PATCH 2/4] docs(operator): record the advertised-hostname endpoint rule operator/specs.md now describes withAdvertisedHostname next to endpointsFromService: when it applies, and that ports are kept. The networking docs no longer promise the name keeps working after an IP change: that holds only when external-dns maintains the record. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Ben Fulton --- docs/networking.md | 11 ++++++----- operator/specs.md | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/networking.md b/docs/networking.md index 783872e42..6c9b07114 100644 --- a/docs/networking.md +++ b/docs/networking.md @@ -285,12 +285,13 @@ adds it to the Service as an external-dns hint (`external-dns.alpha.kubernetes.io/hostname`), and on a LoadBalancer server, once the load balancer has published an address, `status.endpoints` and the dashboard report the hostname in place of that address, with the Service's -ports. Players then see the name, which keeps working if the load balancer -hands out a new IP. +ports. Players then see the name instead of an IP. -The operator doesn't create the DNS record: external-dns does, from the -hint, or you keep one yourself. A ClusterIP or NodePort server keeps -reporting its own address. +The operator doesn't create the DNS record. With external-dns watching +Services, the record is created from the hint and follows the load balancer +if it hands out a new IP. A record you keep yourself must be updated by hand +when that happens, or players reach the old address. A ClusterIP or NodePort +server keeps reporting its own address. ## Related diff --git a/operator/specs.md b/operator/specs.md index 0da5aa7f8..1ea8b6348 100644 --- a/operator/specs.md +++ b/operator/specs.md @@ -479,6 +479,7 @@ Primary reconcilers register with the manager in `cmd/main.go` and handle CRD li - Unset (condition absent): no pool or address requested; no condition emitted. - Precedence when several apply: `IgnoredForExposureMode` → `InvalidAddress` → `NoAddressManagerConfigured` → direct-conflict `AddressInUse` → event-derived failure → `ServiceNotReady` → `AssignmentPending` → `Assigned`. - **Endpoint population:** `endpointsFromService()` populates `GameServerEndpoint.pool` only when a pool request was actually translated (outcome == Assigned and Manager supports it); never claims a pool for the ClusterIP address shown while assignment is pending, for an ignored request, or for a cluster without an address manager. + - **Advertised hostname:** `withAdvertisedHostname()` (`gameserver_status.go`) wraps `endpointsFromService()` at its one call site in `reconcileStatus`. When `spec.networking.hostname` is non-empty, the Service is a LoadBalancer, and the load balancer has published an address (`status.loadBalancer.ingress` has an IP or hostname), it replaces the `Host` of every endpoint with the hostname. Ports, protocols and every other field are kept, one endpoint per Service port as before. Until the load balancer publishes an address, and for ClusterIP and NodePort servers or servers without a hostname, the endpoints are unchanged. Tunnel endpoints aren't touched, since they don't come from the Service. Test: `gameserver_hostname_endpoint_test.go`. - **status.startedAt:** while the server is Running, `status.startedAt` follows the start time of the running game container, matched by container name (`gameContainerStartedAt` in `gameserver_status.go`). Uptime therefore resets when the game container restarts inside the same pod. When that time is unavailable, `startedAt` is set once to the current time and kept. Test: `TestGameContainerStartedAt` (`gameserver_status_test.go`). - **conditionArgs:** `status.conditionArgs[]` carries the values interpolated into the English `message` of the condition's current reason, recomputed on every `reconcileStatus` pass by `deriveConditionArgs` (`gameserver_condition_args.go`); `setPhase`, `setTunnelCredentialRefused` and `clearTunnelCredentialRefused` maintain their own entry. The `message` is unchanged. Translation ids are `condition..` (lower-cased) and are listed in `i18n/locales/en/app.json`. - **TunnelReady condition:** Reports tunnel pod readiness when `spec.networking.tunnel.enabled=true` (absent when disabled). Computed in `computeTunnelConditions` (`gameserver_status.go`) each pass reconcileStatus runs, with reasons `InvalidConfig`, `UnsupportedProtocol` (Tailscale, advertised protocols other than TCP/UDP), `DeploymentNotReady`, `PortNotMapped` (frp, unmapped advertised ports), `NoCredentials` (tailscale/playit missing `credentialsSecretRef`), `UnknownProvider`, and `Ready`. **Credential ownership:** `reconcileTunnel` refuses to mount a `credentialsSecretRef` Secret that has no `ownerReference` matching the GameServer's name and UID (including a stale reference from a deleted same-name GameServer) (`isServerOwnedSecret`) — supported credential paths are the dashboard, the `PUT /servers/{name}:tunnel-credentials` API (which sets the ownerReference), or a manually-created Secret with an explicit ownerReference. A refused Secret is never mounted: `reconcileTunnel` still writes the tunnel Deployment, with no credential volume and zero replicas, so a tunnel already running with that Secret stops. It also writes `TunnelReady=False/TunnelCredentialRefused` (naming the Secret, never its data) directly from `reconcileTunnel` before `Reconcile` returns its error — this bypasses the normal `reconcileStatus` pass since Reconcile returns early on that error — The condition carries its own current `observedGeneration`, but `status.observedGeneration` is not advanced on a refused pass (the rest of status is not recomputed). Once the credential becomes acceptable (or the tunnel is no longer wanted), `reconcileTunnel` removes the refusal condition itself (`clearTunnelCredentialRefused`) before returning, so it does not linger if a later step (NetworkPolicy, Service, StatefulSet) fails; reconcileStatus then writes the real TunnelReady. The refusal message points at the dashboard/API, except when the refused Secret is the canonical `-tunnel-auth` name, where the API answers 409 and the message says to fix the ownerReference or delete the Secret first. From 80838bd75b0e54cce939d8d6bc6dce119b54eb43 Mon Sep 17 00:00:00 2001 From: Ben Fulton Date: Tue, 17 Nov 2026 08:05:30 -0500 Subject: [PATCH 3/4] fix(operator): keep a server's Service address apart from its advertised hostname Review follow-ups for advertising spec.networking.hostname: - Endpoints now carry serviceAddress, the Service's assigned address, alongside host, which may be the hostname. Address-conflict detection compares serviceAddress (falling back to host for older status), so a pool-assigned holder advertising a hostname still holds its IP, and an explicit holder keeps its priority over an older requester. Unit regression tests cover both. - E2E TestAddressPool_HostnameHolderKeepsAddress checks the hostname and serviceAddress in status, and that a server requesting the holder's IP is refused with AddressInUse. - The changelog and docs/networking.md spell out that every existing LoadBalancer server with a hostname starts advertising it on upgrade. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Ben Fulton --- changelog/unreleased/999-hostname-endpoint.md | 12 ++ changelog/unreleased/hostname-endpoint.md | 7 - .../crds/gameplane.local_backups.yaml | 2 +- .../crds/gameplane.local_backupschedules.yaml | 2 +- .../crds/gameplane.local_clusters.yaml | 2 +- .../crds/gameplane.local_gameservers.yaml | 24 +++- .../crds/gameplane.local_gametemplates.yaml | 2 +- .../crds/gameplane.local_modules.yaml | 2 +- .../crds/gameplane.local_modulesources.yaml | 2 +- .../crds/gameplane.local_networkcaptures.yaml | 2 +- .../crds/gameplane.local_restores.yaml | 2 +- .../gameplane.local_backups.yaml | 2 +- .../gameplane.local_backupschedules.yaml | 2 +- .../gameplane.local_clusters.yaml | 2 +- .../gameplane.local_gameservers.yaml | 24 +++- .../gameplane.local_gametemplates.yaml | 2 +- .../gameplane.local_modules.yaml | 2 +- .../gameplane.local_modulesources.yaml | 2 +- .../gameplane.local_networkcaptures.yaml | 2 +- .../gameplane.local_restores.yaml | 2 +- docs/networking.md | 9 ++ operator/api/v1alpha1/gameserver_types.go | 10 ++ .../crd/gameplane.local_gameservers.yaml | 22 +++ .../controller/gameserver_controller.go | 14 +- .../gameserver_hostname_endpoint_test.go | 109 +++++++++++++++ .../internal/controller/gameserver_status.go | 15 +- operator/specs.md | 2 +- test/e2e/buckets.sh | 1 + test/e2e/hostname_endpoint_e2e_test.go | 131 ++++++++++++++++++ web/src/types.ts | 3 + 30 files changed, 381 insertions(+), 34 deletions(-) create mode 100644 changelog/unreleased/999-hostname-endpoint.md delete mode 100644 changelog/unreleased/hostname-endpoint.md create mode 100644 test/e2e/hostname_endpoint_e2e_test.go diff --git a/changelog/unreleased/999-hostname-endpoint.md b/changelog/unreleased/999-hostname-endpoint.md new file mode 100644 index 000000000..30d8ea618 --- /dev/null +++ b/changelog/unreleased/999-hostname-endpoint.md @@ -0,0 +1,12 @@ +# LoadBalancer servers show their hostname as their address + +After upgrading, every LoadBalancer server that already has +`spec.networking.hostname` set reports that hostname as its address in +`status.endpoints` and the dashboard, in place of the load balancer's IP, once +the load balancer has published one. Check that each such hostname resolves to +its server before upgrading, or clear it on servers where it doesn't; players +would otherwise be shown a name that doesn't reach the server. The assigned +address stays in the new `status.endpoints[].serviceAddress`. Servers without a +hostname, and ClusterIP or NodePort servers, are unchanged. See +[A hostname as the server's address](../../docs/networking.md#a-hostname-as-the-servers-address). +[PR #999](https://github.com/GameplanePanel/Gameplane/pull/999) diff --git a/changelog/unreleased/hostname-endpoint.md b/changelog/unreleased/hostname-endpoint.md deleted file mode 100644 index 3816bbb37..000000000 --- a/changelog/unreleased/hostname-endpoint.md +++ /dev/null @@ -1,7 +0,0 @@ -# LoadBalancer servers show their hostname as their address - -A LoadBalancer server with `spec.networking.hostname` set now reports that -hostname as its address in `status.endpoints` and the dashboard, once the -load balancer has published an address, in place of the load balancer's IP. -Players see the DNS name they should use. Servers without a hostname, and -ClusterIP or NodePort servers, are unchanged. diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backups.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backups.yaml index 3df444176..9ecadb2f6 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backups.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backups.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: backups.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backupschedules.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backupschedules.yaml index 6575ad78e..759a17245 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backupschedules.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backupschedules.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: backupschedules.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_clusters.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_clusters.yaml index bc1c19c6b..f2c756d6a 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_clusters.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_clusters.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: clusters.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gameservers.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gameservers.yaml index c3623042c..2a52c5826 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gameservers.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gameservers.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: gameservers.gameplane.local spec: @@ -2604,6 +2604,9 @@ spec: associated with a named template port. properties: host: + description: |- + Host is the address players connect to: the Service's address, or on + a LoadBalancer server with spec.networking.hostname, that hostname. type: string name: type: string @@ -2627,6 +2630,14 @@ spec: description: Protocol defines network protocols supported for things like container ports. type: string + serviceAddress: + description: |- + ServiceAddress is the address the backing Service was assigned (its + load-balancer IP or hostname, or its cluster IP while none is + published), kept apart from Host so an advertised hostname doesn't + hide which address a server holds. Reconciler-owned; empty on tunnel + endpoints and on status written by an operator that predates it. + type: string tunnelProvider: description: |- TunnelProvider is set when this endpoint is served by a tunnel @@ -2732,6 +2743,9 @@ spec: associated with a named template port. properties: host: + description: |- + Host is the address players connect to: the Service's address, or on + a LoadBalancer server with spec.networking.hostname, that hostname. type: string name: type: string @@ -2755,6 +2769,14 @@ spec: description: Protocol defines network protocols supported for things like container ports. type: string + serviceAddress: + description: |- + ServiceAddress is the address the backing Service was assigned (its + load-balancer IP or hostname, or its cluster IP while none is + published), kept apart from Host so an advertised hostname doesn't + hide which address a server holds. Reconciler-owned; empty on tunnel + endpoints and on status written by an operator that predates it. + type: string tunnelProvider: description: |- TunnelProvider is set when this endpoint is served by a tunnel diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gametemplates.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gametemplates.yaml index 23e6048c1..4574c3c4a 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gametemplates.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gametemplates.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: gametemplates.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modules.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modules.yaml index 33d404bd0..c5ae2ed39 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modules.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modules.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: modules.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modulesources.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modulesources.yaml index e1e5dcebc..4797a4d40 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modulesources.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modulesources.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: modulesources.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_networkcaptures.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_networkcaptures.yaml index 3bf11ae28..02450de8b 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_networkcaptures.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_networkcaptures.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: networkcaptures.gameplane.local spec: diff --git a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_restores.yaml b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_restores.yaml index cd1a1884b..96c64f674 100644 --- a/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_restores.yaml +++ b/charts/gameplane/charts/gameplane-crds/crds/gameplane.local_restores.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: restores.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_backups.yaml b/charts/gameplane/crd-manifests/gameplane.local_backups.yaml index 3df444176..9ecadb2f6 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_backups.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_backups.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: backups.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_backupschedules.yaml b/charts/gameplane/crd-manifests/gameplane.local_backupschedules.yaml index 6575ad78e..759a17245 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_backupschedules.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_backupschedules.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: backupschedules.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_clusters.yaml b/charts/gameplane/crd-manifests/gameplane.local_clusters.yaml index bc1c19c6b..f2c756d6a 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_clusters.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_clusters.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: clusters.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_gameservers.yaml b/charts/gameplane/crd-manifests/gameplane.local_gameservers.yaml index c3623042c..2a52c5826 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_gameservers.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_gameservers.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: gameservers.gameplane.local spec: @@ -2604,6 +2604,9 @@ spec: associated with a named template port. properties: host: + description: |- + Host is the address players connect to: the Service's address, or on + a LoadBalancer server with spec.networking.hostname, that hostname. type: string name: type: string @@ -2627,6 +2630,14 @@ spec: description: Protocol defines network protocols supported for things like container ports. type: string + serviceAddress: + description: |- + ServiceAddress is the address the backing Service was assigned (its + load-balancer IP or hostname, or its cluster IP while none is + published), kept apart from Host so an advertised hostname doesn't + hide which address a server holds. Reconciler-owned; empty on tunnel + endpoints and on status written by an operator that predates it. + type: string tunnelProvider: description: |- TunnelProvider is set when this endpoint is served by a tunnel @@ -2732,6 +2743,9 @@ spec: associated with a named template port. properties: host: + description: |- + Host is the address players connect to: the Service's address, or on + a LoadBalancer server with spec.networking.hostname, that hostname. type: string name: type: string @@ -2755,6 +2769,14 @@ spec: description: Protocol defines network protocols supported for things like container ports. type: string + serviceAddress: + description: |- + ServiceAddress is the address the backing Service was assigned (its + load-balancer IP or hostname, or its cluster IP while none is + published), kept apart from Host so an advertised hostname doesn't + hide which address a server holds. Reconciler-owned; empty on tunnel + endpoints and on status written by an operator that predates it. + type: string tunnelProvider: description: |- TunnelProvider is set when this endpoint is served by a tunnel diff --git a/charts/gameplane/crd-manifests/gameplane.local_gametemplates.yaml b/charts/gameplane/crd-manifests/gameplane.local_gametemplates.yaml index 23e6048c1..4574c3c4a 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_gametemplates.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_gametemplates.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: gametemplates.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_modules.yaml b/charts/gameplane/crd-manifests/gameplane.local_modules.yaml index 33d404bd0..c5ae2ed39 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_modules.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_modules.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: modules.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_modulesources.yaml b/charts/gameplane/crd-manifests/gameplane.local_modulesources.yaml index e1e5dcebc..4797a4d40 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_modulesources.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_modulesources.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: modulesources.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_networkcaptures.yaml b/charts/gameplane/crd-manifests/gameplane.local_networkcaptures.yaml index 3bf11ae28..02450de8b 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_networkcaptures.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_networkcaptures.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: networkcaptures.gameplane.local spec: diff --git a/charts/gameplane/crd-manifests/gameplane.local_restores.yaml b/charts/gameplane/crd-manifests/gameplane.local_restores.yaml index cd1a1884b..96c64f674 100644 --- a/charts/gameplane/crd-manifests/gameplane.local_restores.yaml +++ b/charts/gameplane/crd-manifests/gameplane.local_restores.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - gameplane.local/crd-bundle-sha256: 2a9de318ff6d2d196acba35b3d046921ccc9ae4dc5f00c6ea3ba1853d95aef72 + gameplane.local/crd-bundle-sha256: b409bc125837ec9256cb4968d3f98a162c9a145dee35b16c22f39498a9892e64 controller-gen.kubebuilder.io/version: v0.22.0 name: restores.gameplane.local spec: diff --git a/docs/networking.md b/docs/networking.md index 6c9b07114..a28fdaa39 100644 --- a/docs/networking.md +++ b/docs/networking.md @@ -293,6 +293,15 @@ if it hands out a new IP. A record you keep yourself must be updated by hand when that happens, or players reach the old address. A ClusterIP or NodePort server keeps reporting its own address. +The load balancer's address stays in `status.endpoints[].serviceAddress`, and +address-conflict checks for `spec.networking.address` compare against it, so +a server advertising a hostname still holds its IP. + +This applies to every LoadBalancer server with a hostname, including ones +created before the upgrade that introduced it. A hostname that doesn't +resolve to its server would now be shown to players, so before upgrading, +check each such hostname, or clear it where it isn't the name players use. + ## Related - [`install.md`](install.md) — Helm chart values for `operator.addressManager` and cluster prerequisites. diff --git a/operator/api/v1alpha1/gameserver_types.go b/operator/api/v1alpha1/gameserver_types.go index 559f8a22c..605648b85 100644 --- a/operator/api/v1alpha1/gameserver_types.go +++ b/operator/api/v1alpha1/gameserver_types.go @@ -692,8 +692,18 @@ type CaptureStatus struct { // associated with a named template port. type GameServerEndpoint struct { Name string `json:"name"` + // Host is the address players connect to: the Service's address, or on + // a LoadBalancer server with spec.networking.hostname, that hostname. Host string `json:"host"` Port int32 `json:"port"` + + // ServiceAddress is the address the backing Service was assigned (its + // load-balancer IP or hostname, or its cluster IP while none is + // published), kept apart from Host so an advertised hostname doesn't + // hide which address a server holds. Reconciler-owned; empty on tunnel + // endpoints and on status written by an operator that predates it. + // +optional + ServiceAddress string `json:"serviceAddress,omitempty"` // +optional Protocol corev1.Protocol `json:"protocol,omitempty"` diff --git a/operator/config/crd/gameplane.local_gameservers.yaml b/operator/config/crd/gameplane.local_gameservers.yaml index 41d136ee3..483d6c866 100644 --- a/operator/config/crd/gameplane.local_gameservers.yaml +++ b/operator/config/crd/gameplane.local_gameservers.yaml @@ -2603,6 +2603,9 @@ spec: associated with a named template port. properties: host: + description: |- + Host is the address players connect to: the Service's address, or on + a LoadBalancer server with spec.networking.hostname, that hostname. type: string name: type: string @@ -2626,6 +2629,14 @@ spec: description: Protocol defines network protocols supported for things like container ports. type: string + serviceAddress: + description: |- + ServiceAddress is the address the backing Service was assigned (its + load-balancer IP or hostname, or its cluster IP while none is + published), kept apart from Host so an advertised hostname doesn't + hide which address a server holds. Reconciler-owned; empty on tunnel + endpoints and on status written by an operator that predates it. + type: string tunnelProvider: description: |- TunnelProvider is set when this endpoint is served by a tunnel @@ -2731,6 +2742,9 @@ spec: associated with a named template port. properties: host: + description: |- + Host is the address players connect to: the Service's address, or on + a LoadBalancer server with spec.networking.hostname, that hostname. type: string name: type: string @@ -2754,6 +2768,14 @@ spec: description: Protocol defines network protocols supported for things like container ports. type: string + serviceAddress: + description: |- + ServiceAddress is the address the backing Service was assigned (its + load-balancer IP or hostname, or its cluster IP while none is + published), kept apart from Host so an advertised hostname doesn't + hide which address a server holds. Reconciler-owned; empty on tunnel + endpoints and on status written by an operator that predates it. + type: string tunnelProvider: description: |- TunnelProvider is set when this endpoint is served by a tunnel diff --git a/operator/internal/controller/gameserver_controller.go b/operator/internal/controller/gameserver_controller.go index 26172dbbd..e91c2925f 100644 --- a/operator/internal/controller/gameserver_controller.go +++ b/operator/internal/controller/gameserver_controller.go @@ -3045,7 +3045,10 @@ func (r *GameServerReconciler) findAddressConflict( // candidateHoldsAddress reports whether gs is a genuine LoadBalancer holder // of addr — its expose mode is LoadBalancer and one of its status.endpoints -// carries addr as Host with no TunnelProvider. See the discriminator notes +// carries addr as its Service address with no TunnelProvider. The Service +// address is ServiceAddress, not Host, since Host may be an advertised +// hostname; Host is the fallback for status written before ServiceAddress +// existed, when the two were always the same. See the discriminator notes // on findAddressConflict for what this deliberately excludes (tunnel-sourced // endpoints, and the residual ClusterIP-fallback edge case). func candidateHoldsAddress(gs *gameplanev1alpha1.GameServer, addr string) bool { @@ -3053,7 +3056,14 @@ func candidateHoldsAddress(gs *gameplanev1alpha1.GameServer, addr string) bool { return false } for _, endpoint := range gs.Status.Endpoints { - if endpoint.TunnelProvider == "" && endpoint.Host == addr { + if endpoint.TunnelProvider != "" { + continue + } + held := endpoint.ServiceAddress + if held == "" { + held = endpoint.Host + } + if held == addr { return true } } diff --git a/operator/internal/controller/gameserver_hostname_endpoint_test.go b/operator/internal/controller/gameserver_hostname_endpoint_test.go index ad497a9fe..dbe17a284 100644 --- a/operator/internal/controller/gameserver_hostname_endpoint_test.go +++ b/operator/internal/controller/gameserver_hostname_endpoint_test.go @@ -1,9 +1,15 @@ package controller import ( + "context" "testing" + "time" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client/fake" + + gameplanev1alpha1 "github.com/GameplanePanel/gameplane/operator/api/v1alpha1" ) func udpLBService(ingress ...corev1.LoadBalancerIngress) *corev1.Service { @@ -34,6 +40,11 @@ func TestWithAdvertisedHostname_ReplacesTheLoadBalancerAddress(t *testing.T) { if got[1].Port != 2457 { t.Errorf("ports must be kept: got %d, want 2457", got[1].Port) } + for _, ep := range got { + if ep.ServiceAddress != "192.0.2.10" { + t.Errorf("%s: serviceAddress %q, want the load balancer IP", ep.Name, ep.ServiceAddress) + } + } } func TestWithAdvertisedHostname_WaitsForAnAddress(t *testing.T) { @@ -62,3 +73,101 @@ func TestWithAdvertisedHostname_NoHostnameIsUnchanged(t *testing.T) { t.Errorf("host %q, want the load balancer IP", got[0].Host) } } + +// advertisingHolder is a LoadBalancer server holding addr, with the +// endpoints reconcileStatus writes for it: built by endpointsFromService +// and withAdvertisedHostname, so Host is its hostname, not addr. +func advertisingHolder(name, addr, requested string, created metav1.Time) *gameplanev1alpha1.GameServer { + svc := udpLBService(corev1.LoadBalancerIngress{IP: addr}) + return &gameplanev1alpha1.GameServer{ + ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: "games", CreationTimestamp: created}, + Spec: gameplanev1alpha1.GameServerSpec{Networking: gameplanev1alpha1.GameServerNetworking{ + Expose: "LoadBalancer", Address: requested, Hostname: name + ".example.com", + }}, + Status: gameplanev1alpha1.GameServerStatus{ + Endpoints: withAdvertisedHostname(endpointsFromService(svc, addressPlan{}), svc, name+".example.com"), + }, + } +} + +// TestFindAddressConflict_PoolHolderWithHostname — a pool-assigned holder +// that advertises a hostname still holds its load-balancer IP, so a server +// requesting that IP is told who has it. +func TestFindAddressConflict_PoolHolderWithHostname(t *testing.T) { + s := testScheme(t) + now := metav1.Now() + holder := advertisingHolder("beta", "192.0.2.10", "", metav1.NewTime(now.Add(-10*time.Second))) + if holder.Status.Endpoints[0].Host == "192.0.2.10" { + t.Fatal("setup: the holder's Host should be its hostname") + } + requester := &gameplanev1alpha1.GameServer{ + ObjectMeta: metav1.ObjectMeta{Name: "alpha", Namespace: "games", CreationTimestamp: now}, + Spec: gameplanev1alpha1.GameServerSpec{Networking: gameplanev1alpha1.GameServerNetworking{ + Expose: "LoadBalancer", Address: "192.0.2.10", + }}, + } + cl := fake.NewClientBuilder().WithScheme(s).WithObjects(holder, requester).Build() + r := &GameServerReconciler{Client: cl, APIReader: cl, Scheme: s} + + conflict, err := r.findAddressConflict(context.Background(), requester) + if err != nil { + t.Fatalf("findAddressConflict: %v", err) + } + if conflict != "beta" { + t.Errorf("want conflict 'beta', got %q", conflict) + } +} + +// TestFindAddressConflict_ExplicitHolderWithHostnameKeepsPriority — an +// explicit holder that advertises a hostname keeps its priority over an +// older server requesting the same address: the holder reports no conflict, +// and the requester is the one told the address is taken. +func TestFindAddressConflict_ExplicitHolderWithHostnameKeepsPriority(t *testing.T) { + s := testScheme(t) + now := metav1.Now() + holder := advertisingHolder("beta", "192.0.2.10", "192.0.2.10", now) + older := &gameplanev1alpha1.GameServer{ + ObjectMeta: metav1.ObjectMeta{ + Name: "alpha", Namespace: "games", CreationTimestamp: metav1.NewTime(now.Add(-10 * time.Second)), + }, + Spec: gameplanev1alpha1.GameServerSpec{Networking: gameplanev1alpha1.GameServerNetworking{ + Expose: "LoadBalancer", Address: "192.0.2.10", + }}, + } + cl := fake.NewClientBuilder().WithScheme(s).WithObjects(holder, older).Build() + r := &GameServerReconciler{Client: cl, APIReader: cl, Scheme: s} + + conflict, err := r.findAddressConflict(context.Background(), holder) + if err != nil { + t.Fatalf("findAddressConflict(holder): %v", err) + } + if conflict != "" { + t.Errorf("holder: want no conflict, got %q", conflict) + } + conflict, err = r.findAddressConflict(context.Background(), older) + if err != nil { + t.Fatalf("findAddressConflict(older): %v", err) + } + if conflict != "beta" { + t.Errorf("older requester: want conflict 'beta', got %q", conflict) + } +} + +// TestCandidateHoldsAddress_FallsBackToHost — status written before +// serviceAddress existed has only Host, which was then always the Service's +// address, so it still counts. +func TestCandidateHoldsAddress_FallsBackToHost(t *testing.T) { + gs := &gameplanev1alpha1.GameServer{ + Spec: gameplanev1alpha1.GameServerSpec{Networking: gameplanev1alpha1.GameServerNetworking{Expose: "LoadBalancer"}}, + Status: gameplanev1alpha1.GameServerStatus{Endpoints: []gameplanev1alpha1.GameServerEndpoint{ + {Name: "game", Host: "192.0.2.10", Port: 2456}, + }}, + } + if !candidateHoldsAddress(gs, "192.0.2.10") { + t.Error("an endpoint with only Host must still hold its address") + } + gs.Status.Endpoints[0].ServiceAddress = "192.0.2.11" + if candidateHoldsAddress(gs, "192.0.2.10") { + t.Error("serviceAddress, when set, decides what is held, not Host") + } +} diff --git a/operator/internal/controller/gameserver_status.go b/operator/internal/controller/gameserver_status.go index 3240868f8..68138ebe2 100644 --- a/operator/internal/controller/gameserver_status.go +++ b/operator/internal/controller/gameserver_status.go @@ -1319,7 +1319,9 @@ func loadBalancerAddress(svc *corev1.Service) string { // should use, and a name survives the load balancer handing out a new IP. // It applies only once the load balancer has published an address, since // until then the name has nothing to point at, and never to ClusterIP or -// NodePort Services, whose endpoints are not the name's target. +// NodePort Services, whose endpoints are not the name's target. Only Host +// changes: ServiceAddress keeps the load balancer's address, which address +// conflict detection compares against (candidateHoldsAddress). func withAdvertisedHostname( eps []gameplanev1alpha1.GameServerEndpoint, svc *corev1.Service, hostname string, ) []gameplanev1alpha1.GameServerEndpoint { @@ -1363,11 +1365,12 @@ func endpointsFromService( } for _, p := range svc.Spec.Ports { ep := gameplanev1alpha1.GameServerEndpoint{ - Name: p.Name, - Host: host, - Port: p.Port, - Protocol: p.Protocol, - Pool: pool, + Name: p.Name, + Host: host, + ServiceAddress: host, + Port: p.Port, + Protocol: p.Protocol, + Pool: pool, } if svc.Spec.Type == corev1.ServiceTypeNodePort && p.NodePort != 0 { ep.Port = p.NodePort diff --git a/operator/specs.md b/operator/specs.md index 1ea8b6348..b3504578d 100644 --- a/operator/specs.md +++ b/operator/specs.md @@ -479,7 +479,7 @@ Primary reconcilers register with the manager in `cmd/main.go` and handle CRD li - Unset (condition absent): no pool or address requested; no condition emitted. - Precedence when several apply: `IgnoredForExposureMode` → `InvalidAddress` → `NoAddressManagerConfigured` → direct-conflict `AddressInUse` → event-derived failure → `ServiceNotReady` → `AssignmentPending` → `Assigned`. - **Endpoint population:** `endpointsFromService()` populates `GameServerEndpoint.pool` only when a pool request was actually translated (outcome == Assigned and Manager supports it); never claims a pool for the ClusterIP address shown while assignment is pending, for an ignored request, or for a cluster without an address manager. - - **Advertised hostname:** `withAdvertisedHostname()` (`gameserver_status.go`) wraps `endpointsFromService()` at its one call site in `reconcileStatus`. When `spec.networking.hostname` is non-empty, the Service is a LoadBalancer, and the load balancer has published an address (`status.loadBalancer.ingress` has an IP or hostname), it replaces the `Host` of every endpoint with the hostname. Ports, protocols and every other field are kept, one endpoint per Service port as before. Until the load balancer publishes an address, and for ClusterIP and NodePort servers or servers without a hostname, the endpoints are unchanged. Tunnel endpoints aren't touched, since they don't come from the Service. Test: `gameserver_hostname_endpoint_test.go`. + - **Advertised hostname:** `withAdvertisedHostname()` (`gameserver_status.go`) wraps `endpointsFromService()` at its one call site in `reconcileStatus`. When `spec.networking.hostname` is non-empty, the Service is a LoadBalancer, and the load balancer has published an address (`status.loadBalancer.ingress` has an IP or hostname), it replaces the `Host` of every endpoint with the hostname. Ports, protocols and every other field are kept, one endpoint per Service port as before. Until the load balancer publishes an address, and for ClusterIP and NodePort servers or servers without a hostname, the endpoints are unchanged. Tunnel endpoints aren't touched, since they don't come from the Service. `endpointsFromService()` also sets `ServiceAddress` on every endpoint to the Service's assigned address (the load-balancer IP or hostname, or the cluster IP fallback), and `withAdvertisedHostname()` leaves it alone, so the allocation identity stays separate from the advertised connection address. `candidateHoldsAddress` compares `ServiceAddress`, falling back to `Host` for status written before the field existed, so a pool-assigned holder that advertises a hostname still holds its IP, and an explicit holder keeps its priority over an older requester. The behavior is on for every LoadBalancer server with a hostname, existing ones included; the changelog tells operators to check those hostnames before upgrading. Tests: `gameserver_hostname_endpoint_test.go` (including `TestFindAddressConflict_PoolHolderWithHostname` and `TestFindAddressConflict_ExplicitHolderWithHostnameKeepsPriority`), E2E `TestAddressPool_HostnameHolderKeepsAddress`. - **status.startedAt:** while the server is Running, `status.startedAt` follows the start time of the running game container, matched by container name (`gameContainerStartedAt` in `gameserver_status.go`). Uptime therefore resets when the game container restarts inside the same pod. When that time is unavailable, `startedAt` is set once to the current time and kept. Test: `TestGameContainerStartedAt` (`gameserver_status_test.go`). - **conditionArgs:** `status.conditionArgs[]` carries the values interpolated into the English `message` of the condition's current reason, recomputed on every `reconcileStatus` pass by `deriveConditionArgs` (`gameserver_condition_args.go`); `setPhase`, `setTunnelCredentialRefused` and `clearTunnelCredentialRefused` maintain their own entry. The `message` is unchanged. Translation ids are `condition..` (lower-cased) and are listed in `i18n/locales/en/app.json`. - **TunnelReady condition:** Reports tunnel pod readiness when `spec.networking.tunnel.enabled=true` (absent when disabled). Computed in `computeTunnelConditions` (`gameserver_status.go`) each pass reconcileStatus runs, with reasons `InvalidConfig`, `UnsupportedProtocol` (Tailscale, advertised protocols other than TCP/UDP), `DeploymentNotReady`, `PortNotMapped` (frp, unmapped advertised ports), `NoCredentials` (tailscale/playit missing `credentialsSecretRef`), `UnknownProvider`, and `Ready`. **Credential ownership:** `reconcileTunnel` refuses to mount a `credentialsSecretRef` Secret that has no `ownerReference` matching the GameServer's name and UID (including a stale reference from a deleted same-name GameServer) (`isServerOwnedSecret`) — supported credential paths are the dashboard, the `PUT /servers/{name}:tunnel-credentials` API (which sets the ownerReference), or a manually-created Secret with an explicit ownerReference. A refused Secret is never mounted: `reconcileTunnel` still writes the tunnel Deployment, with no credential volume and zero replicas, so a tunnel already running with that Secret stops. It also writes `TunnelReady=False/TunnelCredentialRefused` (naming the Secret, never its data) directly from `reconcileTunnel` before `Reconcile` returns its error — this bypasses the normal `reconcileStatus` pass since Reconcile returns early on that error — The condition carries its own current `observedGeneration`, but `status.observedGeneration` is not advanced on a refused pass (the rest of status is not recomputed). Once the credential becomes acceptable (or the tunnel is no longer wanted), `reconcileTunnel` removes the refusal condition itself (`clearTunnelCredentialRefused`) before returning, so it does not linger if a later step (NetworkPolicy, Service, StatefulSet) fails; reconcileStatus then writes the real TunnelReady. The refusal message points at the dashboard/API, except when the refused Secret is the canonical `-tunnel-auth` name, where the API answers 409 and the message says to fix the ownerReference or delete the Secret first. diff --git a/test/e2e/buckets.sh b/test/e2e/buckets.sh index ad47ddeee..56d5f50a7 100755 --- a/test/e2e/buckets.sh +++ b/test/e2e/buckets.sh @@ -111,6 +111,7 @@ TestAddressPool_StatusVisibleInAddressAssignmentCondition TestAddressPool_ExplicitAddressRequest TestAddressPool_AddressInUseConflict TestAddressPool_PoolExhausted +TestAddressPool_HostnameHolderKeepsAddress TestAPI_EventStreamAndRoleEdits_FollowCallerPermissions TestAPI_I18n_LanguagePref TestAPI_I18n_NotifyLanguage diff --git a/test/e2e/hostname_endpoint_e2e_test.go b/test/e2e/hostname_endpoint_e2e_test.go new file mode 100644 index 000000000..e3cb02f5c --- /dev/null +++ b/test/e2e/hostname_endpoint_e2e_test.go @@ -0,0 +1,131 @@ +//go:build e2e + +package e2e + +import ( + "context" + "fmt" + "net" + "strings" + "testing" + "time" + + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" +) + +// TestAddressPool_HostnameHolderKeepsAddress — a pool-assigned LoadBalancer +// server with spec.networking.hostname reports the hostname as each +// endpoint's host and its load-balancer IP as serviceAddress. It still holds +// that IP: a second server requesting it is refused with AddressInUse naming +// the holder, as it would be if the holder showed its IP. +func TestAddressPool_HostnameHolderKeepsAddress(t *testing.T) { + t.Parallel() + + ctx := context.Background() + ns := "gameplane-games" + suffix := time.Now().UnixNano() + tmplName := fmt.Sprintf("e2e-hostname-%d", suffix) + holderName := fmt.Sprintf("e2e-gs-hostname-holder-%d", suffix) + contenderName := fmt.Sprintf("e2e-gs-hostname-contender-%d", suffix) + hostname := holderName + ".games.example.com" + + applyBusyboxTemplate(t, tmplName) + + createServer := func(name string, networking map[string]any) { + t.Helper() + gs := &unstructured.Unstructured{Object: map[string]any{ + "apiVersion": "gameplane.local/v1alpha1", + "kind": "GameServer", + "metadata": map[string]any{"name": name, "namespace": ns}, + "spec": map[string]any{ + "templateRef": map[string]any{"name": tmplName}, + "networking": networking, + }, + }} + if _, err := envInstance.Dyn.Resource(gameServerGVR).Namespace(ns). + Create(ctx, gs, metav1.CreateOptions{}); err != nil && !apierrors.IsAlreadyExists(err) { + t.Fatalf("create gameserver %s: %v", name, err) + } + t.Cleanup(func() { + _ = envInstance.Dyn.Resource(gameServerGVR).Namespace(ns). + Delete(context.WithoutCancel(ctx), name, metav1.DeleteOptions{}) + }) + } + + // Step 1: the holder gets an address from the pool and advertises its + // hostname, keeping the address as serviceAddress. + createServer(holderName, map[string]any{ + "expose": "LoadBalancer", + "addressPool": "pool-us-west", + "hostname": hostname, + }) + var heldAddr string + envInstance.Eventually(t, 120*time.Second, func() (bool, string) { + svc, err := envInstance.K8s.CoreV1().Services(ns).Get(ctx, holderName, metav1.GetOptions{}) + if err != nil { + return false, "get holder service: " + err.Error() + } + if len(svc.Status.LoadBalancer.Ingress) == 0 || svc.Status.LoadBalancer.Ingress[0].IP == "" { + return false, "holder service has no load-balancer IP yet" + } + lbIP := svc.Status.LoadBalancer.Ingress[0].IP + + got, err := envInstance.Dyn.Resource(gameServerGVR).Namespace(ns). + Get(ctx, holderName, metav1.GetOptions{}) + if err != nil { + return false, "get holder gameserver: " + err.Error() + } + endpoints, _, _ := unstructured.NestedSlice(got.Object, "status", "endpoints") + if len(endpoints) == 0 { + return false, "holder has no endpoints" + } + for i, epIface := range endpoints { + ep, ok := epIface.(map[string]any) + if !ok { + return false, fmt.Sprintf("endpoints[%d] malformed", i) + } + if host, _ := ep["host"].(string); host != hostname { + return false, fmt.Sprintf("endpoints[%d].host = %q, want the hostname %q", i, host, hostname) + } + if addr, _ := ep["serviceAddress"].(string); addr != lbIP { + return false, fmt.Sprintf("endpoints[%d].serviceAddress = %q, want the load-balancer IP %q", i, addr, lbIP) + } + } + heldAddr = lbIP + return true, "" + }) + if net.ParseIP(heldAddr) == nil { + t.Fatalf("held address %q is not an IP", heldAddr) + } + + // Step 2: a second server asks for the holder's IP and must be refused, + // with the holder named. + createServer(contenderName, map[string]any{ + "expose": "LoadBalancer", + "addressPool": "pool-us-west", + "address": heldAddr, + }) + envInstance.Eventually(t, 60*time.Second, func() (bool, string) { + got, err := envInstance.Dyn.Resource(gameServerGVR).Namespace(ns). + Get(ctx, contenderName, metav1.GetOptions{}) + if err != nil { + return false, "get contender gameserver: " + err.Error() + } + cond := findCondition(got.Object, "AddressAssignment") + if cond == nil { + return false, "contender AddressAssignment condition not found" + } + reason, _ := cond["reason"].(string) + status, _ := cond["status"].(string) + message, _ := cond["message"].(string) + if status != "False" || reason != "AddressInUse" { + return false, fmt.Sprintf("contender status=%q reason=%q, want False/AddressInUse", status, reason) + } + if !strings.Contains(message, holderName) { + return false, fmt.Sprintf("message=%q does not name the holder %q", message, holderName) + } + return true, "" + }) +} diff --git a/web/src/types.ts b/web/src/types.ts index 64a80e37b..bf7fa96bd 100644 --- a/web/src/types.ts +++ b/web/src/types.ts @@ -548,7 +548,10 @@ export interface InlineBackupPolicy { export interface GameServerEndpoint { name: string; + // The address players connect to: the Service's, or the server's hostname. host: string; + // The address the Service was assigned, when host is an advertised hostname. + serviceAddress?: string; port: number; protocol?: string; // Tailscale endpoints are tailnet-private only, not reachable from the internet. From 8a840d5a3f38081df5d028489e6552f26d600951 Mon Sep 17 00:00:00 2001 From: Ben Fulton Date: Tue, 17 Nov 2026 19:40:18 -0500 Subject: [PATCH 4/4] docs(changelog): mark the hostname endpoint change as breaking Co-Authored-By: Claude Opus 5.5 Signed-off-by: Ben Fulton --- changelog/unreleased/999-hostname-endpoint.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/unreleased/999-hostname-endpoint.md b/changelog/unreleased/999-hostname-endpoint.md index 30d8ea618..c20a2de4e 100644 --- a/changelog/unreleased/999-hostname-endpoint.md +++ b/changelog/unreleased/999-hostname-endpoint.md @@ -1,4 +1,4 @@ -# LoadBalancer servers show their hostname as their address +# Breaking: LoadBalancer servers show their hostname as their address After upgrading, every LoadBalancer server that already has `spec.networking.hostname` set reports that hostname as its address in