Skip to content

Commit

Permalink
changing gs.Spec.PodSpec to PodTemplateSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios committed Jan 7, 2022
1 parent e3eddd2 commit 1f46184
Show file tree
Hide file tree
Showing 26 changed files with 12,299 additions and 11,629 deletions.
110 changes: 59 additions & 51 deletions cmd/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,18 @@ func main() {
},
StandingBy: 2,
Max: 4,
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: imgName,
Name: "netcore-sample",
ImagePullPolicy: corev1.PullIfNotPresent,
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: imgName,
Name: "netcore-sample",
ImagePullPolicy: corev1.PullIfNotPresent,
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
},
},
},
},
Expand All @@ -148,22 +150,24 @@ func main() {
PortsToExpose: []mpsv1alpha1.PortToExpose{{ContainerName: "netcore-sample", PortName: portKey}},
StandingBy: 2,
Max: 4,
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: imgName,
Name: "netcore-sample",
ImagePullPolicy: corev1.PullIfNotPresent,
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: imgName,
Name: "netcore-sample",
ImagePullPolicy: corev1.PullIfNotPresent,
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
},
},
},
Env: []corev1.EnvVar{
{
Name: "SLEEP_BEFORE_READY_FOR_PLAYERS",
Value: "true",
Env: []corev1.EnvVar{
{
Name: "SLEEP_BEFORE_READY_FOR_PLAYERS",
Value: "true",
},
},
},
},
Expand All @@ -184,17 +188,19 @@ func main() {
PortsToExpose: []mpsv1alpha1.PortToExpose{{ContainerName: "netcore-sample", PortName: portKey}},
StandingBy: 2,
Max: 4,
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: imgName,
Name: "netcore-sample",
ImagePullPolicy: corev1.PullIfNotPresent,
Command: []string{"/bin/sh", "-c", "sleep 2 && command_that_does_not_exist"},
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: imgName,
Name: "netcore-sample",
ImagePullPolicy: corev1.PullIfNotPresent,
Command: []string{"/bin/sh", "-c", "sleep 2 && command_that_does_not_exist"},
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
},
},
},
},
Expand All @@ -215,22 +221,24 @@ func main() {
PortsToExpose: []mpsv1alpha1.PortToExpose{{ContainerName: "netcore-sample", PortName: portKey}},
StandingBy: 2,
Max: 4,
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: imgName,
Name: "netcore-sample",
ImagePullPolicy: corev1.PullIfNotPresent,
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: imgName,
Name: "netcore-sample",
ImagePullPolicy: corev1.PullIfNotPresent,
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
},
},
},
Env: []corev1.EnvVar{
{
Name: "SKIP_READY_FOR_PLAYERS",
Value: "true",
Env: []corev1.EnvVar{
{
Name: "SKIP_READY_FOR_PLAYERS",
Value: "true",
},
},
},
},
Expand Down
27 changes: 14 additions & 13 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ By default, Pods are scheduled using the Kubernetes scheduler. However, if you a
By default GameServer application pods may schedule on different kubernetes node due nature of kubernetes default scheduler. To optimize and schedule the GameServer pods on the same node using PodAffinity can be beneficial in the PodSpec of CRD. Checkout this sample:

``` yaml
podSpec:
affinity:
podAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: BuildID
operator: In
values:
- "85ffe8da-c82f-4035-86c5-9d2b5f42d6f6"
topologyKey: "kubernetes.io/hostname"
template:
spec:
affinity:
podAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: BuildID
operator: In
values:
- "85ffe8da-c82f-4035-86c5-9d2b5f42d6f6"
topologyKey: "kubernetes.io/hostname"
```
To test this behavior check the [sample-nodeaffinity.yaml](../samples/netcore/sample-nodeaffinity.yaml) file.
Expand Down
17 changes: 9 additions & 8 deletions docs/gameserverbuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ spec:
portsToExpose: # port names that you need to expose for your game server, read more below
- containerName: gameserver-sample # name of the container that you want its port exposed
portName: gameport # name of the port that you want to expose
podSpec:
containers:
- image: youGameServerImage:tag # image of your game server
name: gameserver-sample # name of the container. Must be the same as portsToExpose.containerName
ports:
- containerPort: 7777 # port that you want to expose
name: gameport # name of the port that you want to expose. Must be the same as portsToExpose.portName
template:
spec:
containers:
- image: youGameServerImage:tag # image of your game server
name: gameserver-sample # name of the container. Must be the same as portsToExpose.containerName
ports:
- containerPort: 7777 # port that you want to expose
name: gameport # name of the port that you want to expose. Must be the same as portsToExpose.portName
```
The podSpec contains the definition for a [Kubernetes Pod](https://kubernetes.io/docs/concepts/workloads/pods/). As a result, you should include here whatever is needed for your game server (environment variables, storage, etc). Bear in mind though that not everything will work in MPS though.
The template.spec contains the definition for a [Kubernetes Pod](https://kubernetes.io/docs/concepts/workloads/pods/). As a result, you should include here whatever is needed for your game server (environment variables, storage, etc). Bear in mind though that not everything will work in MPS though.
## PortsToExpose
Expand Down
17 changes: 9 additions & 8 deletions docs/yourgameserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ spec:
portsToExpose:
- containerName: thundernetes-sample # must be the same as the container name described below
portName: gameport # must be the same as the port name described below
podSpec:
containers:
- image: thundernetes-netcore-sample:0.0.1.2
name: thundernetes-sample
ports:
- containerPort: 80 # your game server port
protocol: TCP # your game server port protocol
name: gameport # required field
template:
spec:
containers:
- image: thundernetes-netcore-sample:0.0.1.2
name: thundernetes-sample
ports:
- containerPort: 80 # your game server port
protocol: TCP # your game server port protocol
name: gameport # required field
```
You can call this file `gameserverbuild.yaml`.
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false,generateEmbeddedObjectMeta=true"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -99,7 +99,7 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/api/v1alpha1/gameserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ type GameServerSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// PodSpec describes the pod specification of the game server
PodSpec corev1.PodSpec `json:"podSpec,omitempty"`
// Template describes the pod template specification of the game server
Template corev1.PodTemplateSpec `json:"template,omitempty"`
//+kubebuilder:validation:Required
// TitleID is the TitleID this GameServer belongs to
TitleID string `json:"titleID,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/api/v1alpha1/gameserverbuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ type GameServerBuildSpec struct {
// Max is the maximum number of servers in any state
Max int `json:"max,omitempty"`

// PodSpec describes the pod specification of the game server
PodSpec corev1.PodSpec `json:"podSpec,omitempty"`
// Template describes the pod template specification of the game server
Template corev1.PodTemplateSpec `json:"template,omitempty"`

//+kubebuilder:validation:Required
// TitleID is the TitleID this Build belongs to
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1f46184

Please sign in to comment.