Skip to content

Commit 3c7304d

Browse files
committed
Implements SDK callback for GameServer updates
This implements the gRPC system to send messages up to a unidirectional stream from the sdk-server to the SDK. This has been implemented in the Go, C++ and REST SDK. Closes agones-dev#277
1 parent 84b60d5 commit 3c7304d

31 files changed

Lines changed: 1001 additions & 292 deletions

‎cmd/sdk-server/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func main() {
8686
defer cancel()
8787

8888
if ctlConf.IsLocal {
89-
sdk.RegisterSDKServer(grpcServer, &gameservers.LocalSDKServer{})
89+
sdk.RegisterSDKServer(grpcServer, gameservers.NewLocalSDKServer())
9090
} else {
9191
var config *rest.Config
9292
config, err = rest.InClusterConfig()

‎docs/sdk_rest_api.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,24 @@ Response:
102102
}
103103
}
104104
```
105+
106+
### Watch GameServer
107+
108+
⚠️⚠️⚠️ **/watch/gameserver is currently a development feature and has not been released** ⚠️⚠️⚠️
109+
110+
Call this when you want to get updates of when the backing `GameServer` configuration is updated.
111+
112+
These updates will come as newline delimited JSON, send on each update. To that end, you will
113+
want to keep the http connection open, and read lines from the result stream and and process as they
114+
come in.
115+
116+
```bash
117+
$ curl -H "Content-Type: application/json" -X GET http://localhost:59358/watch/gameserver
118+
```
119+
120+
Response:
121+
```json
122+
{"result":{"object_meta":{"name":"local","namespace":"default","uid":"1234","resource_version":"v1","generation":"1","creation_timestamp":"1533766607","annotations":{"annotation":"true"},"labels":{"islocal":"true"}},"status":{"state":"Ready","address":"127.0.0.1","ports":[{"name":"default","port":7777}]}}}
123+
{"result":{"object_meta":{"name":"local","namespace":"default","uid":"1234","resource_version":"v1","generation":"1","creation_timestamp":"1533766607","annotations":{"annotation":"true"},"labels":{"islocal":"true"}},"status":{"state":"Ready","address":"127.0.0.1","ports":[{"name":"default","port":7777}]}}}
124+
{"result":{"object_meta":{"name":"local","namespace":"default","uid":"1234","resource_version":"v1","generation":"1","creation_timestamp":"1533766607","annotations":{"annotation":"true"},"labels":{"islocal":"true"}},"status":{"state":"Ready","address":"127.0.0.1","ports":[{"name":"default","port":7777}]}}}
125+
```

‎examples/cpp-simple/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ REPOSITORY = gcr.io/agones-images
3232
# Directory that this Makefile is in.
3333
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
3434
project_path := $(dir $(mkfile_path))
35-
server_tag = $(REPOSITORY)/cpp-simple-server:0.2
35+
server_tag = $(REPOSITORY)/cpp-simple-server:0.3
3636

3737
# _____ _
3838
# |_ _|_ _ _ __ __ _ ___| |_ ___

‎examples/cpp-simple/fleet.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ spec:
3030
spec:
3131
containers:
3232
- name: cpp-simple
33-
image: gcr.io/agones-images/cpp-simple-server:0.2
33+
image: gcr.io/agones-images/cpp-simple-server:0.3
3434
# imagePullPolicy: Always # add for development

‎examples/cpp-simple/gameserver.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ spec:
2727
spec:
2828
containers:
2929
- name: cpp-simple
30-
image: gcr.io/agones-images/cpp-simple-server:0.2
30+
image: gcr.io/agones-images/cpp-simple-server:0.3
3131
# imagePullPolicy: Always # add for development

‎examples/cpp-simple/server.cc‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ void doHealth(agones::SDK *sdk) {
3333
}
3434
}
3535

36+
// watch GameServer Updates
37+
void watchUpdates(agones::SDK *sdk) {
38+
std::cout << "Starting to watch GameServer updates..." << std::endl;
39+
sdk->WatchGameServer([](stable::agones::dev::sdk::GameServer gameserver){
40+
std::cout << "GameServer Update, name: " << gameserver.object_meta().name() << std::endl;
41+
std::cout << "GameServer Update, state: " << gameserver.status().state() << std::endl;
42+
});
43+
}
44+
3645
int main() {
3746
std::cout << "C++ Game Server has started!" << std::endl;
3847

@@ -48,6 +57,7 @@ int main() {
4857
std::cout << "...handshake complete." << std::endl;
4958

5059
std::thread health (doHealth, sdk);
60+
std::thread watch (watchUpdates, sdk);
5161

5262
std::cout << "Marking server as ready..." << std::endl;
5363
grpc::Status status = sdk->Ready();

‎examples/simple-udp/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ REPOSITORY = gcr.io/agones-images
2727

2828
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
2929
project_path := $(dir $(mkfile_path))
30-
server_tag = $(REPOSITORY)/udp-server:0.2
30+
server_tag = $(REPOSITORY)/udp-server:0.3
3131
package = agones.dev/agones/examples/simple-udp
3232

3333
# _____ _

‎examples/simple-udp/server/fleet.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ spec:
3131
spec:
3232
containers:
3333
- name: simple-udp
34-
image: gcr.io/agones-images/udp-server:0.2
34+
image: gcr.io/agones-images/udp-server:0.3

‎examples/simple-udp/server/gameserver-legacy.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ spec:
2525
spec:
2626
containers:
2727
- name: simple-udp
28-
image: gcr.io/agones-images/udp-server:0.2
28+
image: gcr.io/agones-images/udp-server:0.3

‎examples/simple-udp/server/gameserver.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ spec:
2525
spec:
2626
containers:
2727
- name: simple-udp
28-
image: gcr.io/agones-images/udp-server:0.2
28+
image: gcr.io/agones-images/udp-server:0.3

0 commit comments

Comments
 (0)