Skip to content

Commit

Permalink
Pulls feature gate validation out of the validate func
Browse files Browse the repository at this point in the history
  • Loading branch information
igooch committed Feb 15, 2023
1 parent 3b93cab commit 92c4a00
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
8 changes: 4 additions & 4 deletions examples/gameserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ spec:
# Counts and Lists provides the configuration for generic (player, room, session, etc.) tracking features.
# Commented out since Alpha, and disabled by default
# counters:
# gameCounter:
# games:
# count: 1
# capacity: 100
# sessionCounter:
# sessions:
# capacity: 999
# lists:
# playerList:
# players:
# capacity: 1000
# values:
# roomList:
# rooms:
# capacity: 333
# values:
# - room1
Expand Down
35 changes: 23 additions & 12 deletions pkg/apis/agones/v1/gameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ type GameServerSpec struct {
Players *PlayersSpec `json:"players,omitempty"`
// (Alpha, CountsAndLists feature flag) Counters and Lists provides the configuration for generic tracking features.
// +optional
Counters *CountersSpec `json:"counters,omitempty"`
Lists *ListsSpec `json:"lists,omitempty"`
Counters map[string]*CounterSpec `json:"counters,omitempty"`
Lists map[string]*ListSpec `json:"lists,omitempty"`
// (Alpha, SafeToEvict feature flag) Eviction specifies the eviction tolerance of the GameServer. Defaults to "Never".
// +optional
Eviction Eviction `json:"eviction,omitempty"`
Expand All @@ -202,13 +202,16 @@ type PlayersSpec struct {
InitialCapacity int64 `json:"initialCapacity,omitempty"`
}

// CountersSpec tracks if counter specified (for giving error message if feature gate not set)
type CountersSpec struct {
// CounterSpec tracks if counter specified (for giving error message if feature gate not set)
type CounterSpec struct {
Count int64 `json:"count,omitempty"`
Capacity int64 `json:"capacity,omitempty"`
}

// ListsSpec tracks the list capacity
type ListsSpec struct {
Capacity int64 `json:"capacity,omitempty"`
// ListSpec tracks the list capacity
type ListSpec struct {
Capacity int64 `json:"capacity,omitempty"`
Values []string `json:"values,omitempty"`
}

// Eviction specifies the eviction tolerance of the GameServer
Expand Down Expand Up @@ -434,11 +437,8 @@ func (gs *GameServer) applyEvictionStatus() {
}
}

// Validate validates the GameServerSpec configuration.
// devAddress is a specific IP address used for local Gameservers, for fleets "" is used
// If a GameServer Spec is invalid there will be > 0 values in
// the returned array
func (gss *GameServerSpec) Validate(apiHooks APIHooks, devAddress string) ([]metav1.StatusCause, bool) {
// validateFeatureGates checks if fields are set when the associated feature gate is not set.
func (gss *GameServerSpec) validateFeatureGates() []metav1.StatusCause {
var causes []metav1.StatusCause

if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) {
Expand Down Expand Up @@ -478,6 +478,17 @@ func (gss *GameServerSpec) Validate(apiHooks APIHooks, devAddress string) ([]met
}
}

return causes
}

// Validate validates the GameServerSpec configuration.
// devAddress is a specific IP address used for local Gameservers, for fleets "" is used
// If a GameServer Spec is invalid there will be > 0 values in the returned array
func (gss *GameServerSpec) Validate(apiHooks APIHooks, devAddress string) ([]metav1.StatusCause, bool) {
var causes []metav1.StatusCause

causes = append(causes, gss.validateFeatureGates()...)

if devAddress != "" {
// verify that the value is a valid IP address.
if net.ParseIP(devAddress) == nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/agones/v1/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ func TestGameServerValidateFeatures(t *testing.T) {
gs: GameServer{
Spec: GameServerSpec{
Container: "testing",
Counters: &CountersSpec{},
Counters: map[string]*CounterSpec{},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{Containers: []corev1.Container{{Name: "testing", Image: "testing/image"}}}}},
},
Expand All @@ -1133,7 +1133,7 @@ func TestGameServerValidateFeatures(t *testing.T) {
gs: GameServer{
Spec: GameServerSpec{
Container: "testing",
Lists: &ListsSpec{Capacity: 100},
Lists: map[string]*ListSpec{},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{Containers: []corev1.Container{{Name: "testing", Image: "testing/image"}}}}},
},
Expand All @@ -1148,7 +1148,7 @@ func TestGameServerValidateFeatures(t *testing.T) {
gs: GameServer{
Spec: GameServerSpec{
Container: "testing",
Counters: &CountersSpec{},
Counters: map[string]*CounterSpec{},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{Containers: []corev1.Container{{Name: "testing", Image: "testing/image"}}}}},
},
Expand All @@ -1161,7 +1161,7 @@ func TestGameServerValidateFeatures(t *testing.T) {
gs: GameServer{
Spec: GameServerSpec{
Container: "testing",
Lists: &ListsSpec{Capacity: 100},
Lists: map[string]*ListSpec{},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{Containers: []corev1.Container{{Name: "testing", Image: "testing/image"}}}}},
},
Expand Down

0 comments on commit 92c4a00

Please sign in to comment.