diff --git a/pkg/apis/agones/v1/gameserver.go b/pkg/apis/agones/v1/gameserver.go index e8a00696fa..f1aa7b2c7e 100644 --- a/pkg/apis/agones/v1/gameserver.go +++ b/pkg/apis/agones/v1/gameserver.go @@ -578,7 +578,13 @@ func (gss *GameServerSpec) Validate(apiHooks APIHooks, devAddress string, fldPat // make sure the container value points to a valid container if !gss.HasContainer(gss.Container, false) { - allErrs = append(allErrs, field.Invalid(fldPath.Child("container"), gss.Container, "Could not find a container named " + gss.Container)) + allErrs = append(allErrs, + field.Invalid( + fldPath.Child("container"), + gss.Container, + "Could not find a container named "+gss.Container, + ), + ) } // no host port when using dynamic PortPolicy diff --git a/test/e2e/gameserverallocation_test.go b/test/e2e/gameserverallocation_test.go index 02d19e9c73..e8fcfbe8a3 100644 --- a/test/e2e/gameserverallocation_test.go +++ b/test/e2e/gameserverallocation_test.go @@ -1348,29 +1348,42 @@ func TestGameServerAllocationReturnLabels(t *testing.T) { flt.Spec.Replicas = 1 flt.Spec.Template.ObjectMeta.Labels = label flt.Spec.Template.ObjectMeta.Annotations = annotations + flt, err := fleets.Create(ctx, flt, metav1.CreateOptions{}) - defer fleets.Delete(ctx, flt.ObjectMeta.Name, metav1.DeleteOptions{}) // nolint:errcheck require.NoError(t, err) + defer fleets.Delete(ctx, flt.ObjectMeta.Name, metav1.DeleteOptions{}) // nolint framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas)) - gsa := &allocationv1.GameServerAllocation{ObjectMeta: metav1.ObjectMeta{GenerateName: "allocation-"}, + gsa := &allocationv1.GameServerAllocation{ + ObjectMeta: metav1.ObjectMeta{ + GenerateName: "allocation-", + }, Spec: allocationv1.GameServerAllocationSpec{ Selectors: []allocationv1.GameServerSelector{ - {LabelSelector: metav1.LabelSelector{MatchLabels: label}}, + { + LabelSelector: metav1.LabelSelector{ + MatchLabels: label, + }, + }, }, - }} + }, + } - gsa, err = framework.AgonesClient.AllocationV1().GameServerAllocations(framework.Namespace).Create(ctx, gsa.DeepCopy(), metav1.CreateOptions{}) - require.NoError(t, err) + require.EventuallyWithT(t, func(c *assert.CollectT) { + currGsa, err := framework.AgonesClient.AllocationV1().GameServerAllocations(framework.Namespace).Create(ctx, gsa.DeepCopy(), metav1.CreateOptions{}) - assert.Equal(t, allocationv1.GameServerAllocationAllocated, gsa.Status.State) - assert.Equal(t, t.Name(), gsa.Status.Metadata.Labels[role]) - assert.Equal(t, flt.ObjectMeta.Name, gsa.Status.Metadata.Labels[agonesv1.FleetNameLabel]) - assert.Equal(t, annotationValue, gsa.Status.Metadata.Annotations[annotationKey]) - gs, err := gameServers.Get(ctx, gsa.Status.GameServerName, metav1.GetOptions{}) - require.NoError(t, err) - assert.Equal(t, flt.ObjectMeta.Name, gs.ObjectMeta.Labels[agonesv1.FleetNameLabel]) + require.NoError(c, err, "API call to allocate should not fail") + require.Equal(c, allocationv1.GameServerAllocationAllocated, currGsa.Status.State, "Allocation should be 'Allocated' state") + require.NotEmpty(c, currGsa.Status.GameServerName, "Allocated GS name should not be empty") + require.Equal(c, t.Name(), currGsa.Status.Metadata.Labels[role], "Role label should match test name") + require.Equal(c, flt.ObjectMeta.Name, currGsa.Status.Metadata.Labels[agonesv1.FleetNameLabel], "Fleet name label should match") + require.Equal(c, annotationValue, currGsa.Status.Metadata.Annotations[annotationKey], "Annotation value should match") + + gs, err := gameServers.Get(ctx, currGsa.Status.GameServerName, metav1.GetOptions{}) + require.NoError(c, err, "Should be able to get the allocated GameServer") + require.Equal(c, flt.ObjectMeta.Name, gs.ObjectMeta.Labels[agonesv1.FleetNameLabel], "Fleet name label should match") + }, 30*time.Second, 1*time.Second) } func TestGameServerAllocationDeletionOnUnAllocate(t *testing.T) {