Skip to content

Commit

Permalink
Merge branch 'master' into monitoring/nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltovena authored Feb 3, 2019
2 parents 6fd7e3d + bc75c34 commit 37fbb3b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 90 deletions.
2 changes: 1 addition & 1 deletion site/content/en/blog/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Docsy Blog"
title: "Agones Blog"
linkTitle: "Blog"
menu:
main:
Expand Down
57 changes: 19 additions & 38 deletions test/e2e/fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func TestCreateFleetAndFleetAllocate(t *testing.T) {
defer fleets.Delete(flt.ObjectMeta.Name, nil) // nolint:errcheck
}

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

fa := &v1alpha1.FleetAllocation{
ObjectMeta: metav1.ObjectMeta{GenerateName: "allocation-", Namespace: defaultNs},
Expand Down Expand Up @@ -88,8 +87,7 @@ func TestCreateFullFleetAndCantFleetAllocate(t *testing.T) {
defer fleets.Delete(flt.ObjectMeta.Name, nil) // nolint:errcheck
}

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

fa := &v1alpha1.FleetAllocation{
ObjectMeta: metav1.ObjectMeta{GenerateName: "allocation-", Namespace: defaultNs},
Expand All @@ -104,10 +102,9 @@ func TestCreateFullFleetAndCantFleetAllocate(t *testing.T) {
assert.Equal(t, v1alpha1.GameServerStateAllocated, fa2.Status.GameServer.Status.State)
}

err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.AllocatedReplicas == replicasCount
})
assert.Nil(t, err)

fa2, err := framework.AgonesClient.StableV1alpha1().FleetAllocations(defaultNs).Create(fa)
assert.NotNil(t, err)
Expand All @@ -131,16 +128,14 @@ func TestScaleFleetUpAndDownWithFleetAllocation(t *testing.T) {

assert.Equal(t, int32(1), flt.Spec.Replicas)

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

// scale up
flt, err = scaleFleet(flt, 3)
assert.Nil(t, err)
assert.Equal(t, int32(3), flt.Spec.Replicas)

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err)
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

// get an allocation
fa := &v1alpha1.FleetAllocation{
Expand All @@ -153,28 +148,24 @@ func TestScaleFleetUpAndDownWithFleetAllocation(t *testing.T) {
fa, err = alpha1.FleetAllocations(defaultNs).Create(fa)
assert.Nil(t, err)
assert.Equal(t, v1alpha1.GameServerStateAllocated, fa.Status.GameServer.Status.State)
err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.AllocatedReplicas == 1
})
assert.Nil(t, err)

// scale down, with allocation
flt, err = scaleFleet(flt, 1)
assert.Nil(t, err)
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(0))
assert.Nil(t, err)
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(0))

// delete the allocated GameServer
gp := int64(1)
err = alpha1.GameServers(defaultNs).Delete(fa.Status.GameServer.ObjectMeta.Name, &metav1.DeleteOptions{GracePeriodSeconds: &gp})
assert.Nil(t, err)
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(1))
assert.Nil(t, err)
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(1))

err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.AllocatedReplicas == 0
})
assert.Nil(t, err)
}

func TestScaleFleetUpAndDownWithGameServerAllocation(t *testing.T) {
Expand All @@ -190,16 +181,14 @@ func TestScaleFleetUpAndDownWithGameServerAllocation(t *testing.T) {

assert.Equal(t, int32(1), flt.Spec.Replicas)

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

// scale up
flt, err = scaleFleet(flt, 3)
assert.Nil(t, err)
assert.Equal(t, int32(3), flt.Spec.Replicas)

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err)
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

// get an allocation
gsa := &v1alpha1.GameServerAllocation{ObjectMeta: metav1.ObjectMeta{GenerateName: "allocation-"},
Expand All @@ -210,28 +199,24 @@ func TestScaleFleetUpAndDownWithGameServerAllocation(t *testing.T) {
gsa, err = alpha1.GameServerAllocations(defaultNs).Create(gsa)
assert.Nil(t, err)
assert.Equal(t, v1alpha1.GameServerAllocationAllocated, gsa.Status.State)
err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.AllocatedReplicas == 1
})
assert.Nil(t, err)

// scale down, with allocation
flt, err = scaleFleet(flt, 1)
assert.Nil(t, err)
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(0))
assert.Nil(t, err)
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(0))

// delete the allocated GameServer
gp := int64(1)
err = alpha1.GameServers(defaultNs).Delete(gsa.Status.GameServerName, &metav1.DeleteOptions{GracePeriodSeconds: &gp})
assert.Nil(t, err)
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(1))
assert.Nil(t, err)
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(1))

err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.AllocatedReplicas == 0
})
assert.Nil(t, err)
}

func TestFleetUpdates(t *testing.T) {
Expand Down Expand Up @@ -312,8 +297,7 @@ func TestUpdateGameServerConfigurationInFleet(t *testing.T) {

assert.Equal(t, int32(replicasCount), flt.Spec.Replicas)

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

// get an allocation
gsa := &v1alpha1.GameServerAllocation{ObjectMeta: metav1.ObjectMeta{GenerateName: "allocation-"},
Expand All @@ -324,10 +308,9 @@ func TestUpdateGameServerConfigurationInFleet(t *testing.T) {
gsa, err = alpha1.GameServerAllocations(defaultNs).Create(gsa)
assert.Nil(t, err, "cloud not create gameserver allocation")
assert.Equal(t, v1alpha1.GameServerAllocationAllocated, gsa.Status.State)
err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.AllocatedReplicas == 1
})
assert.Nil(t, err, "could not allocate a gameserver")

flt, err = framework.AgonesClient.StableV1alpha1().Fleets(defaultNs).Get(flt.Name, metav1.GetOptions{})
assert.Nil(t, err, "could not get fleet")
Expand Down Expand Up @@ -371,8 +354,7 @@ func TestFleetAllocationDuringGameServerDeletion(t *testing.T) {

assert.Equal(t, size, flt.Spec.Replicas)

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

var allocs []*v1alpha1.GameServer

Expand Down Expand Up @@ -502,8 +484,7 @@ func TestGameServerAllocationDuringGameServerDeletion(t *testing.T) {

assert.Equal(t, size, flt.Spec.Replicas)

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

var allocs []string

Expand Down
56 changes: 21 additions & 35 deletions test/e2e/fleetautoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func TestAutoscalerBasicFunctions(t *testing.T) {
defer fleets.Delete(flt.ObjectMeta.Name, nil) // nolint:errcheck
}

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

fleetautoscalers := alpha1.FleetAutoscalers(defaultNs)
fas, err := fleetautoscalers.Create(defaultFleetAutoscaler(flt))
Expand All @@ -64,56 +63,49 @@ func TestAutoscalerBasicFunctions(t *testing.T) {

// the fleet autoscaler should scale the fleet up now up to BufferSize
bufferSize := int32(fas.Spec.Policy.Buffer.BufferSize.IntValue())
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(bufferSize))
assert.Nil(t, err, "fleet did not sync with autoscaler")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(bufferSize))

// patch the autoscaler to increase MinReplicas and watch the fleet scale up
fas, err = patchFleetAutoscaler(fas, intstr.FromInt(int(bufferSize)), bufferSize+2, fas.Spec.Policy.Buffer.MaxReplicas)
assert.Nil(t, err, "could not patch fleetautoscaler")

bufferSize = int32(fas.Spec.Policy.Buffer.BufferSize.IntValue())
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(bufferSize))
assert.Nil(t, err, "fleet did not sync with autoscaler")
// min replicas is now higher than buffer size, will scale to that level
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(fas.Spec.Policy.Buffer.MinReplicas))

// patch the autoscaler to remove MinReplicas and watch the fleet scale down
// patch the autoscaler to remove MinReplicas and watch the fleet scale down to bufferSize
fas, err = patchFleetAutoscaler(fas, intstr.FromInt(int(bufferSize)), 0, fas.Spec.Policy.Buffer.MaxReplicas)
assert.Nil(t, err, "could not patch fleetautoscaler")

bufferSize = int32(fas.Spec.Policy.Buffer.BufferSize.IntValue())
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(bufferSize))
assert.Nil(t, err, "fleet did not sync with autoscaler")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(bufferSize))

// do an allocation and watch the fleet scale up
fa := getAllocation(flt)
fa, err = alpha1.FleetAllocations(defaultNs).Create(fa)
assert.Nil(t, err)
assert.Equal(t, v1alpha1.GameServerStateAllocated, fa.Status.GameServer.Status.State)
err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.AllocatedReplicas == 1
})
assert.Nil(t, err)

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(bufferSize))
assert.Nil(t, err, "fleet did not sync with autoscaler")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(bufferSize))

// patch autoscaler to switch to relative buffer size and check if the fleet adjusts
_, err = patchFleetAutoscaler(fas, intstr.FromString("10%"), 1, fas.Spec.Policy.Buffer.MaxReplicas)
assert.Nil(t, err, "could not patch fleetautoscaler")

//10% with only one allocated GS means only one ready server
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(1))
assert.Nil(t, err, "fleet did not sync with autoscaler")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(1))

// delete the allocated GameServer and watch the fleet scale down
gp := int64(1)
err = alpha1.GameServers(defaultNs).Delete(fa.Status.GameServer.ObjectMeta.Name, &metav1.DeleteOptions{GracePeriodSeconds: &gp})
assert.Nil(t, err)
err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.AllocatedReplicas == 0 &&
fleet.Status.ReadyReplicas == 1 &&
fleet.Status.Replicas == 1
})
assert.Nil(t, err)
}

// TestAutoscalerStressCreate creates many fleetautoscalers with random values
Expand All @@ -129,8 +121,7 @@ func TestAutoscalerStressCreate(t *testing.T) {
defer fleets.Delete(flt.ObjectMeta.Name, nil) // nolint:errcheck
}

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

r := rand.New(rand.NewSource(1783))

Expand Down Expand Up @@ -170,8 +161,7 @@ func TestAutoscalerStressCreate(t *testing.T) {
expectedReplicas = fas.Spec.Policy.Buffer.MaxReplicas
}
// the fleet autoscaler should scale the fleet now to expectedReplicas
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(expectedReplicas))
assert.Nil(t, err, fmt.Sprintf("fleet did not sync with autoscaler, expected %d ready replicas", expectedReplicas))
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(expectedReplicas))
} else {
assert.False(t, valid,
fmt.Sprintf("FleetAutoscaler NOT created even if the parameters are valid: %d %d %d (%s)",
Expand Down Expand Up @@ -206,7 +196,9 @@ func patchFleetAutoscaler(fas *v1alpha1.FleetAutoscaler, bufferSize intstr.IntOr
WithField("patch", patch).
Info("Patching fleetautoscaler")

return framework.AgonesClient.StableV1alpha1().FleetAutoscalers(defaultNs).Patch(fas.ObjectMeta.Name, types.JSONPatchType, []byte(patch))
fas, err := framework.AgonesClient.StableV1alpha1().FleetAutoscalers(defaultNs).Patch(fas.ObjectMeta.Name, types.JSONPatchType, []byte(patch))
logrus.WithField("fleetautoscaler", fas).Info("Patched fleet autoscaler")
return fas, err
}

// defaultFleetAutoscaler returns a default fleet autoscaler configuration for a given fleet
Expand Down Expand Up @@ -269,8 +261,7 @@ func TestAutoscalerWebhook(t *testing.T) {
defer fleets.Delete(flt.ObjectMeta.Name, nil) // nolint:errcheck
}

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

fleetautoscalers := alpha1.FleetAutoscalers(defaultNs)
fas := defaultFleetAutoscaler(flt)
Expand All @@ -295,15 +286,13 @@ func TestAutoscalerWebhook(t *testing.T) {
fa, err = alpha1.FleetAllocations(defaultNs).Create(fa)
assert.Nil(t, err)
assert.Equal(t, v1alpha1.GameServerStateAllocated, fa.Status.GameServer.Status.State)
err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.AllocatedReplicas == 1
})
assert.Nil(t, err)

err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.Replicas > initialReplicasCount
})
assert.Nil(t, err)
}

var webhookKey = `
Expand Down Expand Up @@ -446,8 +435,7 @@ func TestTlsWebhook(t *testing.T) {
defer fleets.Delete(flt.ObjectMeta.Name, nil) // nolint:errcheck
}

err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
assert.Nil(t, err, "fleet not ready")
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

fleetautoscalers := alpha1.FleetAutoscalers(defaultNs)
fas := defaultFleetAutoscaler(flt)
Expand All @@ -474,15 +462,13 @@ func TestTlsWebhook(t *testing.T) {
fa, err = alpha1.FleetAllocations(defaultNs).Create(fa.DeepCopy())
assert.Nil(t, err)
assert.Equal(t, v1alpha1.GameServerStateAllocated, fa.Status.GameServer.Status.State)
err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.AllocatedReplicas == 1
})
assert.Nil(t, err)

err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
framework.WaitForFleetCondition(t, flt, func(fleet *v1alpha1.Fleet) bool {
return fleet.Status.Replicas > initialReplicasCount
})
assert.Nil(t, err)
}

func defaultAutoscalerWebhook() (*corev1.Pod, *corev1.Service) {
Expand Down
13 changes: 10 additions & 3 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package framework
import (
"fmt"
"net"
"testing"
"time"

"agones.dev/agones/pkg/apis/stable/v1alpha1"
Expand Down Expand Up @@ -122,8 +123,10 @@ func (f *Framework) WaitForGameServerState(gs *v1alpha1.GameServer, state v1alph
return readyGs, nil
}

// WaitForFleetCondition waits for the Fleet to be in a specific condition
func (f *Framework) WaitForFleetCondition(flt *v1alpha1.Fleet, condition func(fleet *v1alpha1.Fleet) bool) error {
// WaitForFleetCondition waits for the Fleet to be in a specific condition or fails the test if the condition can't be met in 5 minutes.
func (f *Framework) WaitForFleetCondition(t *testing.T, flt *v1alpha1.Fleet, condition func(fleet *v1alpha1.Fleet) bool) {
t.Helper()
logrus.WithField("fleet", flt.Name).Info("waiting for fleet condition")
err := wait.PollImmediate(2*time.Second, 5*time.Minute, func() (bool, error) {
fleet, err := f.AgonesClient.StableV1alpha1().Fleets(flt.ObjectMeta.Namespace).Get(flt.ObjectMeta.Name, metav1.GetOptions{})
if err != nil {
Expand All @@ -132,7 +135,10 @@ func (f *Framework) WaitForFleetCondition(flt *v1alpha1.Fleet, condition func(fl

return condition(fleet), nil
})
return err
if err != nil {
logrus.WithField("fleet", flt.Name).WithError(err).Info("error waiting for fleet condition")
t.Fatal("error waiting for fleet condition")
}
}

// ListGameServersFromFleet lists GameServers from a particular fleet
Expand Down Expand Up @@ -161,6 +167,7 @@ func (f *Framework) ListGameServersFromFleet(flt *v1alpha1.Fleet) ([]v1alpha1.Ga
// FleetReadyCount returns the ready count in a fleet
func FleetReadyCount(amount int32) func(fleet *v1alpha1.Fleet) bool {
return func(fleet *v1alpha1.Fleet) bool {
logrus.Infof("fleet %v has %v/%v ready replicas", fleet.Name, fleet.Status.ReadyReplicas, amount)
return fleet.Status.ReadyReplicas == amount
}
}
Expand Down
Loading

0 comments on commit 37fbb3b

Please sign in to comment.