Skip to content

Commit 0f376ea

Browse files
authored
Alpha GameServer attributes added to SDK (agones-dev#1440)
* Alpha GameServer attributes added to SDK Rather than recreating SDK.GameServer() and SDK.WatchGameServer() in the alpha SDK, I thought it would be easiest both in the short and long term to mimic what we have done in the GameServer CRD, and populate the Alpha attributes from these SDK methods when the feature flag for Player Tracking is enabled. This is done by adding logic to the conversion function that converts the K8s GameServer definition into the SDK GameServer definition. This includes regenerated gRPC code for the supported clients. I also had to fix the line endings in the C# gen.sh, so including that in this PR. * Update based on review
1 parent 6f5edc0 commit 0f376ea

13 files changed

Lines changed: 1683 additions & 235 deletions

File tree

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
#!/usr/bin/env bash
2-
3-
# Copyright 2020 Google LLC All Rights Reserved.
4-
#
5-
# Licensed under the Apache License, Version 2.0 (the "License");
6-
# you may not use this file except in compliance with the License.
7-
# You may obtain a copy of the License at
8-
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing, software
12-
# distributed under the License is distributed on an "AS IS" BASIS,
13-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
# See the License for the specific language governing permissions and
15-
# limitations under the License.
16-
17-
set -ex
18-
19-
sdk=/go/src/agones.dev/agones/proto/sdk
20-
googleapis=/go/src/agones.dev/agones/proto/googleapis
21-
protoc_destination=/go/src/agones.dev/agones/sdks/csharp/sdk/generated
22-
23-
# Generate C# proto file `Sdk.cs`
24-
protoc --csharp_out=${protoc_destination} -I ${sdk} -I ${googleapis} --plugin=protoc-gen-grpc=`which grpc_csharp_plugin` sdk.proto
25-
# Generate proto stub?
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2020 Google LLC All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -ex
18+
19+
sdk=/go/src/agones.dev/agones/proto/sdk
20+
googleapis=/go/src/agones.dev/agones/proto/googleapis
21+
protoc_destination=/go/src/agones.dev/agones/sdks/csharp/sdk/generated
22+
23+
# Generate C# proto file `Sdk.cs`
24+
protoc --csharp_out=${protoc_destination} -I ${sdk} -I ${googleapis} --plugin=protoc-gen-grpc=`which grpc_csharp_plugin` sdk.proto
25+
# Generate proto stub?
2626
protoc --grpc_out=${protoc_destination} -I ${sdk} -I ${googleapis} --plugin=protoc-gen-grpc=`which grpc_csharp_plugin` sdk.proto

‎pkg/sdk/sdk.pb.go‎

Lines changed: 134 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/sdkserver/sdk.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package sdkserver
1717
import (
1818
agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
1919
"agones.dev/agones/pkg/sdk"
20+
"agones.dev/agones/pkg/util/runtime"
2021
)
2122

2223
const (
@@ -66,5 +67,14 @@ func convert(gs *agonesv1.GameServer) *sdk.GameServer {
6667
result.Status.Ports = append(result.Status.Ports, grpcPort)
6768
}
6869

70+
if runtime.FeatureEnabled(runtime.FeaturePlayerTracking) {
71+
if gs.Status.Players != nil {
72+
result.Status.Players = &sdk.GameServer_Status_PlayerStatus{
73+
Count: gs.Status.Players.Count,
74+
Capacity: gs.Status.Players.Capacity,
75+
}
76+
}
77+
}
78+
6979
return result
7080
}

‎pkg/sdkserver/sdk_test.go‎

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ import (
1919

2020
agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
2121
"agones.dev/agones/pkg/sdk"
22+
"agones.dev/agones/pkg/util/runtime"
2223
"github.com/stretchr/testify/assert"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
)
2526

2627
func TestConvert(t *testing.T) {
2728
t.Parallel()
2829

30+
runtime.FeatureTestMutex.Lock()
31+
defer runtime.FeatureTestMutex.Unlock()
32+
2933
fixture := &agonesv1.GameServer{
3034
ObjectMeta: metav1.ObjectMeta{
3135
CreationTimestamp: metav1.Now(),
@@ -75,13 +79,37 @@ func TestConvert(t *testing.T) {
7579
}
7680
}
7781

78-
sdkGs := convert(fixture)
79-
eq(t, fixture, sdkGs)
80-
assert.Zero(t, sdkGs.ObjectMeta.DeletionTimestamp)
82+
t.Run(string(runtime.FeaturePlayerTracking)+" disabled", func(t *testing.T) {
83+
assert.NoError(t, runtime.ParseFeatures(""))
84+
85+
gs := fixture.DeepCopy()
86+
87+
sdkGs := convert(gs)
88+
eq(t, fixture, sdkGs)
89+
assert.Zero(t, sdkGs.ObjectMeta.DeletionTimestamp)
90+
assert.Nil(t, sdkGs.Status.Players)
91+
})
92+
93+
t.Run(string(runtime.FeaturePlayerTracking)+" enabled", func(t *testing.T) {
94+
assert.NoError(t, runtime.ParseFeatures(string(runtime.FeaturePlayerTracking)+"=true"))
95+
96+
gs := fixture.DeepCopy()
97+
gs.Status.Players = &agonesv1.PlayerStatus{Capacity: 10, Count: 5}
98+
99+
sdkGs := convert(gs)
100+
eq(t, fixture, sdkGs)
101+
assert.Zero(t, sdkGs.ObjectMeta.DeletionTimestamp)
102+
assert.Equal(t, gs.Status.Players.Capacity, sdkGs.Status.Players.Capacity)
103+
assert.Equal(t, gs.Status.Players.Count, sdkGs.Status.Players.Count)
104+
})
105+
106+
t.Run("DeletionTimestamp", func(t *testing.T) {
107+
gs := fixture.DeepCopy()
81108

82-
now := metav1.Now()
83-
fixture.DeletionTimestamp = &now
84-
sdkGs = convert(fixture)
85-
eq(t, fixture, sdkGs)
86-
assert.Equal(t, fixture.ObjectMeta.DeletionTimestamp.Unix(), sdkGs.ObjectMeta.DeletionTimestamp)
109+
now := metav1.Now()
110+
gs.DeletionTimestamp = &now
111+
sdkGs := convert(gs)
112+
eq(t, gs, sdkGs)
113+
assert.Equal(t, gs.ObjectMeta.DeletionTimestamp.Unix(), sdkGs.ObjectMeta.DeletionTimestamp)
114+
})
87115
}

‎proto/sdk/sdk.proto‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,19 @@ message GameServer {
143143
string name = 1;
144144
int32 port = 2;
145145
}
146+
// [Stage:Alpha]
147+
// [FeatureFlag:PlayerTesting]
148+
message PlayerStatus {
149+
int64 count = 1;
150+
int64 capacity = 2;
151+
}
146152

147153
string state = 1;
148154
string address = 2;
149155
repeated Port ports = 3;
156+
157+
// [Stage:Alpha]
158+
// [FeatureFlag:PlayerTesting]
159+
PlayerStatus Players = 4;
150160
}
151161
}

0 commit comments

Comments
 (0)