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

E2E test for Ready->Allocated->Ready #834

Merged
merged 2 commits into from
Jun 18, 2019
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
2 changes: 1 addition & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ KIND_PROFILE ?= agones
KIND_CONTAINER_NAME=kind-$(KIND_PROFILE)-control-plane

# Game Server image to use while doing end-to-end tests
GS_TEST_IMAGE ?= gcr.io/agones-images/udp-server:0.10
GS_TEST_IMAGE ?= gcr.io/agones-images/udp-server:0.11

# Directory that this Makefile is in.
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
Expand Down
2 changes: 1 addition & 1 deletion examples/fleet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11
2 changes: 1 addition & 1 deletion examples/simple-udp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ REPOSITORY = gcr.io/agones-images

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
project_path := $(dir $(mkfile_path))
server_tag = $(REPOSITORY)/udp-server:0.10
server_tag = $(REPOSITORY)/udp-server:0.11
root_path = $(realpath $(project_path)/../..)

# _____ _
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-udp/fleet-distributed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11
resources:
requests:
memory: "32Mi"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-udp/fleet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11
resources:
requests:
memory: "64Mi"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-udp/gameserver-passthrough.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11
env:
- name: "PASSTHROUGH"
value: "TRUE"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-udp/gameserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11
resources:
requests:
memory: "32Mi"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-udp/gameserverset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11
19 changes: 13 additions & 6 deletions examples/simple-udp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ func main() {
defer conn.Close() // nolint: errcheck

log.Print("Marking this server as ready")
// This tells Agones that the server is ready to receive connections.
err = s.Ready()
if err != nil {
log.Fatalf("Could not send ready message")
}
ready(s)

readWriteLoop(conn, stop, s)
}
Expand Down Expand Up @@ -112,6 +108,9 @@ func readWriteLoop(conn net.PacketConn, stop chan struct{}, s *sdk.SDK) {
case "GAMESERVER":
writeGameServerName(s, conn, sender)

case "READY":
ready(s)

case "ALLOCATE":
allocate(s)

Expand Down Expand Up @@ -147,7 +146,15 @@ func readWriteLoop(conn net.PacketConn, stop chan struct{}, s *sdk.SDK) {
}
}

// allocate attemps to allocate this gameserver
// ready attempts to mark this gameserver as ready
func ready(s *sdk.SDK) {
err := s.Ready()
if err != nil {
log.Fatalf("Could not send ready message")
}
}

// allocate attempts to allocate this gameserver
func allocate(s *sdk.SDK) {
err := s.Allocate()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion install/helm/agones/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11

Finally don't forget to explore our documentation and usage guides on how to develop and host dedicated game servers on top of Agones. :

Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/Advanced/limiting-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11
resources:
limit:
cpu: "250m" #this is our limit here
Expand Down
4 changes: 2 additions & 2 deletions site/content/en/docs/Advanced/scheduling-and-autoscaling.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11
```
This is the *default* Fleet scheduling strategy. It is designed for dynamic Kubernetes environments, wherein you wish
Expand Down Expand Up @@ -135,7 +135,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11
```

This Fleet scheduling strategy is designed for static Kubernetes environments, such as when you are running Kubernetes
Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/Advanced/service-accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
serviceAccountName: my-special-service-account # a custom service account
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.10
image: gcr.io/agones-images/udp-server:0.11
```
If a service account is configured, the mounted key is not overwritten, as it assumed that you want to have full control
Expand Down
4 changes: 2 additions & 2 deletions site/content/en/docs/Getting Started/create-fleet.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Spec:
Creation Timestamp: <nil>
Spec:
Containers:
Image: gcr.io/agones-images/udp-server:0.10
Image: gcr.io/agones-images/udp-server:0.11
Name: simple-udp
Resources:
Status:
Expand Down Expand Up @@ -308,7 +308,7 @@ status:
creationTimestamp: null
spec:
containers:
- image: gcr.io/agones-images/udp-server:0.10
- image: gcr.io/agones-images/udp-server:0.11
name: simple-udp
resources: {}
status:
Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/Getting Started/create-gameserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Spec:
Creation Timestamp: <nil>
Spec:
Containers:
Image: gcr.io/agones-images/udp-server:0.10
Image: gcr.io/agones-images/udp-server:0.11
Name: simple-udp
Resources:
Limits:
Expand Down
8 changes: 4 additions & 4 deletions site/content/en/docs/Guides/access-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func main() {
Spec: v1alpha1.GameServerSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{{Name: "udp-server", Image: "gcr.io/agones-images/udp-server:0.10"}},
Containers: []corev1.Container{{Name: "udp-server", Image: "gcr.io/agones-images/udp-server:0.11"}},
},
},
},
Expand Down Expand Up @@ -178,7 +178,7 @@ $ curl http://localhost:8001/apis/stable.agones.dev/v1alpha1/namespaces/default/
"kind": "GameServer",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"stable.agones.dev/v1alpha1\",\"kind\":\"GameServer\",\"metadata\":{\"annotations\":{},\"name\":\"simple-udp\",\"namespace\":\"default\"},\"spec\":{\"containerPort\":7654,\"hostPort\":7777,\"portPolicy\":\"static\",\"template\":{\"spec\":{\"containers\":[{\"image\":\"gcr.io/agones-images/udp-server:0.10\",\"name\":\"simple-udp\"}]}}}}\n"
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"stable.agones.dev/v1alpha1\",\"kind\":\"GameServer\",\"metadata\":{\"annotations\":{},\"name\":\"simple-udp\",\"namespace\":\"default\"},\"spec\":{\"containerPort\":7654,\"hostPort\":7777,\"portPolicy\":\"static\",\"template\":{\"spec\":{\"containers\":[{\"image\":\"gcr.io/agones-images/udp-server:0.11\",\"name\":\"simple-udp\"}]}}}}\n"
},
"clusterName": "",
"creationTimestamp": "2018-03-02T21:41:05Z",
Expand Down Expand Up @@ -210,7 +210,7 @@ $ curl http://localhost:8001/apis/stable.agones.dev/v1alpha1/namespaces/default/
"spec": {
"containers": [
{
"image": "gcr.io/agones-images/udp-server:0.10",
"image": "gcr.io/agones-images/udp-server:0.11",
"name": "simple-udp",
"resources": {}
}
Expand Down Expand Up @@ -317,7 +317,7 @@ $ curl -d '{"apiVersion":"stable.agones.dev/v1alpha1","kind":"FleetAllocation","
"spec": {
"containers": [
{
"image": "gcr.io/agones-images/udp-server:0.10",
"image": "gcr.io/agones-images/udp-server:0.11",
"name": "simple-udp",
"resources": {}
}
Expand Down
16 changes: 7 additions & 9 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ func (f *Framework) CreateGameServerAndWaitUntilReady(ns string, gs *stable.Game
// WaitForGameServerState Waits untils the gameserver reach a given state before the timeout expires
func (f *Framework) WaitForGameServerState(gs *stable.GameServer, state stable.GameServerState,
timeout time.Duration) (*stable.GameServer, error) {
var pollErr error
var readyGs *stable.GameServer

err := wait.PollImmediate(2*time.Second, timeout, func() (bool, error) {
readyGs, pollErr = f.AgonesClient.StableV1alpha1().GameServers(gs.Namespace).Get(gs.Name, metav1.GetOptions{})
var err error
readyGs, err = f.AgonesClient.StableV1alpha1().GameServers(gs.Namespace).Get(gs.Name, metav1.GetOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readyGs, err := ...
and remove var err error?


if pollErr != nil {
logrus.WithError(pollErr).Warn("error retrieving gameserver")
if err != nil {
logrus.WithError(err).Warn("error retrieving gameserver")
return false, nil
}

Expand All @@ -120,11 +120,9 @@ func (f *Framework) WaitForGameServerState(gs *stable.GameServer, state stable.G

return false, nil
})
if err != nil {
return nil, errors.Wrapf(pollErr, "waiting for GameServer to be %v %v/%v: %v",
state, gs.Namespace, gs.Name, err)
}
return readyGs, nil

return readyGs, errors.Wrapf(err, "waiting for GameServer to be %v %v/%v",
state, gs.Namespace, gs.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would replace your previous change. pollErr is replaced with err which is local to the PollImmediate method.
err := wait.PollImmediate --> this error will still be timeout as it is different that the err inside PollImmediate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was my intent with this change. I'm saying I don't think we need to do replace err with pollErr at all.

The original code was in place to make the pollErr error visible, in case it is the cause of the test failing -- but we already have logging in place to show that error, so it seems redundant to do do both logging and bubble the error up.

If we remove the bubble up, the code is cleaner, and we don't sacrifice the ability to discover the reasons for issues.

At least - that is my intent 😄

}

// 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.
Expand Down
36 changes: 28 additions & 8 deletions test/e2e/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,38 @@ func TestGameServerSelfAllocate(t *testing.T) {
}

assert.Equal(t, "ACK: ALLOCATE\n", reply)
gs, err = framework.WaitForGameServerState(readyGs, v1alpha1.GameServerStateAllocated, time.Minute)
assert.NoError(t, err)
assert.Equal(t, v1alpha1.GameServerStateAllocated, gs.Status.State)
}

// the label is set in a queue, so it may take a moment
err = wait.PollImmediate(time.Second, 10*time.Second, func() (bool, error) {
gs, err = framework.AgonesClient.StableV1alpha1().GameServers(defaultNs).Get(readyGs.ObjectMeta.Name, metav1.GetOptions{})
if err != nil {
return true, err
}
func TestGameServerReadyAllocateReady(t *testing.T) {
t.Parallel()
gs := defaultGameServer()
readyGs, err := framework.CreateGameServerAndWaitUntilReady(defaultNs, gs)
if err != nil {
t.Fatalf("Could not get a GameServer ready: %v", err)
}
defer framework.AgonesClient.StableV1alpha1().GameServers(defaultNs).Delete(readyGs.ObjectMeta.Name, nil) // nolint: errcheck
assert.Equal(t, readyGs.Status.State, v1alpha1.GameServerStateReady)

return gs.Status.State == v1alpha1.GameServerStateAllocated, nil
})
reply, err := e2eframework.SendGameServerUDP(readyGs, "ALLOCATE")
if err != nil {
t.Fatalf("Could not message GameServer: %v", err)
}
assert.Equal(t, "ACK: ALLOCATE\n", reply)
gs, err = framework.WaitForGameServerState(readyGs, v1alpha1.GameServerStateAllocated, time.Minute)
assert.NoError(t, err)
assert.Equal(t, v1alpha1.GameServerStateAllocated, gs.Status.State)

reply, err = e2eframework.SendGameServerUDP(readyGs, "READY")
if !assert.NoError(t, err) {
assert.FailNow(t, "Could not message GameServer")
}
assert.Equal(t, "ACK: READY\n", reply)
gs, err = framework.WaitForGameServerState(gs, v1alpha1.GameServerStateReady, time.Minute)
assert.NoError(t, err)
assert.Equal(t, v1alpha1.GameServerStateReady, gs.Status.State)
}

func TestGameServerShutdown(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/gameserverallocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ func TestGameServerAllocationPreferredSelection(t *testing.T) {
}

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

allocations := framework.AgonesClient.AllocationV1alpha1().GameServerAllocations(defaultNs)

gsa := &v1alpha1.GameServerAllocation{ObjectMeta: metav1.ObjectMeta{GenerateName: "allocation-"},
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestMain(m *testing.M) {
usr, _ := user.Current()
kubeconfig := flag.String("kubeconfig", filepath.Join(usr.HomeDir, "/.kube/config"),
"kube config path, e.g. $HOME/.kube/config")
gsimage := flag.String("gameserver-image", "gcr.io/agones-images/udp-server:0.10",
"gameserver image to use for those tests, gcr.io/agones-images/udp-server:0.10")
gsimage := flag.String("gameserver-image", "gcr.io/agones-images/udp-server:0.11",
"gameserver image to use for those tests, gcr.io/agones-images/udp-server:0.11")
pullSecret := flag.String("pullsecret", "",
"optional secret to be used for pulling the gameserver and/or Agones SDK sidecar images")
stressTestLevel := flag.Int("stress", 0, "enable stress test at given level 0-100")
Expand Down
1 change: 1 addition & 0 deletions test/e2e/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func externalPort(svc *corev1.Service, port corev1.ServicePort) (int32, error) {
}

func TestPingUDP(t *testing.T) {
t.Parallel()
kubeCore := framework.KubeClient.CoreV1()
svc, err := kubeCore.Services("agones-system").Get("agones-ping-udp-service", metav1.GetOptions{})
assert.Nil(t, err)
Expand Down