envapi

package
v0.0.0-...-58535fa Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchGameServerPods

func FetchGameServerPods(ctx context.Context, kubeCli *KubeClient) ([]corev1.Pod, error)

FetchGameServerPods retrieves pods with a specific label selector in a namespace. If (optional) shardSets is specified, only return pods owned by said stateful set. Otherwise, all pods are returned. \todo Figure out how to handle multi-region gameservers

func NewDockerClient

func NewDockerClient() (*client.Client, error)

newDockerClient creates a new Docker client with a verified connection. It first tries the default connection mechanism (via environment variables or default socket). If that fails on macOS, it attempts to connect to the Docker Desktop socket as a fallback.

Types

type AWSCredentials

type AWSCredentials struct {
	Version         int    `json:"Version"`
	AccessKeyID     string `json:"AccessKeyId"`
	SecretAccessKey string `json:"SecretAccessKey"`
	SessionToken    string `json:"SessionToken"`
	Expiration      string `json:"Expiration"`
}

Container for AWS access credentials into the target environment. The JSON names match those used by AWS.

type Deployment

type Deployment struct {
	AdminHostname            string `json:"admin_hostname"`
	AdminTLSCert             string `json:"admin_tls_cert"`
	AwsRegion                string `json:"aws_region"`
	CdnDistributionArn       string `json:"cdn_distribution_arn"`
	CdnDistributionID        string `json:"cdn_distribution_id"`
	CdnS3Fqdn                string `json:"cdn_s3_fqdn"`
	EcrRepo                  string `json:"ecr_repo"`
	GameserverAdminIamRole   string `json:"gameserver_admin_iam_role"`
	GameserverIamRole        string `json:"gameserver_iam_role"`
	GameserverServiceAccount string `json:"gameserver_service_account"`
	KubernetesNamespace      string `json:"kubernetes_namespace"`
	MetaplayInfraVersion     string `json:"metaplay_infra_version"`
	S3BucketPrivate          string `json:"s3_bucket_private"`
	S3BucketPublic           string `json:"s3_bucket_public"`
	ServerHostname           string `json:"server_hostname"`
	ServerPorts              []int  `json:"server_ports"`
	ServerTLSCert            string `json:"server_tls_cert"`
}

type DeploymentSecret

type DeploymentSecret struct {
	Deployment    Deployment    `json:"deployment"`
	Format        string        `json:"format"`
	OAuth2Client  OAuth2Client  `json:"oauth2_client"`
	Observability Observability `json:"observability"`
	Type          string        `json:"type"`
}

Kubernetes secret `metaplay-deployment` field 'deployment'.

type DockerCredentials

type DockerCredentials struct {
	Username    string
	Password    string
	RegistryURL string
}

Container for access information to an environment's docker registry.

type GameServerPodPhase

type GameServerPodPhase string

\todo is there an official k8s type for this?

const (
	PhaseReady   GameServerPodPhase = "Ready"
	PhaseRunning GameServerPodPhase = "Running"
	PhasePending GameServerPodPhase = "Pending"
	PhaseUnknown GameServerPodPhase = "Unknown"
	PhaseFailed  GameServerPodPhase = "Failed"
)

type GameServerPodStatus

type GameServerPodStatus struct {
	Phase   GameServerPodPhase `json:"phase"`
	Message string             `json:"message"`
	Details any                `json:"details,omitempty"`
}

type KubeClient

type KubeClient struct {
	Namespace     string // Kubernetes namespace
	KubeConfig    string // Kubeconfig with embedded credentials
	RestConfig    *rest.Config
	RestClient    *rest.RESTClient
	Clientset     *kubernetes.Clientset
	DynamicClient *dynamic.DynamicClient
}

Kubernetes client that wraps all the various Kubernetes client configs and client types into one struct for convenient use.

type KubeConfig

type KubeConfig struct {
	ApiVersion     string              `yaml:"apiVersion"`
	Clusters       []KubeConfigCluster `yaml:"clusters"`
	Contexts       []KubeConfigContext `yaml:"contexts"`
	CurrentContext string              `yaml:"current-context"`
	Kind           string              `yaml:"kind"`
	Preferences    map[string]any      `yaml:"preferences"`
	Users          []KubeConfigUser    `yaml:"users"`
}

type KubeConfigCluster

type KubeConfigCluster struct {
	Cluster KubeConfigClusterData `yaml:"cluster"`
	Name    string                `yaml:"name"`
}

type KubeConfigClusterData

type KubeConfigClusterData struct {
	CertificateAuthorityData string `yaml:"certificate-authority-data"`
	Server                   string `yaml:"server"`
}

type KubeConfigContext

type KubeConfigContext struct {
	Context KubeConfigContextData `yaml:"context"`
	Name    string                `yaml:"name"`
}

type KubeConfigContextData

type KubeConfigContextData struct {
	Cluster   string `yaml:"cluster"`
	User      string `yaml:"user"`
	Namespace string `yaml:"namespace"`
}

type KubeConfigUser

type KubeConfigUser struct {
	Name string             `yaml:"name"`
	User KubeConfigUserData `yaml:"user"`
}

type KubeConfigUserData

type KubeConfigUserData struct {
	Token string                 `yaml:"token"`
	Exec  KubeConfigUserDataExec `yaml:"exec"`
}

type KubeConfigUserDataExec

type KubeConfigUserDataExec struct {
	Command         string   `yaml:"command"`
	Args            []string `yaml:"args"`
	ApiVersion      string   `yaml:"apiVersion"`
	InteractiveMode string   `yaml:"interactiveMode"`
}

type KubeExecCredential

type KubeExecCredential struct {
	ApiVersion string                                    `json:"apiVersion"`
	Kind       string                                    `json:"kind"`
	Spec       clientauthentication.ExecCredentialSpec   `json:"spec"`
	Status     clientauthentication.ExecCredentialStatus `json:"status"`
}

type MetaplayImageInfo

type MetaplayImageInfo struct {
	ImageID      string    // Docker image ID
	Name         string    // Image name (generally project ID for local projects), empty for remote projects.
	RepoTag      string    // Eg, 'lovely-wombats-build:12345678'.
	Tag          string    // Image tag (eg, Git hash).
	ProjectID    string    // Project human ID (label io.metaplay.project_id).
	SdkVersion   string    // Metaplay SDK version (label io.metaplay.sdk_version).
	CommitID     string    // Commit ID, e.g., git hash (label io.metaplay.commit_id).
	BuildNumber  string    // Build number (label io.metaplay.build_number).
	CreatedTime  time.Time // Image creation timestamp.
	OS           string    // OS the image is built for (e.g., "linux") - can be added if needed elsewhere
	Architecture string    // Architecture the image is built for (e.g., "amd64") - can be added if needed elsewhere
}

Metadata about a Metaplay docker image.

func FetchRemoteDockerImageMetadata

func FetchRemoteDockerImageMetadata(creds *DockerCredentials, imageRef string) (*MetaplayImageInfo, error)

FetchRemoteDockerImageMetadata retrieves the labels of an image in a remote Docker registry.

func ReadLocalDockerImageMetadata

func ReadLocalDockerImageMetadata(imageRefString string) (*MetaplayImageInfo, error)

ReadLocalDockerImageMetadata retrieves metadata from a local Docker image.

func ReadLocalDockerImagesByProjectID

func ReadLocalDockerImagesByProjectID(projectID string) ([]MetaplayImageInfo, error)

ReadLocalDockerImagesByProjectID retrieves metadata for all local Docker images that have the 'io.metaplay.project_id' label matching the provided projectID. The images are returned in a timestamp order, latest first (highest timestamp first).

type NewGameServerCR

type NewGameServerCR struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec struct {
		Config struct {
			EnvVars             []corev1.EnvVar `json:"envVars,omitempty"`
			RuntimeOptionsFiles []string        `json:"runtimeOptionsFiles,omitempty"`
			SecretRefs          []struct {
				Name    string `json:"name,omitempty"`
				KeyRefs []struct {
					Key string `json:"key,omitempty"`
				} `json:"keyRef,omitempty"`
			} `json:"secretRefs,omitempty"`
		} `json:"config,omitempty"`

		EnvironmentFamily string `json:"environmentFamily,omitempty"`

		Image struct {
			PullPolicy corev1.PullPolicy `json:"pullPolicy,omitempty"`
			Repository string            `json:"repository,omitempty"`
			Tag        string            `json:"tag,omitempty"`
		} `json:"image,omitempty"`

		Shards []struct {
			ClusterLabelSelector map[string]string `json:"clusterLabelSelector,omitempty"`
			MaxNodeCount         *int              `json:"maxNodeCount,omitempty"`
			MinNodeCount         *int              `json:"minNodeCount,omitempty"`
			Name                 string            `json:"name,omitempty"`
			PodTemplate          struct {
				ContainerTemplate struct {
					ExtraPorts []corev1.ContainerPort      `json:"extraPorts,omitempty"`
					Resources  corev1.ResourceRequirements `json:"resources,omitempty"`
				} `json:"containerTemplate,omitempty"`
			} `json:"podTemplate,omitempty"`
			Public     bool   `json:"public,omitempty"`
			Scaling    string `json:"scaling,omitempty"`
			Connection bool   `json:"connection,omitempty"`
			Admin      bool   `json:"admin,omitempty"`
			NodeCount  *int   `json:"nodeCount,omitempty"`
		} `json:"shards,omitempty"`
	} `json:"spec,omitempty"`

	Status struct {
		NodeSetConfigs []struct {
			GlobalSuffix string   `json:"globalSuffix,omitempty"`
			MaxNodeCount *int     `json:"maxNodeCount,omitempty"`
			MinNodeCount *int     `json:"minNodeCount,omitempty"`
			Name         string   `json:"name,omitempty"`
			Public       bool     `json:"public,omitempty"`
			Scaling      string   `json:"scaling,omitempty"`
			Connection   bool     `json:"connection,omitempty"`
			AdminAPI     bool     `json:"adminApi,omitempty"`
			EntityKinds  []string `json:"entityKinds,omitempty"`
			NodeCount    *int     `json:"nodeCount,omitempty"`
		} `json:"nodeSetConfigs,omitempty"`

		Phase  string `json:"phase,omitempty"`
		Shards map[string]struct {
			ClusterName  string `json:"clusterName,omitempty"`
			GlobalSuffix string `json:"globalSuffix,omitempty"`
		} `json:"shards,omitempty"`
	} `json:"status,omitempty"`
}

NewGameServerCR represents the structured CRD for the new operator GameServer.

type OAuth2Client

type OAuth2Client struct {
	AuthProvider      string   `json:"auth_provider"`
	Audience          string   `json:"audience"`
	ClientID          string   `json:"client_id"`
	ClientSecret      string   `json:"client_secret"`
	Domain            string   `json:"domain"`
	EmailDomain       string   `json:"email_domain"`
	Issuer            string   `json:"issuer"`
	LogoutRedirectUri string   `json:"logout_redirect_uri"`
	RolesClaim        string   `json:"roles_claim"`
	RolePrefix        string   `json:"role_prefix"`
	LocalCallback     string   `json:"local_callback"`
	AdditionalScopes  []string `json:"additional_scopes"`
}

type Observability

type Observability struct {
	LokiEndpoint       string `json:"loki_endpoint"`
	LokiPassword       string `json:"loki_password"`
	LokiUsername       string `json:"loki_username"`
	PrometheusEndpoint string `json:"prometheus_endpoint"`
	PrometheusPassword string `json:"prometheus_password"`
	PrometheusUsername string `json:"prometheus_username"`
}

type OldGameServerCR

type OldGameServerCR struct {
	APIVersion string            `json:"apiVersion"`
	Kind       string            `json:"kind"`
	Metadata   metav1.ObjectMeta `json:"metadata"`
	Spec       struct {
		DedicatedShardNodes bool               `json:"dedicatedShardNodes"`
		ServiceSpec         corev1.ServiceSpec `json:"serviceSpec"`
		ShardSpec           []struct {
			Name        string                      `json:"name"`
			NodeCount   int                         `json:"nodeCount"`
			EntityKinds []string                    `json:"entityKinds"`
			Requests    corev1.ResourceRequirements `json:"requests"`
		} `json:"shardSpec"`
		StatefulSetSpec appsv1.StatefulSetSpec `json:"statefulSetSpec"`
	} `json:"spec"`
	Status struct {
		Phase             string   `json:"phase"`
		ShardConfigMap    string   `json:"shardConfigMap"`
		ShardServices     []string `json:"shardServices"`
		ShardStatefulSets []string `json:"shardStatefulSets"`
	} `json:"status"`
}

OldGameServerCR represents the structured CRD for the old operator GameServer.

type ShardSetWithPods

type ShardSetWithPods struct {
	ShardSet *TargetShardSet // ShardSet spec.
	Pods     []corev1.Pod    // Pods belonging to this shardSet.
}

Result of fetching all shardSets including their pods from all the clusters.

type TargetCluster

type TargetCluster struct {
	KubeClient *KubeClient // Kubernetes client(s) to access target cluster.

}

Wrapper for accessing each cluster associated with the game server deployment.

type TargetEnvironment

type TargetEnvironment struct {
	TokenSet        *auth.TokenSet   // Tokens to use to access the environment.
	StackApiBaseURL string           // Base URL of the StackAPI, eg, 'https://infra.<stack>/stackapi'
	HumanID         string           // Environment human ID, eg, 'tiny-squids'. Same as Kubernetes namespace.
	StackApiClient  *metahttp.Client // HTTP client to access environment StackAPI.
	// contains filtered or unexported fields
}

Wrapper object for accessing an environment within a target stack.

func NewTargetEnvironment

func NewTargetEnvironment(tokenSet *auth.TokenSet, stackDomain, humanID string) *TargetEnvironment

func (*TargetEnvironment) CreateSecret

func (targetEnv *TargetEnvironment) CreateSecret(ctx context.Context, name string, payloadValues map[string][]byte) error

func (*TargetEnvironment) DeleteSecret

func (targetEnv *TargetEnvironment) DeleteSecret(ctx context.Context, name string) error

DeleteSecret deletes a Kubernetes secret with the given name

func (*TargetEnvironment) GetAWSCredentials

func (target *TargetEnvironment) GetAWSCredentials() (*AWSCredentials, error)

Get AWS credentials against the target environment. \todo migrate this into StackAPI -- AWS creds should not be given to the client

func (*TargetEnvironment) GetDetails

func (target *TargetEnvironment) GetDetails() (*DeploymentSecret, error)

Request details about an environment from the StackAPI.

func (*TargetEnvironment) GetDockerCredentials

func (target *TargetEnvironment) GetDockerCredentials(envDetails *DeploymentSecret) (*DockerCredentials, error)

Get Docker credentials for the environment's docker registry.

func (*TargetEnvironment) GetGameServer

func (target *TargetEnvironment) GetGameServer(ctx context.Context) (*TargetGameServer, error)

Get the accessor to the gameserver resource in this environment.

func (*TargetEnvironment) GetKubeConfigWithEmbeddedCredentials

func (target *TargetEnvironment) GetKubeConfigWithEmbeddedCredentials() (string, error)

Get a short-lived kubeconfig with the access credentials embedded in the kubeconfig file.

func (*TargetEnvironment) GetKubeConfigWithExecCredential

func (target *TargetEnvironment) GetKubeConfigWithExecCredential(userID string) (string, error)

* * Get a `kubeconfig` payload which invokes `metaplay-auth get-kubernetes-execcredential` to get the actual * access credentials each time the kubeconfig is used. * @param userID Any identity for the user, stored in the kubeconfig but not used otherwise. * @returns The kubeconfig YAML.

func (*TargetEnvironment) GetKubeExecCredential

func (target *TargetEnvironment) GetKubeExecCredential() (*string, error)

Get the Kubernetes credentials in the execcredential format

func (*TargetEnvironment) GetKubernetesNamespace

func (target *TargetEnvironment) GetKubernetesNamespace() string

func (*TargetEnvironment) GetPrimaryKubeClient

func (target *TargetEnvironment) GetPrimaryKubeClient() (*KubeClient, error)

Get a Kubernetes client for the primary cluster.

func (*TargetEnvironment) GetSecret

func (targetEnv *TargetEnvironment) GetSecret(ctx context.Context, name string) (*corev1.Secret, error)

GetSecret retrieves a Kubernetes secret by name

func (*TargetEnvironment) ListSecrets

func (targetEnv *TargetEnvironment) ListSecrets(ctx context.Context) ([]corev1.Secret, error)

ListSecrets lists all Kubernetes secrets with the user secret label. If no secrets exist, an empty list is returned.

func (*TargetEnvironment) WaitForServerToBeReady

func (targetEnv *TargetEnvironment) WaitForServerToBeReady(ctx context.Context, taskRunner *tui.TaskRunner) error

type TargetGameServer

type TargetGameServer struct {
	Namespace       string           // Kubernetes namespace.
	GameServerNewCR *NewGameServerCR // GameServer CR for new operator.
	GameServerOldCR *OldGameServerCR // GameServer CR for old operator.
	KubeCli         *KubeClient      // Kubernetes clients for the primary cluster.
	Clusters        []TargetCluster  // All clusters associated with the environment (primary and edge clusters).
	ShardSets       []TargetShardSet // ShardSets belonging to the game server.
}

Wrapper for a (single or multi-cluster) gameserver CR in an environment.

func (*TargetGameServer) GetAllShardSetsWithPods

func (gs *TargetGameServer) GetAllShardSetsWithPods() ([]ShardSetWithPods, error)

Get all shardSets across all gameserver clusters and their asscoiated pods.

func (*TargetGameServer) GetPod

func (gs *TargetGameServer) GetPod(podName string) (*KubeClient, *corev1.Pod, error)

Find a gameserver pod with the given name.

func (*TargetGameServer) GetShardSetWithPods

func (gs *TargetGameServer) GetShardSetWithPods(shardSetName string) (*ShardSetWithPods, error)

Get the shardSet with given name. Can be on any cluster.

type TargetShardSet

type TargetShardSet struct {
	Name    string         // Name of the shardSet, also prefix for the pod names.
	Cluster *TargetCluster // Cluster on which the shard set resides on.

}

Jump to

Keyboard shortcuts

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