shared

package
v0.0.0-...-af0835f Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DedicatedGameServerKind = "DedicatedGameServer"
	GameNamespace           = "default"

	// MinPort is minimum Port Number
	MinPort int32 = 20000
	// MaxPort is maximum Port Number
	MaxPort int32 = 30000

	RandStringSize = 5
)
View Source
const (
	LabelIsDedicatedGameServer                     = "IsDedicatedGameServer"
	LabelDedicatedGameServerName                   = "DedicatedGameServerName"
	LabelDedicatedGameServerCollectionName         = "DedicatedGameServerCollectionName"
	LabelOriginalDedicatedGameServerCollectionName = "OriginalDedicatedGameServerCollectionName"
)
View Source
const (
	// SuccessSynced is used as part of the Event 'reason' when a CRD is synced
	SuccessSynced = "Synced"
	// ErrResourceExists is used as part of the Event 'reason' when a CRD fails
	// to sync due to a Deployment of the same name already existing.
	ErrResourceExists = "ErrResourceExists"

	// MessageResourceExists is the message used for Events when a resource
	// fails to sync due to a Deployment already existing
	MessageResourceExists = "Resource %q already exists and is not managed by CRD"
	// MessageResourceSynced is the message used for an Event fired when a resource
	// is synced successfully
	MessageResourceSynced = "%s with name %s synced successfully"

	DedicatedGameServerReplicasChanged = "Dedicated Game Server Replicas Changed"

	MessageReplicasDecreased = "%s with name %s decreased by %d replicas successfully"
	MessageReplicasIncreased = "%s with name %s increased by %d replicas successfully"

	MessageMarkedForDeletionDedicatedGameServerDeleted = "Dedicated Game Server %s that was MarkedForDeletion with 0 Active Players was deleted"
	MessageAutoscalingNotConfigured                    = "Autoscaling is not configured for DedicatedGameServerCollection %s"
)
View Source
const APIAccessCodeSecretName = "apiaccesscode"
View Source
const (
	APIServerURL = "http://aks-gaming-apiserver.dgs-system.svc.cluster.local"
)

make sure to change the host values if the K8s service name for the API Server is changed

Variables

This section is empty.

Functions

func AreMapsSame

func AreMapsSame(map1, map2 map[string]string) bool

AreMapsSame compares two map[string]string objects

func AuthenticateWebServerCode

func AuthenticateWebServerCode(code string) (bool, error)

AuthenticateWebServerCode authenticates the user request by comparing the given code with the actual

func GetAccessCode

func GetAccessCode(client kubernetes.Interface) (string, error)

func GetClientSet

GetClientSet returns a Kubernetes interface object that will allow us to give commands to the K8s API

func GetRandomIndexes

func GetRandomIndexes(length int, count int) []int

GetRandomIndexes will return *count* random integers from a hypothetical slice of *length* For example, think that we want to take two random indexes from a length-five slice

func GetRandomInt

func GetRandomInt(min int, max int) int

GetRandomInt returns a random number

func GetReadyDGSs

func GetReadyDGSs() ([]dgsv1alpha1.DedicatedGameServer, error)

GetReadyDGSs returns a list of DGS that are "PodRunning", "Healthy" and not "MarkedForDeletion"

func Logger

func Logger() *logrus.Logger

Logger returns a default Logger

func NewDedicatedGameServer

NewDedicatedGameServer returns a new DedicatedGameServer object that belongs to the specified DedicatedGameServerCollection and has the designated PodSpec

func NewDedicatedGameServerCollection

func NewDedicatedGameServerCollection(name string, namespace string, replicas int32, template corev1.PodSpec) *dgsv1alpha1.DedicatedGameServerCollection

NewDedicatedGameServerCollection creates a new DedicatedGameServerCollection with the specified parameters Initial state is DGSHealth: creating, DGSState: Idle and PodPhase: pending

func NewDedicatedGameServerWithNoParent

func NewDedicatedGameServerWithNoParent(namespace string, name string, template corev1.PodSpec, portsToExpose []int32) *dgsv1alpha1.DedicatedGameServer

NewDedicatedGameServerWithNoParent creates a new DedicatedGameServer that is not part of a DedicatedGameServerCollection

func NewPod

func NewPod(dgs *dgsv1alpha1.DedicatedGameServer, apiDetails APIDetails) *corev1.Pod

NewPod returns a Kubernetes Pod struct It also sets a label called "DedicatedGameServer" with the value of the corresponding DedicatedGameServer resource

func SliceContains

func SliceContains(slice []int32, value int32) bool

SliceContains returns true if the specific int32 value is contained in the slice

func UpdateActivePlayers

func UpdateActivePlayers(serverName string, namespace string, activePlayers int) error

UpdateActivePlayers updates the active players count for the server with name serverName

func UpdateDGSStatus

func UpdateDGSStatus(serverName string, namespace string, fields DGSStatusFields) error

func UpdateGameServerHealth

func UpdateGameServerHealth(serverName string, namespace string, serverHealth dgsv1alpha1.DGSHealth) error

UpdateGameServerHealth updates the DedicatedGameServer with the serverName health

func UpdateGameServerMarkedForDeletion

func UpdateGameServerMarkedForDeletion(serverName string, namespace string, markedForDeletion bool) error

func UpdateGameServerState

func UpdateGameServerState(serverName string, namespace string, serverState dgsv1alpha1.DGSState) error

UpdateGameServerState updates the DedicatedGameServer with the serverName state

Types

type APIDetails

type APIDetails struct {
	APIServerURL string
	Code         string
}

APIDetails contains the information that allows our DedicatedGameServer to communicate with the API Server

type DGSStatusFields

type DGSStatusFields struct {
	MarkedForDeletion *bool
	DGSHealth         *dgsv1alpha1.DGSHealth
	DGSState          *dgsv1alpha1.DGSState
	ActivePlayers     *int
}

Jump to

Keyboard shortcuts

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