Skip to content

Commit 0aae082

Browse files
Yingxin-Jiangmarkmandel
authored andcommitted
Add e2e test for updating gameserver configurations in fleet
1 parent f6ccd18 commit 0aae082

1 file changed

Lines changed: 65 additions & 3 deletions

File tree

test/e2e/fleet_test.go

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/sirupsen/logrus"
2626
"github.com/stretchr/testify/assert"
2727
appsv1 "k8s.io/api/apps/v1"
28+
corev1 "k8s.io/api/core/v1"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"k8s.io/apimachinery/pkg/types"
3031
"k8s.io/apimachinery/pkg/util/wait"
@@ -290,9 +291,66 @@ func TestFleetUpdates(t *testing.T) {
290291
}
291292
}
292293

294+
func TestUpdateGameServerConfigurationInFleet(t *testing.T) {
295+
t.Parallel()
296+
297+
alpha1 := framework.AgonesClient.StableV1alpha1()
298+
299+
gsSpec := defaultGameServer().Spec
300+
oldPort := int32(7111)
301+
gsSpec.Ports = []v1alpha1.GameServerPort{{
302+
ContainerPort: oldPort,
303+
Name: "gameport",
304+
PortPolicy: v1alpha1.Dynamic,
305+
Protocol: corev1.ProtocolUDP,
306+
}}
307+
flt := fleetWithGameServerSpec(gsSpec)
308+
flt, err := alpha1.Fleets(defaultNs).Create(flt)
309+
assert.Nil(t, err, "could not create fleet")
310+
defer alpha1.Fleets(defaultNs).Delete(flt.ObjectMeta.Name, nil) // nolint:errcheck
311+
312+
assert.Equal(t, int32(replicasCount), flt.Spec.Replicas)
313+
314+
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(flt.Spec.Replicas))
315+
assert.Nil(t, err, "fleet not ready")
316+
317+
// get an allocation
318+
gsa := &v1alpha1.GameServerAllocation{ObjectMeta: metav1.ObjectMeta{GenerateName: "allocation-"},
319+
Spec: v1alpha1.GameServerAllocationSpec{
320+
Required: metav1.LabelSelector{MatchLabels: map[string]string{v1alpha1.FleetNameLabel: flt.ObjectMeta.Name}},
321+
}}
322+
323+
gsa, err = alpha1.GameServerAllocations(defaultNs).Create(gsa)
324+
assert.Nil(t, err, "cloud not create gameserver allocation")
325+
assert.Equal(t, v1alpha1.GameServerAllocationAllocated, gsa.Status.State)
326+
err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
327+
return fleet.Status.AllocatedReplicas == 1
328+
})
329+
assert.Nil(t, err, "could not allocate a gameserver")
330+
331+
flt, err = framework.AgonesClient.StableV1alpha1().Fleets(defaultNs).Get(flt.Name, metav1.GetOptions{})
332+
assert.Nil(t, err, "could not get fleet")
333+
334+
// Update the configuration of the gameservers of the fleet, i.e. container port.
335+
// The changes should only be rolled out to gameservers in ready state, but not the allocated gameserver.
336+
newPort := int32(7222)
337+
fltCopy := flt.DeepCopy()
338+
fltCopy.Spec.Template.Spec.Ports[0].ContainerPort = newPort
339+
340+
_, err = framework.AgonesClient.StableV1alpha1().Fleets(defaultNs).Update(fltCopy)
341+
assert.Nil(t, err, "could not update fleet")
342+
343+
err = framework.WaitForFleetGameServersCondition(flt, func(gs v1alpha1.GameServer) bool {
344+
containerPort := gs.Spec.Ports[0].ContainerPort
345+
return (gs.Name == gsa.Status.GameServerName && containerPort == oldPort) ||
346+
(gs.Name != gsa.Status.GameServerName && containerPort == newPort)
347+
})
348+
assert.Nil(t, err, "gameservers don't have expected container port")
349+
}
350+
293351
// TestFleetAllocationDuringGameServerDeletion is built to specifically
294352
// test for race conditions of allocations when doing scale up/down,
295-
// rolling updates, etc. Failures my not happen ALL the time -- as that is the
353+
// rolling updates, etc. Failures may not happen ALL the time -- as that is the
296354
// nature of race conditions.
297355
// nolint: dupl
298356
func TestFleetAllocationDuringGameServerDeletion(t *testing.T) {
@@ -416,7 +474,7 @@ func TestFleetAllocationDuringGameServerDeletion(t *testing.T) {
416474

417475
// TestGameServerAllocationDuringGameServerDeletion is built to specifically
418476
// test for race conditions of allocations when doing scale up/down,
419-
// rolling updates, etc. Failures my not happen ALL the time -- as that is the
477+
// rolling updates, etc. Failures may not happen ALL the time -- as that is the
420478
// nature of race conditions.
421479
// nolint: dupl
422480
func TestGameServerAllocationDuringGameServerDeletion(t *testing.T) {
@@ -548,13 +606,17 @@ func scaleFleet(f *v1alpha1.Fleet, scale int32) (*v1alpha1.Fleet, error) {
548606
// defaultFleet returns a default fleet configuration
549607
func defaultFleet() *v1alpha1.Fleet {
550608
gs := defaultGameServer()
609+
return fleetWithGameServerSpec(gs.Spec)
610+
}
551611

612+
// fleetWithGameServerSpec returns a fleet with specified gameserver spec
613+
func fleetWithGameServerSpec(gsSpec v1alpha1.GameServerSpec) *v1alpha1.Fleet {
552614
return &v1alpha1.Fleet{
553615
ObjectMeta: metav1.ObjectMeta{GenerateName: "simple-fleet-", Namespace: defaultNs},
554616
Spec: v1alpha1.FleetSpec{
555617
Replicas: replicasCount,
556618
Template: v1alpha1.GameServerTemplateSpec{
557-
Spec: gs.Spec,
619+
Spec: gsSpec,
558620
},
559621
},
560622
}

0 commit comments

Comments
 (0)