Skip to content

Commit

Permalink
chore: add statusport to gameservers tatus
Browse files Browse the repository at this point in the history
  • Loading branch information
rudoi committed Jul 11, 2024
1 parent 93bf7c4 commit bd8cc33
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/gameserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type GameServerStatus struct {
// NetImguiPort represents the port on which the underlying pod is listening for netimgui traffic
NetImguiPort int32 `json:"netimguiPort,omitempty"`

// Status port represents the port on which the game server is serving game/session status information
StatusPort int32 `json:"statusPort,omitempty"`

// PodRef refers to the name of the Pod backing the GameServer
PodRef *corev1.LocalObjectReference `json:"podRef,omitempty"`
}
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/game.believer.dev_gameservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ spec:
is listening for game traffic
format: int32
type: integer
statusPort:
description: Status port represents the port on which the game server
is serving game/session status information
format: int32
type: integer
type: object
type: object
served: true
Expand Down
21 changes: 15 additions & 6 deletions internal/controller/gameserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,21 @@ func (r *GameServerReconciler) reconcilePod(ctx context.Context, gameServer *gam
return ctrl.Result{Requeue: true}, nil
}

if gameServer.Status.Port != pod.Spec.Containers[0].Ports[0].HostPort {
gameServer.Status.Port = pod.Spec.Containers[0].Ports[0].HostPort
}

if gameServer.Status.NetImguiPort != pod.Spec.Containers[0].Ports[1].HostPort {
gameServer.Status.NetImguiPort = pod.Spec.Containers[0].Ports[1].HostPort
// iterate over the ports
for _, port := range pod.Spec.Containers[0].Ports {
if port.Name == "game" {
if gameServer.Status.Port != port.ContainerPort {
gameServer.Status.Port = port.ContainerPort
}
} else if port.Name == "netimgui" {
if gameServer.Status.NetImguiPort != port.ContainerPort {
gameServer.Status.NetImguiPort = port.ContainerPort
}
} else if port.Name == "status" {
if gameServer.Status.StatusPort != port.ContainerPort {
gameServer.Status.StatusPort = port.ContainerPort
}
}
}

// requeue until we've got a node
Expand Down

0 comments on commit bd8cc33

Please sign in to comment.