forked from googleforgames/agones
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GameServerSets are the basic building block for Fleets. GameServerSets will be allow Fleet migrations to occur, similarly to how ReplicaSets allow Deployments to migrate one image type to another. This has not been formally documented, as this will likely be an internal CRD, and not (widely) used externally. Parent ticket: googleforgames#70
- Loading branch information
1 parent
794dcdb
commit cdfab72
Showing
25 changed files
with
1,913 additions
and
19 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2018 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Usually you would define a Fleet rather than a GameServerSet | ||
# directly. This is here mostly for testing purposes | ||
|
||
apiVersion: "stable.agones.dev/v1alpha1" | ||
kind: GameServerSet | ||
metadata: | ||
name: cpp-simple | ||
spec: | ||
replicas: 5 | ||
template: | ||
spec: | ||
containerPort: 7654 | ||
template: | ||
spec: | ||
health: | ||
initialDelaySeconds: 15 | ||
containers: | ||
- name: cpp-simple | ||
image: gcr.io/agones-images/cpp-simple-server:0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2018 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Usually you would define a Fleet rather than a GameServerSet | ||
# directly. This is here mostly for testing purposes | ||
|
||
apiVersion: "stable.agones.dev/v1alpha1" | ||
kind: GameServerSet | ||
metadata: | ||
name: simple-udp | ||
spec: | ||
replicas: 2 | ||
template: | ||
spec: | ||
containerPort: 7654 | ||
template: | ||
spec: | ||
containers: | ||
- name: simple-udp | ||
image: gcr.io/agones-images/udp-server:0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2018 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"reflect" | ||
|
||
"agones.dev/agones/pkg/apis/stable" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
// GameServerSetGameServerLabel is the label that the name of the GameServerSet | ||
// is set on the GameServer the GameServerSet controls | ||
GameServerSetGameServerLabel = stable.GroupName + "/gameserverset" | ||
) | ||
|
||
// +genclient | ||
// +genclient:noStatus | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// GameServerSet is the data structure a set of GameServers | ||
// This matches philosophically with the relationship between | ||
// Depoyments and ReplicaSets | ||
type GameServerSet struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec GameServerSetSpec `json:"spec"` | ||
Status GameServerSetStatus `json:"status"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// GameServerSetList is a list of GameServerSet resources | ||
type GameServerSetList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
|
||
Items []GameServerSet `json:"items"` | ||
} | ||
|
||
// GameServerSetSpec the specification for | ||
type GameServerSetSpec struct { | ||
// Replicas are the number of GameServers that should be in this set | ||
Replicas int32 `json:"replicas"` | ||
// Template the GameServer template to apply for this GameServerSet | ||
Template GameServerTemplateSpec `json:"template"` | ||
} | ||
|
||
// GameServerSetStatus is the status of a GameServerSet | ||
type GameServerSetStatus struct { | ||
// Replicas the total number of current GameServer replicas | ||
Replicas int32 `json:"replicas"` | ||
// ReadyReplicas are the number of Ready GameServer replicas | ||
ReadyReplicas int32 `json:"readyReplicas"` | ||
} | ||
|
||
// ValidateUpdate validates when updates occur. The argument | ||
// is the new GameServerSet, being passed into the old GameServerSet | ||
func (gsSet *GameServerSet) ValidateUpdate(new *GameServerSet) (bool, []metav1.StatusCause) { | ||
var causes []metav1.StatusCause | ||
if !reflect.DeepEqual(gsSet.Spec.Template, new.Spec.Template) { | ||
causes = append(causes, metav1.StatusCause{ | ||
Type: metav1.CauseTypeFieldValueInvalid, | ||
Field: "template", | ||
Message: "template values cannot be updated after creation", | ||
}) | ||
} | ||
|
||
return len(causes) == 0, causes | ||
} | ||
|
||
// GameServer returns a single GameServer derived | ||
// from the GameSever template | ||
func (gsSet *GameServerSet) GameServer() *GameServer { | ||
gs := &GameServer{ | ||
ObjectMeta: *gsSet.Spec.Template.ObjectMeta.DeepCopy(), | ||
Spec: *gsSet.Spec.Template.Spec.DeepCopy(), | ||
} | ||
|
||
// Switch to GenerateName, so that we always get a Unique name for the GameServer, and there | ||
// can be no collisions | ||
gs.ObjectMeta.GenerateName = gsSet.ObjectMeta.Name + "-" | ||
gs.ObjectMeta.Name = "" | ||
gs.ObjectMeta.Namespace = gsSet.ObjectMeta.Namespace | ||
gs.ObjectMeta.ResourceVersion = "" | ||
gs.ObjectMeta.UID = "" | ||
|
||
ref := metav1.NewControllerRef(gsSet, SchemeGroupVersion.WithKind("GameServerSet")) | ||
gs.ObjectMeta.OwnerReferences = append(gs.ObjectMeta.OwnerReferences, *ref) | ||
|
||
if gs.ObjectMeta.Labels == nil { | ||
gs.ObjectMeta.Labels = make(map[string]string, 1) | ||
} | ||
|
||
gs.ObjectMeta.Labels[GameServerSetGameServerLabel] = gsSet.ObjectMeta.Name | ||
|
||
return gs | ||
} |
Oops, something went wrong.