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
20 changes: 15 additions & 5 deletions test/e2e/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func TestAllocatorWithDeprecatedRequired(t *testing.T) {
} else {
flt, err = helper.CreateFleet(ctx, framework.Namespace, framework)
}
assert.NoError(t, err)
require.NoError(t, err)
defer framework.AgonesClient.AgonesV1().Fleets(framework.Namespace).Delete(ctx, flt.Name, metav1.DeleteOptions{}) // nolint: errcheck

framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))
request := &pb.AllocationRequest{
Expand Down Expand Up @@ -146,7 +147,7 @@ func TestAllocatorWithDeprecatedRequired(t *testing.T) {
return true, nil
})

assert.NoError(t, err)
require.NoError(t, err)
}

func TestAllocatorWithSelectors(t *testing.T) {
Expand All @@ -168,6 +169,7 @@ func TestAllocatorWithSelectors(t *testing.T) {
flt, err = helper.CreateFleet(ctx, framework.Namespace, framework)
}
assert.NoError(t, err)
defer framework.AgonesClient.AgonesV1().Fleets(framework.Namespace).Delete(ctx, flt.Name, metav1.DeleteOptions{}) // nolint: errcheck

framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))
request := &pb.AllocationRequest{
Expand Down Expand Up @@ -250,6 +252,8 @@ func TestRestAllocatorWithDeprecatedRequired(t *testing.T) {
return
}
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))
defer framework.AgonesClient.AgonesV1().Fleets(framework.Namespace).Delete(ctx, flt.Name, metav1.DeleteOptions{}) // nolint: errcheck

request := &pb.AllocationRequest{
Namespace: framework.Namespace,
RequiredGameServerSelector: &pb.GameServerSelector{MatchLabels: map[string]string{agonesv1.FleetNameLabel: flt.ObjectMeta.Name}},
Expand Down Expand Up @@ -328,7 +332,9 @@ func TestAllocatorWithCountersAndLists(t *testing.T) {
}
})
assert.NoError(t, err)
defer framework.AgonesClient.AgonesV1().Fleets(framework.Namespace).Delete(ctx, flt.Name, metav1.DeleteOptions{}) // nolint: errcheck
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

request := &pb.AllocationRequest{
Namespace: framework.Namespace,
GameServerSelectors: []*pb.GameServerSelector{{
Expand Down Expand Up @@ -413,7 +419,9 @@ func TestRestAllocatorWithCountersAndLists(t *testing.T) {
}
})
assert.NoError(t, err)
defer framework.AgonesClient.AgonesV1().Fleets(framework.Namespace).Delete(ctx, flt.Name, metav1.DeleteOptions{}) // nolint: errcheck
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

request := &pb.AllocationRequest{
Namespace: framework.Namespace,
GameServerSelectors: []*pb.GameServerSelector{{
Expand Down Expand Up @@ -498,10 +506,10 @@ func TestRestAllocatorWithSelectors(t *testing.T) {
tlsCA := helper.RefreshAllocatorTLSCerts(ctx, t, ip, framework)

flt, err := helper.CreateFleet(ctx, framework.Namespace, framework)
if !assert.Nil(t, err) {
return
}
require.NoError(t, err)
defer framework.AgonesClient.AgonesV1().Fleets(framework.Namespace).Delete(ctx, flt.Name, metav1.DeleteOptions{}) // nolint: errcheck
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))

request := &pb.AllocationRequest{
Namespace: framework.Namespace,
GameServerSelectors: []*pb.GameServerSelector{{MatchLabels: map[string]string{agonesv1.FleetNameLabel: flt.ObjectMeta.Name}}},
Expand Down Expand Up @@ -608,6 +616,8 @@ func TestAllocatorCrossNamespace(t *testing.T) {
return
}
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))
defer framework.AgonesClient.AgonesV1().Fleets(namespaceB).Delete(ctx, flt.Name, metav1.DeleteOptions{}) // nolint: errcheck

request := &pb.AllocationRequest{
Namespace: namespaceA,
// Enable multi-cluster setting
Expand Down
21 changes: 20 additions & 1 deletion test/e2e/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package e2e

import (
"context"
"testing"

e2eframework "agones.dev/agones/test/e2e/framework"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
Expand All @@ -28,6 +30,9 @@ import (

func TestSuperTuxKartGameServerReady(t *testing.T) {
t.Parallel()

log := e2eframework.TestLogger(t)

gs := &agonesv1.GameServer{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "supertuxkart-",
Expand All @@ -40,6 +45,10 @@ func TestSuperTuxKartGameServerReady(t *testing.T) {
PortPolicy: agonesv1.Dynamic,
Protocol: corev1.ProtocolUDP,
}},
Health: agonesv1.Health{
PeriodSeconds: 60,
InitialDelaySeconds: 30,
},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
Expand All @@ -61,10 +70,20 @@ func TestSuperTuxKartGameServerReady(t *testing.T) {

// Use the e2e framework's function to create the GameServer and wait until it's ready
readyGs, err := framework.CreateGameServerAndWaitUntilReady(t, framework.Namespace, gs)
if err != nil {
log.Info("Game Server Events:")
framework.LogEvents(t, log, readyGs.ObjectMeta.Namespace, readyGs)

// Get pod and log events
log.Info("Game Server Pod Events:")
pod, err := framework.KubeClient.CoreV1().Pods(framework.Namespace).Get(context.Background(), readyGs.ObjectMeta.Name, metav1.GetOptions{})
require.NoError(t, err)
framework.LogEvents(t, log, pod.ObjectMeta.Namespace, pod)
}
require.NoError(t, err)

// Assert that the GameServer is in the expected state
assert.Equal(t, agonesv1.GameServerStateReady, readyGs.Status.State)
require.Equal(t, agonesv1.GameServerStateReady, readyGs.Status.State)
}

func TestRustGameServerReady(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (f *Framework) CreateGameServerAndWaitUntilReady(t *testing.T, ns string, g
readyGs, err := f.WaitForGameServerState(t, newGs, agonesv1.GameServerStateReady, f.WaitForState)

if err != nil {
return nil, fmt.Errorf("waiting for %v GameServer instance readiness timed out (%v): %v",
return readyGs, fmt.Errorf("waiting for %v GameServer instance readiness timed out (%v): %v",
gs.Spec, gs.Name, err)
}

Expand All @@ -240,7 +240,7 @@ func (f *Framework) CreateGameServerAndWaitUntilReady(t *testing.T, ns string, g
}

if len(readyGs.Status.Ports) != expectedPortCount {
return nil, fmt.Errorf("ready GameServer instance has %d port(s), want %d", len(readyGs.Status.Ports), expectedPortCount)
return readyGs, fmt.Errorf("ready GameServer instance has %d port(s), want %d", len(readyGs.Status.Ports), expectedPortCount)
}

logrus.WithField("gs", newGs.ObjectMeta.Name).Info("GameServer Ready")
Expand Down
67 changes: 57 additions & 10 deletions test/e2e/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -803,22 +804,35 @@ func TestGameServerShutdown(t *testing.T) {
// TestGameServerEvicted test that if Gameserver would be evicted than it becomes Unhealthy
// Ephemeral Storage limit set to 0Mi
func TestGameServerEvicted(t *testing.T) {
framework.SkipOnCloudProduct(t, "gke-autopilot", "Autopilot adjusts ephmeral storage to a minimum of 10Mi, see https://github.com/googleforgames/agones/issues/2890")
t.Parallel()
log := e2eframework.TestLogger(t)

ctx := context.Background()
gs := framework.DefaultGameServer(framework.Namespace)
gs.Spec.Template.Spec.Containers[0].Resources.Limits[corev1.ResourceEphemeralStorage] = resource.MustParse("0Mi")

newGs, err := framework.AgonesClient.AgonesV1().GameServers(framework.Namespace).Create(ctx, gs, metav1.CreateOptions{})
if err != nil {
assert.FailNow(t, fmt.Sprintf("creating %v GameServer instances failed (%v): %v", gs.Spec, gs.Name, err))
}
newGs, err := framework.CreateGameServerAndWaitUntilReady(t, framework.Namespace, gs)
require.NoError(t, err)
log.WithField("name", newGs.ObjectMeta.Name).Info("GameServer created, waiting for being Evicted and Unhealthy")
defer framework.AgonesClient.AgonesV1().GameServers(framework.Namespace).Delete(ctx, newGs.ObjectMeta.Name, metav1.DeleteOptions{}) // nolint: errcheck

logrus.WithField("name", newGs.ObjectMeta.Name).Info("GameServer created, waiting for being Evicted and Unhealthy")
pods := framework.KubeClient.CoreV1().Pods(framework.Namespace)
pod, err := pods.Get(ctx, newGs.ObjectMeta.Name, metav1.GetOptions{})
require.NoError(t, err)

_, err = framework.WaitForGameServerState(t, newGs, agonesv1.GameServerStateUnhealthy, 5*time.Minute)
eviction := &policyv1.Eviction{
ObjectMeta: metav1.ObjectMeta{
Name: pod.Name,
Namespace: pod.Namespace,
},
}
go func() {
time.Sleep(3 * time.Second) // just make sure it comes in later
log.WithField("name", eviction.ObjectMeta.Name).Info("Evicting pod!")
err := pods.EvictV1(context.Background(), eviction)
require.NoError(t, err)
}()

assert.Nil(t, err, fmt.Sprintf("waiting for %v GameServer Unhealthy state timed out (%v): %v", gs.Spec, gs.Name, err))
_, err = framework.WaitForGameServerState(t, newGs, agonesv1.GameServerStateUnhealthy, 10*time.Minute)
require.NoError(t, err, fmt.Sprintf("waiting for [%v] GameServer Unhealthy state timed out (%v)", gs.Status.State, gs.Name))
}

func TestGameServerPassthroughPort(t *testing.T) {
Expand Down Expand Up @@ -1650,6 +1664,39 @@ func TestLists(t *testing.T) {
}
}

func TestSideCarCommunicatesWhileTerminating(t *testing.T) {
t.Parallel()
ctx := context.Background()
gs := framework.DefaultGameServer(framework.Namespace)

minute := int64(60)
gs.Spec.Template.Spec.Containers[0].Args = append(gs.Spec.Template.Spec.Containers[0].Args, "--gracefulTerminationDelaySec", "60")
gs.Spec.Template.Spec.TerminationGracePeriodSeconds = &minute
readyGs, err := framework.CreateGameServerAndWaitUntilReady(t, framework.Namespace, gs)
require.NoError(t, err)
require.Equal(t, readyGs.Status.State, agonesv1.GameServerStateReady)

// delete the GameServer
gameServers := framework.AgonesClient.AgonesV1().GameServers(framework.Namespace)
err = gameServers.Delete(context.Background(), readyGs.ObjectMeta.Name, metav1.DeleteOptions{})
require.NoError(t, err, "Could not delete GameServer")

// wait for the deletion timestamp to be set
err = wait.PollUntilContextTimeout(ctx, time.Second, time.Minute, true, func(ctx context.Context) (bool, error) {
gs, err := gameServers.Get(ctx, readyGs.ObjectMeta.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
return gs.DeletionTimestamp != nil, nil
})
require.NoError(t, err, "Could not get a GameServer with deletion timestamp")

// send a "GAMESERVER" message, and confirm it works
reply, err := framework.SendGameServerUDP(t, readyGs, "GAMESERVER")
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("NAME: %s\n", readyGs.ObjectMeta.Name), reply)
}

func TestGracefulShutdown(t *testing.T) {
t.Parallel()

Expand Down