controllers

package
v0.0.0-...-ef787ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2021 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActiveServerStatus       = "active"
	StandingByServerStatus   = "standingby"
	InitializingServerStatus = "initializing"
	PendingServerStatus      = "pending"
)
View Source
const (
	InitContainerName = "initcontainer"

	GameServerKind      = "GameServer"
	GameServerBuildKind = "GameServerBuild"

	DataVolumeName      = "data"
	DataVolumeMountPath = "/data"

	// MinPort is minimum Port Number
	MinPort int32 = 10000
	// MaxPort is maximum Port Number
	MaxPort int32 = 50000

	RandStringSize = 5

	LabelBuildID          = "BuildID"
	LabelBuildName        = "BuildName"
	LabelOwningGameServer = "OwningGameServer"
	LabelOwningOperator   = "OwningOperator"
	LabelNodeName         = "NodeName"

	GsdkConfigFile             = "/data/Config/gsdkConfig.json"
	LogDirectory               = "/data/GameLogs/"
	CertificatesDirectory      = "/data/GameCertificates"
	GameSharedContentDirectory = "/data/GameSharedContent"

	DaemonSetPort int32 = 56001
)

Variables

View Source
var (
	GameServersCreatedCounter = registry.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "thundernetes",
			Name:      "gameservers_created_total",
			Help:      "Number of GameServers created",
		},
		[]string{"BuildName"},
	)
	GameServersSessionEndedCounter = registry.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "thundernetes",
			Name:      "gameservers_sessionended_total",
			Help:      "Number of GameServer sessions ended",
		},
		[]string{"BuildName"},
	)
	GameServersCrashedCounter = registry.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "thundernetes",
			Name:      "gameservers_crashed_total",
			Help:      "Number of GameServers sessions crashed",
		},
		[]string{"BuildName"},
	)
	GameServersDeletedCounter = registry.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "thundernetes",
			Name:      "gameservers_deleted_total",
			Help:      "Number of GameServers deleted",
		},
		[]string{"BuildName"},
	)
	CurrentGameServerGauge = registry.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: "thundernetes",
			Name:      "gameservers_current_state",
			Help:      "Gameserver gauges by state",
		},
		[]string{"BuildName", "state"},
	)
	AllocationsCounter = registry.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "thundernetes",
			Name:      "allocations_total",
			Help:      "Number of GameServers allocations",
		},
		[]string{"BuildName"},
	)
)
View Source
var InitContainerImage string

Functions

func GetPublicIPForNode

func GetPublicIPForNode(ctx context.Context, r client.Reader, nodeName string) (string, error)

GetPublicIPForNode returns the Public IP of the node if the Node does not have a Public IP, method returns the internal one

func NewGameServerForGameServerBuild

func NewGameServerForGameServerBuild(gsb *mpsv1alpha1.GameServerBuild, portRegistry *PortRegistry) (*mpsv1alpha1.GameServer, error)

NewGameServerForGameServerBuild creates a GameServer for a GameServerBuild

func NewPodForGameServer

func NewPodForGameServer(gs *mpsv1alpha1.GameServer) *corev1.Pod

NewPodForGameServer returns a Kubernetes Pod struct for a specified GameServer Pod has the same name as the GameServer It also sets a label called "GameServer" with the value of the corresponding GameServer resource

Types

type GameServerBuildReconciler

type GameServerBuildReconciler struct {
	client.Client
	Scheme       *runtime.Scheme
	PortRegistry *PortRegistry
	Recorder     record.EventRecorder
}

GameServerBuildReconciler reconciles a GameServerBuild object

func (*GameServerBuildReconciler) Reconcile

Reconcile is part of the main kubernetes reconciliation loop which aims to move the current state of the cluster closer to the desired state. For more details, check Reconcile and its Result here: - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.8.3/pkg/reconcile

func (*GameServerBuildReconciler) SetupWithManager

func (r *GameServerBuildReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

type GameServerReconciler

type GameServerReconciler struct {
	client.Client
	Scheme                     *runtime.Scheme
	Recorder                   record.EventRecorder
	PortRegistry               *PortRegistry
	GetPublicIpForNodeProvider func(ctx context.Context, r client.Reader, nodeName string) (string, error) // we abstract this for testing purposes
}

GameServerReconciler reconciles a GameServer object

func (*GameServerReconciler) Reconcile

func (r *GameServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile is part of the main kubernetes reconciliation loop which aims to move the current state of the cluster closer to the desired state. For more details, check Reconcile and its Result here: - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.8.3/pkg/reconcile

func (*GameServerReconciler) SetupWithManager

func (r *GameServerReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

type PortRegistry

type PortRegistry struct {
	HostPorts         map[int32]bool
	Indexes           []int32
	NextFreePortIndex int32
	Min               int32 // Minimum Port
	Max               int32 // Maximum Port
	// contains filtered or unexported fields
}

PortRegistry implements a custom map for the port registry

func NewPortRegistry

func NewPortRegistry(gameServers mpsv1alpha1.GameServerList, min, max int32, setupLog logr.Logger) (*PortRegistry, error)

NewPortRegistry initializes the IndexedDictionary that holds the port registry.

func (*PortRegistry) DeregisterServerPorts

func (pr *PortRegistry) DeregisterServerPorts(ports []int32)

DeregisterServerPorts deregisters all host ports so they can be re-used by additional game servers

func (*PortRegistry) GetNewPort

func (pr *PortRegistry) GetNewPort() (int32, error)

GetNewPort returns and registers a new port for the designated game server. Locks a mutex

func (*PortRegistry) Stop

func (pr *PortRegistry) Stop()

Stop stops port registry mechanism by closing requests and responses channels

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL