diff --git a/examples/simple-udp/server/Dockerfile b/examples/simple-udp/Dockerfile similarity index 72% rename from examples/simple-udp/server/Dockerfile rename to examples/simple-udp/Dockerfile index 3b22c41205..fe69050e20 100644 --- a/examples/simple-udp/server/Dockerfile +++ b/examples/simple-udp/Dockerfile @@ -12,12 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +# build +FROM golang:1.10.3 as builder +WORKDIR /go/src/simple-udp + +COPY examples/simple-udp/main.go . +COPY . /go/src/agones.dev/agones +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server . + +# final image FROM alpine:3.7 RUN adduser -D server - -COPY ./bin/server /home/server/server - +COPY --from=builder /go/src/simple-udp/server /home/server/server RUN chown -R server /home/server && \ chmod o+x /home/server/server diff --git a/examples/simple-udp/Makefile b/examples/simple-udp/Makefile index e5da71b956..d93f3ea026 100644 --- a/examples/simple-udp/Makefile +++ b/examples/simple-udp/Makefile @@ -28,7 +28,7 @@ REPOSITORY = gcr.io/agones-images mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) project_path := $(dir $(mkfile_path)) server_tag = $(REPOSITORY)/udp-server:0.3 -package = agones.dev/agones/examples/simple-udp +root_path = $(realpath $(project_path)/../..) # _____ _ # |_ _|_ _ _ __ __ _ ___| |_ ___ @@ -37,19 +37,6 @@ package = agones.dev/agones/examples/simple-udp # |_|\__,_|_| \__, |\___|\__|___/ # |___/ -# build both client and server -build: build-server build-client - -# Build the server -build-server: - CGO_ENABLED=0 go build -o $(project_path)/server/bin/server -a -installsuffix cgo $(package)/server - # Build a docker image for the server, and tag it -build-server-image: - docker build $(project_path)/server/ --tag=$(server_tag) - -# Build the client -build-client: - go build -o $(project_path)/client/bin/client $(package)/client - - +build: + cd $(root_path) && docker build -f $(project_path)/Dockerfile --tag=$(server_tag) . diff --git a/examples/simple-udp/README.md b/examples/simple-udp/README.md index b76db6824a..6bec758f01 100644 --- a/examples/simple-udp/README.md +++ b/examples/simple-udp/README.md @@ -1,6 +1,6 @@ # Simple UDP Server -A very simple UDP logging server and client, for the purposes of demoing and testing +A very simple UDP logging server, for the purposes of demoing and testing running a UDP based server on Agones. ## Server @@ -10,7 +10,5 @@ When it receives a text packet, it will send back "ACK:" as an ech If it receives the text "EXIT", then it will `sys.Exit(0)` -## Client -Client will read in from stdin and send each line to the server. - -Address defaults to `localhost:7654` but can be changed through the `address` flag. +To learn how to deploy your edited version of go server to gcp, please check out this link: [Edit Your First Game Server (Go)](../../../docs/edit_first_game_server.md), +or also look at the [`Makefile`](./Makefile). diff --git a/examples/simple-udp/client/main.go b/examples/simple-udp/client/main.go deleted file mode 100644 index 636aebb08a..0000000000 --- a/examples/simple-udp/client/main.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package main implements a client that reads a line -// from stdin and then sends it as a UDP packet to the -// -address flag -package main - -import ( - "bufio" - "flag" - "fmt" - "log" - "net" - "os" -) - -const ( - bufferSize = 1024 -) - -var ( - maxMessageSize = bufferSize - len([]byte("ACK: ")) -) - -// Program client reads a line in from stdin and sends it to a server as a UDP packet. -func main() { - address := flag.String("address", "localhost:7654", "The address to send the UDP packets to") - flag.Parse() - - log.Printf("Starting client, connecting to %s", *address) - conn, err := net.Dial("udp", *address) - if err != nil { - log.Fatalf("Could not connect: %v", err) - } - - defer func() { - err = conn.Close() - if err != nil { - log.Fatalf("Could not close connection: %v", err) - } - }() - - go func() { - b := make([]byte, bufferSize) - for { - n, errRead := conn.Read(b) - if errRead != nil { - log.Fatalf("Could not read packet: %v", errRead) - } - log.Printf("Received Packet: %s", b[:n]) - } - }() - - scanner := bufio.NewScanner(os.Stdin) - fmt.Print(">> Send Line: ") - for scanner.Scan() { - line := scanner.Bytes() - len := len(line) - - if len > maxMessageSize { - log.Printf("Messages cannot be larger than the buffer of %d bytes. Please try again.", maxMessageSize) - continue - } - - log.Printf("Sending %d bytes string %s via UDP", len, line) - _, err = conn.Write(line) - if err != nil { - log.Fatalf("Could not write line %s to %s: %v", line, *address, err) - } - - fmt.Print(">> Send Line: ") - } -} diff --git a/examples/simple-udp/server/fleet.yaml b/examples/simple-udp/fleet.yaml similarity index 100% rename from examples/simple-udp/server/fleet.yaml rename to examples/simple-udp/fleet.yaml diff --git a/examples/simple-udp/server/fleetallocation.yaml b/examples/simple-udp/fleetallocation.yaml similarity index 100% rename from examples/simple-udp/server/fleetallocation.yaml rename to examples/simple-udp/fleetallocation.yaml diff --git a/examples/simple-udp/server/gameserver.yaml b/examples/simple-udp/gameserver.yaml similarity index 100% rename from examples/simple-udp/server/gameserver.yaml rename to examples/simple-udp/gameserver.yaml diff --git a/examples/simple-udp/server/gameserverset.yaml b/examples/simple-udp/gameserverset.yaml similarity index 100% rename from examples/simple-udp/server/gameserverset.yaml rename to examples/simple-udp/gameserverset.yaml diff --git a/examples/simple-udp/server/main.go b/examples/simple-udp/main.go similarity index 98% rename from examples/simple-udp/server/main.go rename to examples/simple-udp/main.go index fc73a6a925..23632a7785 100644 --- a/examples/simple-udp/server/main.go +++ b/examples/simple-udp/main.go @@ -1,4 +1,4 @@ -// Copyright 2017 Google Inc. All Rights Reserved. +// Copyright 2018 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/examples/simple-udp/server/README.md b/examples/simple-udp/server/README.md deleted file mode 100644 index 1e7aa7b4a2..0000000000 --- a/examples/simple-udp/server/README.md +++ /dev/null @@ -1 +0,0 @@ -To learn how to deploy your edited version of go server to gcp, please check out this link: [Edit Your First Game Server (Go)](../../../docs/edit_first_game_server.md) diff --git a/examples/simple-udp/server/gameserver-legacy.yaml b/examples/simple-udp/server/gameserver-legacy.yaml deleted file mode 100644 index 8fa5fd67f7..0000000000 --- a/examples/simple-udp/server/gameserver-legacy.yaml +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2018 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This will be removed in 0.4.0 - -apiVersion: "stable.agones.dev/v1alpha1" -kind: GameServer -metadata: - name: "simple-udp" -spec: - portPolicy: "dynamic" - containerPort: 7654 - template: - spec: - containers: - - name: simple-udp - image: gcr.io/agones-images/udp-server:0.3 \ No newline at end of file diff --git a/pkg/apis/stable/v1alpha1/fleet_test.go b/pkg/apis/stable/v1alpha1/fleet_test.go index 571e01fb50..46e13eb3a0 100644 --- a/pkg/apis/stable/v1alpha1/fleet_test.go +++ b/pkg/apis/stable/v1alpha1/fleet_test.go @@ -34,7 +34,7 @@ func TestFleetGameServerSetGameServer(t *testing.T) { Replicas: 10, Template: GameServerTemplateSpec{ Spec: GameServerSpec{ - GameServerPort: &GameServerPort{ContainerPort: 1234}, + Ports: []GameServerPort{{ContainerPort: 1234}}, Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ Containers: []corev1.Container{{Name: "container", Image: "myimage"}}, diff --git a/pkg/apis/stable/v1alpha1/gameserver.go b/pkg/apis/stable/v1alpha1/gameserver.go index cee4890bb6..47d5329605 100644 --- a/pkg/apis/stable/v1alpha1/gameserver.go +++ b/pkg/apis/stable/v1alpha1/gameserver.go @@ -110,8 +110,6 @@ type GameServerSpec struct { // Container specifies which Pod container is the game server. Only required if there is more than one // container defined Container string `json:"container,omitempty"` - // GameServerPort is deprecated, to be removed in 0.4.0: - *GameServerPort `json:",inline,omitempty"` // Ports are the array of ports that can be exposed via the game server Ports []GameServerPort `json:"ports"` // Health configures health checking @@ -178,7 +176,6 @@ func (gs *GameServer) ApplyDefaults() { gs.ObjectMeta.Finalizers = append(gs.ObjectMeta.Finalizers, stable.GroupName) gs.applyContainerDefaults() - gs.applyLegacyConversion() gs.applyPortDefaults() gs.applyStateDefaults() gs.applyHealthDefaults() @@ -216,14 +213,6 @@ func (gs *GameServer) applyStateDefaults() { } } -// applyLegacyConversion applies the legacy conversion -func (gs *GameServer) applyLegacyConversion() { - if gs.Spec.GameServerPort != nil { - gs.Spec.Ports = append(gs.Spec.Ports, *gs.Spec.GameServerPort) - gs.Spec.GameServerPort = nil - } -} - // applyPortDefaults applies default values for all ports func (gs *GameServer) applyPortDefaults() { for i, p := range gs.Spec.Ports { diff --git a/pkg/apis/stable/v1alpha1/gameserver_test.go b/pkg/apis/stable/v1alpha1/gameserver_test.go index 7848497df6..327e8a9b8d 100644 --- a/pkg/apis/stable/v1alpha1/gameserver_test.go +++ b/pkg/apis/stable/v1alpha1/gameserver_test.go @@ -89,10 +89,10 @@ func TestGameServerApplyDefaults(t *testing.T) { gameServer: GameServer{ Spec: GameServerSpec{ Container: "testing2", - GameServerPort: &GameServerPort{ + Ports: []GameServerPort{{ Protocol: "TCP", PortPolicy: Static, - }, + }}, Health: Health{ Disabled: false, PeriodSeconds: 12, @@ -123,7 +123,7 @@ func TestGameServerApplyDefaults(t *testing.T) { "set basic defaults on static gameserver": { gameServer: GameServer{ Spec: GameServerSpec{ - GameServerPort: &GameServerPort{PortPolicy: Static}, + Ports: []GameServerPort{{PortPolicy: Static}}, Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{Containers: []corev1.Container{{Name: "testing", Image: "testing/image"}}}}}, }, @@ -161,11 +161,13 @@ func TestGameServerApplyDefaults(t *testing.T) { "convert from legacy single port to multiple": { gameServer: GameServer{ Spec: GameServerSpec{ - GameServerPort: &GameServerPort{ - ContainerPort: 777, - HostPort: 777, - PortPolicy: Static, - Protocol: corev1.ProtocolTCP, + Ports: []GameServerPort{ + { + ContainerPort: 777, + HostPort: 777, + PortPolicy: Static, + Protocol: corev1.ProtocolTCP, + }, }, Health: Health{Disabled: true}, Template: corev1.PodTemplateSpec{ @@ -235,10 +237,12 @@ func TestGameServerValidate(t *testing.T) { func TestGameServerPod(t *testing.T) { fixture := &GameServer{ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default", UID: "1234"}, Spec: GameServerSpec{ - GameServerPort: &GameServerPort{ - ContainerPort: 7777, - HostPort: 9999, - PortPolicy: Static, + Ports: []GameServerPort{ + { + ContainerPort: 7777, + HostPort: 9999, + PortPolicy: Static, + }, }, Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ diff --git a/pkg/apis/stable/v1alpha1/gameserverset_test.go b/pkg/apis/stable/v1alpha1/gameserverset_test.go index a532454978..20834baaf2 100644 --- a/pkg/apis/stable/v1alpha1/gameserverset_test.go +++ b/pkg/apis/stable/v1alpha1/gameserverset_test.go @@ -33,7 +33,7 @@ func TestGameServerSetGameServer(t *testing.T) { Replicas: 10, Template: GameServerTemplateSpec{ Spec: GameServerSpec{ - GameServerPort: &GameServerPort{ContainerPort: 1234}, + Ports: []GameServerPort{{ContainerPort: 1234}}, Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ Containers: []corev1.Container{{Name: "container", Image: "myimage"}}, @@ -59,7 +59,7 @@ func TestGameServerSetValidateUpdate(t *testing.T) { Spec: GameServerSetSpec{ Replicas: 10, Template: GameServerTemplateSpec{ - Spec: GameServerSpec{GameServerPort: &GameServerPort{ContainerPort: 1234}}, + Spec: GameServerSpec{Ports: []GameServerPort{{ContainerPort: 1234}}}, }, }, } @@ -74,7 +74,7 @@ func TestGameServerSetValidateUpdate(t *testing.T) { assert.True(t, ok) assert.Empty(t, causes) - newGSS.Spec.Template.Spec.ContainerPort = 321 + newGSS.Spec.Template.Spec.Ports[0].ContainerPort = 321 ok, causes = gsSet.ValidateUpdate(newGSS) assert.False(t, ok) assert.Len(t, causes, 1) diff --git a/pkg/apis/stable/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/stable/v1alpha1/zz_generated.deepcopy.go index 6fd9485633..3d4d665278 100644 --- a/pkg/apis/stable/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/stable/v1alpha1/zz_generated.deepcopy.go @@ -426,15 +426,6 @@ func (in *GameServerSetStatus) DeepCopy() *GameServerSetStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GameServerSpec) DeepCopyInto(out *GameServerSpec) { *out = *in - if in.GameServerPort != nil { - in, out := &in.GameServerPort, &out.GameServerPort - if *in == nil { - *out = nil - } else { - *out = new(GameServerPort) - **out = **in - } - } if in.Ports != nil { in, out := &in.Ports, &out.Ports *out = make([]GameServerPort, len(*in))