Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for empty ports #2006

Merged
merged 12 commits into from
Mar 9, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ properties:
ports:
title: array of ports to expose on the game server container
type: array
minItems: 1
nullable: true
items:
type: object
properties:
Expand Down
6 changes: 3 additions & 3 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3906,7 +3906,7 @@ spec:
ports:
title: array of ports to expose on the game server container
type: array
minItems: 1
nullable: true
items:
type: object
properties:
Expand Down Expand Up @@ -7777,7 +7777,7 @@ spec:
ports:
title: array of ports to expose on the game server container
type: array
minItems: 1
nullable: true
items:
type: object
properties:
Expand Down Expand Up @@ -11769,7 +11769,7 @@ spec:
ports:
title: array of ports to expose on the game server container
type: array
minItems: 1
nullable: true
items:
type: object
properties:
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/agones/v1/gameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ type GameServerSpec struct {
// container defined
Container string `json:"container,omitempty"`
// Ports are the array of ports that can be exposed via the game server
Ports []GameServerPort `json:"ports"`
Ports []GameServerPort `json:"ports,omitempty"`
// Health configures health checking
Health Health `json:"health,omitempty"`
// Scheduling strategy. Defaults to "Packed"
Expand Down
9 changes: 9 additions & 0 deletions pkg/gameservers/portallocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ func TestPortAllocatorAllocate(t *testing.T) {
assert.Equal(t, "gameport-tcp", gsCopy.Spec.Ports[0].Name)
assert.Equal(t, "gameport-udp", gsCopy.Spec.Ports[1].Name)
assert.Equal(t, 12, countTotalAllocatedPorts(pa))

// no port
gsCopy = fixture.DeepCopy()
gsCopy.Spec.Ports = nil
assert.Len(t, gsCopy.Spec.Ports, 0)
pa.Allocate(gsCopy)
assert.Nil(t, gsCopy.Spec.Ports)
assert.Nil(t, err)
assert.Equal(t, 12, countTotalAllocatedPorts(pa))
})

t.Run("ports are all allocated", func(t *testing.T) {
Expand Down
14 changes: 12 additions & 2 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,18 @@ func (f *Framework) CreateGameServerAndWaitUntilReady(ns string, gs *agonesv1.Ga
return nil, fmt.Errorf("waiting for %v GameServer instance readiness timed out (%v): %v",
gs.Spec, gs.Name, err)
}
if len(readyGs.Status.Ports) == 0 {
return nil, fmt.Errorf("Ready GameServer instance has no port: %v", readyGs.Status)

expectedPortCount := len(gs.Spec.Ports)
if expectedPortCount > 0 {
for _, port := range gs.Spec.Ports {
if port.Protocol == agonesv1.ProtocolTCPUDP {
expectedPortCount++
}
}
}

if len(readyGs.Status.Ports) != expectedPortCount {
return nil, 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
14 changes: 14 additions & 0 deletions test/e2e/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,20 @@ func TestGameServerTcpUdpProtocol(t *testing.T) {
assert.Equal(t, "ACK TCP: Hello World !\n", replyTCP)
}

func TestGameServerWithoutPort(t *testing.T) {
t.Parallel()
gs := framework.DefaultGameServer(framework.Namespace)
gs.Spec.Ports = nil

_, valid := gs.Validate()
assert.True(t, valid)

readyGs, err := framework.CreateGameServerAndWaitUntilReady(framework.Namespace, gs)

require.NoError(t, err, "Could not get a GameServer ready")
assert.Empty(t, readyGs.Spec.Ports)
}

// TestGameServerResourceValidation - check that we are not able to use
// invalid PodTemplate for GameServer Spec with wrong Resource Requests and Limits
func TestGameServerResourceValidation(t *testing.T) {
Expand Down