Skip to content

Commit

Permalink
Implement SDK SetLabel and SetAnnotation functionality
Browse files Browse the repository at this point in the history
This implements new functions in the SDK:

- SetLabel(key, value) - that lets you set a label on the backing `GameServer`
- SetAnnotation(key, value) - that lets you set an annotation on the backing
`GameServer`

All keys are prefixed with "stable.agones.dev/sdk-" to maintain isolation.

Closes googleforgames#279
  • Loading branch information
markmandel committed Aug 21, 2018
1 parent 40ed624 commit b8d2150
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 170 deletions.
6 changes: 4 additions & 2 deletions docs/sdk_rest_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ $ curl -d "{}" -H "Content-Type: application/json" -X POST http://localhost:5935

### Set Label

TODO: write stuff here.
Apply a Label with the prefix "stable.agones.dev/sdk-" to the backing `GameServer` metadata.

See the SDK [SetLabel](../sdks/README.md#setlabelkey-value) documentation for restrictions.

#### Example

Expand All @@ -74,7 +76,7 @@ $ curl -d '{"key": "foo", "value": "bar"}' -H "Content-Type: application/json" -

### Set Annotation

TODO: write stuff here.
Apply a Annotation with the prefix "stable.agones.dev/sdk-" to the backing `GameServer` metadata

#### Example

Expand Down
24 changes: 10 additions & 14 deletions pkg/sdk/sdk.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions sdk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ service SDK {
}

// Apply a Label to the backing GameServer metadata
// TODO: document -- make note that keys and values are alpha, - .
// TODO: e2e test
rpc SetLabel(KeyValue) returns (Empty) {
option (google.api.http) = {
put: "/metadata/label"
Expand All @@ -66,8 +64,6 @@ service SDK {
}

// Apply a Annotation to the backing GameServer metadata
// TODO: document -- make note that keys are alpha, -, .
// TODO: e2e test
rpc SetAnnotation(KeyValue) returns (Empty) {
option (google.api.http) = {
put: "/metadata/annotation"
Expand Down
4 changes: 2 additions & 2 deletions sdk.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"/metadata/annotation": {
"put": {
"summary": "Apply a Annotation to the backing GameServer metadata\nTODO: document",
"summary": "Apply a Annotation to the backing GameServer metadata",
"operationId": "SetAnnotation",
"responses": {
"200": {
Expand All @@ -88,7 +88,7 @@
},
"/metadata/label": {
"put": {
"summary": "Apply a Label to the backing GameServer metadata\nTODO: document",
"summary": "Apply a Label to the backing GameServer metadata",
"operationId": "SetLabel",
"responses": {
"200": {
Expand Down
20 changes: 19 additions & 1 deletion sdks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ This tells Agones to shut down the currently running game server.
The GameServer state will be set `Shutdown` and the
backing Pod will be deleted, if they have not shut themselves down already.

### SetLabel(key, value)
⚠️⚠️⚠️ **`SetLabel` is currently a development feature and has not been released** ⚠️⚠️⚠️

This will set a [Label](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) value on the backing `GameServer`
record that is stored in Kubernetes. To maintain isolation, the `key` value is automatically prefixed with "stable.agones.dev/sdk-"

> Note: There are limits on the characters that be used for label keys and values. Details are [here](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set).
This can be useful if you want to information from your running game server process to be observable or searchable through the Kubernetes API.

### SetAnnotation(key, value)
⚠️⚠️⚠️ **`SetAnnotation` is currently a development feature and has not been released** ⚠️⚠️⚠️

This will set a [Annotation](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/) value on the backing
`Gameserver` record that is stored in Kubernetes. To maintain isolation, the `key` value is automatically prefixed with "stable.agones.dev/sdk-"

This can be useful if you want to information from your running game server process to be observable through the Kubernetes API.

### GameServer()
This returns most of the backing GameServer configuration and Status. This can be useful
for instances where you may want to know Health check configuration, or the IP and Port
Expand All @@ -63,7 +81,7 @@ and the [examples](../examples).

### WatchGameServer(function(gameserver){...})

⚠️⚠️⚠️ **`WatchGameServer` is currently a development feature and has not been released** ⚠️⚠️⚠
⚠️⚠️⚠️ **`WatchGameServer` is currently a development feature and has not been released** ⚠️⚠️⚠

This executes the passed in callback with the current `GameServer` details whenever the underlying `GameServer` configuration is updated.
This can be useful to track `GameServer > Status > State` changes, `metadata` changes, such as labels and annotations, and more.
Expand Down
38 changes: 31 additions & 7 deletions sdks/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,41 @@ if the function completed successfully.
For more information you can also look at the [gRPC Status reference](https://grpc.io/grpc/cpp/classgrpc_1_1_status.html)
```cpp
grpc::Status status = sdk->Shutdown();
if (!status.ok()) { ... }
```

For more information, you can also read the [SDK Overview](../), check out [sdk.h](sdk.h) and also look at the
[C++ example](../../examples/cpp-simple).
To [set a Label](../README.md#setlabelkey-value) on the backing `GameServer` call
`sdk->SetLabel(key, value)`.

⚠️⚠️⚠️ **`SetLabel` is currently a development feature and has not been released** ⚠️⚠️⚠️

This will return a grpc::Status object, from which we can call `status.ok()` to determine
if the function completed successfully.

For more information you can also look at the [gRPC Status reference](https://grpc.io/grpc/cpp/classgrpc_1_1_status.html)

```cpp
grpc::Status status = sdk->SetLabel("test-label", "test-value");
if (!status.ok()) { ... }
```
To [set an Annotation](../README.md#setannotationkey-value) on the backing `GameServer` call
`sdk->SetAnnotation(key, value)`.
⚠️⚠️⚠️ **`SetAnnotation` is currently a development feature and has not been released** ⚠️⚠️⚠️
This will return a grpc::Status object, from which we can call `status.ok()` to determine
if the function completed successfully.
For more information you can also look at the [gRPC Status reference](https://grpc.io/grpc/cpp/classgrpc_1_1_status.html)
```cpp
status = sdk->SetAnnotation("test-annotation", "test value");
if (!status.ok()) { ... }
```


To get the details on the [backing `GameServer`](../README.md#gameserver) call `sdk->GameServer(&gameserver)`,
passing in a `stable::agones::dev::sdk::GameServer*` to push the results of the `GameServer` configuration into.
Expand All @@ -71,10 +98,7 @@ grpc::Status status = sdk->GameServer(&gameserver);
if (!status.ok()) {...}
```
For more information, you can also read the [SDK Overview](../), check out [sdk.h](sdk.h) and also look at the
[C++ example](../../examples/cpp-simple).
To get updates on the [backing `GameServer`](../README.md#gameserver) as they happen,
To get [updates on the backing `GameServer`](../README.md#watchgameserverfunctiongameserver) as they happen,
call `sdk->WatchGameServer([](stable::agones::dev::sdk::GameServer gameserver){...})`.
⚠️⚠️⚠️ **`WatchGameServer` is currently a development feature and has not been released** ⚠️⚠️️⚠️
Expand Down
4 changes: 0 additions & 4 deletions sdks/cpp/sdk.grpc.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions sdks/cpp/sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ namespace agones {
// Marks the Game Server as ready to shutdown
grpc::Status Shutdown();

// Set a label on the current GameServer
// SetLabel sets a metadata label on the `GameServer` with the prefix
// stable.agones.dev/sdk-
grpc::Status SetLabel(std::string key, std::string value);

// Set an Annotation on the current GameServer
// SetAnnotation sets a metadata annotation on the `GameServer` with the prefix
// stable.agones.dev/sdk-
grpc::Status SetAnnotation(std::string key, std::string value);

// Watch the GameServer configuration, and fire the callback
Expand Down
Loading

0 comments on commit b8d2150

Please sign in to comment.