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

simple-udp: added support for customizing labels and annotations by the caller #564

Merged
merged 1 commit into from
Feb 7, 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 @@ -53,7 +53,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.5
GS_TEST_IMAGE ?= gcr.io/agones-images/udp-server:0.6

# 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.5
image: gcr.io/agones-images/udp-server:0.6
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.5
server_tag = $(REPOSITORY)/udp-server:0.6
root_path = $(realpath $(project_path)/../..)

# _____ _
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.5
image: gcr.io/agones-images/udp-server:0.6
resources:
requests:
memory: "64Mi"
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.5
image: gcr.io/agones-images/udp-server:0.6
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.5
image: gcr.io/agones-images/udp-server:0.6
46 changes: 32 additions & 14 deletions examples/simple-udp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

coresdk "agones.dev/agones/pkg/sdk"
"agones.dev/agones/pkg/util/signals"
"agones.dev/agones/sdks/go"
sdk "agones.dev/agones/sdks/go"
)

// main starts a UDP server that received 1024 byte sized packets at at time
Expand Down Expand Up @@ -80,8 +80,9 @@ func readWriteLoop(conn net.PacketConn, stop chan struct{}, s *sdk.SDK) {
b := make([]byte, 1024)
for {
sender, txt := readPacket(conn, b)
switch txt {
parts := strings.Split(strings.TrimSpace(txt), " ")

switch parts[0] {
// shuts down the gameserver
case "EXIT":
exit(s)
Expand All @@ -97,13 +98,31 @@ func readWriteLoop(conn net.PacketConn, stop chan struct{}, s *sdk.SDK) {
watchGameServerEvents(s)

case "LABEL":
setLabel(s)
switch len(parts) {
case 1:
// legacy format
setLabel(s, "timestamp", strconv.FormatInt(time.Now().Unix(), 10))
case 3:
setLabel(s, parts[1], parts[2])
default:
respond(conn, sender, "ERROR: Invalid LABEL command, must use zero or 2 arguments")
continue
}

case "ANNOTATION":
setAnnotation(s)
switch len(parts) {
case 1:
// legacy format
setAnnotation(s, "timestamp", time.Now().UTC().String())
case 3:
setAnnotation(s, parts[1], parts[2])
default:
respond(conn, sender, "ERROR: Invalid ANNOTATION command, must use zero or 2 arguments\n")
continue
}
}

ack(conn, sender, txt)
respond(conn, sender, "ACK: "+txt+"\n")
}
}

Expand All @@ -118,10 +137,9 @@ func readPacket(conn net.PacketConn, b []byte) (net.Addr, string) {
return sender, txt
}

// ack echoes it back, with an ACK
func ack(conn net.PacketConn, sender net.Addr, txt string) {
ack := "ACK: " + txt + "\n"
if _, err := conn.WriteTo([]byte(ack), sender); err != nil {
// respond responds to a given sender.
func respond(conn net.PacketConn, sender net.Addr, txt string) {
if _, err := conn.WriteTo([]byte(txt), sender); err != nil {
log.Fatalf("Could not write to udp stream: %v", err)
}
}
Expand Down Expand Up @@ -172,19 +190,19 @@ func watchGameServerEvents(s *sdk.SDK) {
}

// setAnnotation sets a given annotation
func setAnnotation(s *sdk.SDK) {
log.Print("Setting annotation")
func setAnnotation(s *sdk.SDK, key string, value string) {
log.Printf("Setting annotation %v=%v", key, value)
err := s.SetAnnotation("timestamp", time.Now().UTC().String())
if err != nil {
log.Fatalf("could not set annotation: %v", err)
}
}

// setLabel sets a given label
func setLabel(s *sdk.SDK) {
log.Print("Setting label")
func setLabel(s *sdk.SDK, key, value string) {
log.Printf("Setting label %v=%v", key, value)
// label values can only be alpha, - and .
err := s.SetLabel("timestamp", strconv.FormatInt(time.Now().Unix(), 10))
err := s.SetLabel(key, value)
if err != nil {
log.Fatalf("could not set label: %v", err)
}
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.5
image: gcr.io/agones-images/udp-server:0.6

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 @@ -39,7 +39,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.5
image: gcr.io/agones-images/udp-server:0.6
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 @@ -79,7 +79,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.5
image: gcr.io/agones-images/udp-server:0.6
```

This is the *default* Fleet scheduling strategy. It is designed for dynamic Kubernetes environments, wherein you wish
Expand Down Expand Up @@ -134,7 +134,7 @@ spec:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.5
image: gcr.io/agones-images/udp-server:0.6
```

This Fleet scheduling strategy is designed for static Kubernetes environments, such as when you are running Kubernetes
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.5
Image: gcr.io/agones-images/udp-server:0.6
Name: simple-udp
Resources:
Status:
Expand Down Expand Up @@ -326,7 +326,7 @@ status:
creationTimestamp: null
spec:
containers:
- image: gcr.io/agones-images/udp-server:0.5
- image: gcr.io/agones-images/udp-server:0.6
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.5
Image: gcr.io/agones-images/udp-server:0.6
Name: simple-udp
Resources:
Status:
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 @@ -88,7 +88,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.5"}},
Containers: []corev1.Container{{Name: "udp-server", Image: "gcr.io/agones-images/udp-server:0.6"}},
},
},
},
Expand Down Expand Up @@ -176,7 +176,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.5\",\"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.6\",\"name\":\"simple-udp\"}]}}}}\n"
},
"clusterName": "",
"creationTimestamp": "2018-03-02T21:41:05Z",
Expand Down Expand Up @@ -208,7 +208,7 @@ $ curl http://localhost:8001/apis/stable.agones.dev/v1alpha1/namespaces/default/
"spec": {
"containers": [
{
"image": "gcr.io/agones-images/udp-server:0.5",
"image": "gcr.io/agones-images/udp-server:0.6",
"name": "simple-udp",
"resources": {}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ $ curl -d '{"apiVersion":"stable.agones.dev/v1alpha1","kind":"FleetAllocation","
"spec": {
"containers": [
{
"image": "gcr.io/agones-images/udp-server:0.5",
"image": "gcr.io/agones-images/udp-server:0.6",
"name": "simple-udp",
"resources": {}
}
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 @@ -33,8 +33,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.5",
"gameserver image to use for those tests, gcr.io/agones-images/udp-server:0.5")
gsimage := flag.String("gameserver-image", "gcr.io/agones-images/udp-server:0.6",
"gameserver image to use for those tests, gcr.io/agones-images/udp-server:0.6")
pullSecret := flag.String("pullsecret", "",
"optional secret to be used for pulling the gameserver and/or Agones SDK sidecar images")

Expand Down