Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/apis/stable/v1alpha1/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ type FleetStatus struct {
Replicas int32 `json:"replicas"`
// ReadyReplicas are the number of Ready GameServer replicas
ReadyReplicas int32 `json:"readyReplicas"`
// AllocatedReplicas are the number of Allocated GameServer replicas
AllocatedReplicas int32 `json:"allocatedReplicas"`
}

// GameServerSet returns a single GameServerSet for this Fleet definition
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/stable/v1alpha1/gameserverset.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type GameServerSetStatus struct {
Replicas int32 `json:"replicas"`
// ReadyReplicas are the number of Ready GameServer replicas
ReadyReplicas int32 `json:"readyReplicas"`
// AllocatedReplicas are the number of Allocated GameServer replicas
AllocatedReplicas int32 `json:"allocatedReplicas"`
}

// ValidateUpdate validates when updates occur. The argument
Expand Down
7 changes: 4 additions & 3 deletions pkg/fleetallocation/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@
package fleetallocation

import (
"testing"
"encoding/json"
"fmt"
"strconv"
"testing"

"sync"

"agones.dev/agones/pkg/apis/stable/v1alpha1"
agtesting "agones.dev/agones/pkg/testing"
"agones.dev/agones/pkg/util/webhooks"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
admv1beta1 "k8s.io/api/admission/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
k8stesting "k8s.io/client-go/testing"
"sync"
"github.com/sirupsen/logrus"
)

var (
Expand Down
2 changes: 2 additions & 0 deletions pkg/fleets/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ func (c *Controller) updateFleetStatus(fleet *stablev1alpha1.Fleet) error {
fCopy := fleet.DeepCopy()
fCopy.Status.Replicas = 0
fCopy.Status.ReadyReplicas = 0
fCopy.Status.AllocatedReplicas = 0

for _, gsSet := range list {
fCopy.Status.Replicas += gsSet.Status.Replicas
fCopy.Status.ReadyReplicas += gsSet.Status.ReadyReplicas
fCopy.Status.AllocatedReplicas += gsSet.Status.AllocatedReplicas
}

_, err = c.fleetGetter.Fleets(fCopy.Namespace).Update(fCopy)
Expand Down
3 changes: 3 additions & 0 deletions pkg/fleets/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,13 @@ func TestControllerUpdateFleetStatus(t *testing.T) {
gsSet1.ObjectMeta.Name = "gsSet1"
gsSet1.Status.Replicas = 3
gsSet1.Status.ReadyReplicas = 2
gsSet1.Status.AllocatedReplicas = 1

gsSet2 := fleet.GameServerSet()
gsSet2.ObjectMeta.Name = "gsSet2"
gsSet2.Status.Replicas = 5
gsSet2.Status.ReadyReplicas = 5
gsSet2.Status.AllocatedReplicas = 2

m.AgonesClient.AddReactor("list", "gameserversets",
func(action k8stesting.Action) (bool, runtime.Object, error) {
Expand All @@ -227,6 +229,7 @@ func TestControllerUpdateFleetStatus(t *testing.T) {

assert.Equal(t, gsSet1.Status.Replicas+gsSet2.Status.Replicas, fleet.Status.Replicas)
assert.Equal(t, gsSet1.Status.ReadyReplicas+gsSet2.Status.ReadyReplicas, fleet.Status.ReadyReplicas)
assert.Equal(t, gsSet1.Status.AllocatedReplicas+gsSet2.Status.AllocatedReplicas, fleet.Status.AllocatedReplicas)
return true, fleet, nil
})

Expand Down
12 changes: 10 additions & 2 deletions pkg/gameserversets/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,21 @@ func (c *Controller) syncLessGameSevers(gsSet *stablev1alpha1.GameServerSet, lis
// syncGameServerSetState synchronises the GameServerSet State with active GameServer counts
func (c *Controller) syncGameServerSetState(gsSet *stablev1alpha1.GameServerSet, list []*stablev1alpha1.GameServer) error {
rc := int32(0)
ac := int32(0)
for _, gs := range list {
if gs.Status.State == stablev1alpha1.Ready {
switch gs.Status.State {
case stablev1alpha1.Ready:
rc++
case stablev1alpha1.Allocated:
ac++
}
}

status := stablev1alpha1.GameServerSetStatus{Replicas: int32(len(list)), ReadyReplicas: rc}
status := stablev1alpha1.GameServerSetStatus{
Replicas: int32(len(list)),
ReadyReplicas: rc,
AllocatedReplicas: ac,
}
if gsSet.Status != status {
gsSetCopy := gsSet.DeepCopy()
gsSetCopy.Status = status
Expand Down
6 changes: 5 additions & 1 deletion pkg/gameserversets/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ func TestControllerSyncGameServerSetState(t *testing.T) {

assert.Equal(t, int32(1), gsSet.Status.Replicas)
assert.Equal(t, int32(1), gsSet.Status.ReadyReplicas)
assert.Equal(t, int32(0), gsSet.Status.AllocatedReplicas)

return true, nil, nil
})
Expand All @@ -370,8 +371,9 @@ func TestControllerSyncGameServerSetState(t *testing.T) {
ua := action.(k8stesting.UpdateAction)
gsSet := ua.GetObject().(*v1alpha1.GameServerSet)

assert.Equal(t, int32(6), gsSet.Status.Replicas)
assert.Equal(t, int32(8), gsSet.Status.Replicas)
assert.Equal(t, int32(1), gsSet.Status.ReadyReplicas)
assert.Equal(t, int32(2), gsSet.Status.AllocatedReplicas)

return true, nil, nil
})
Expand All @@ -383,6 +385,8 @@ func TestControllerSyncGameServerSetState(t *testing.T) {
{Status: v1alpha1.GameServerStatus{State: v1alpha1.PortAllocation}},
{Status: v1alpha1.GameServerStatus{State: v1alpha1.Error}},
{Status: v1alpha1.GameServerStatus{State: v1alpha1.Creating}},
{Status: v1alpha1.GameServerStatus{State: v1alpha1.Allocated}},
{Status: v1alpha1.GameServerStatus{State: v1alpha1.Allocated}},
}
err := c.syncGameServerSetState(gsSet, list)
assert.Nil(t, err)
Expand Down