Skip to content

Commit 03eb7b1

Browse files
author
Robert Bailey
authored
Sdkserver port configuration (agones-dev#1078)
* Add API fields for the gRPC and HTTP ports along with command line flags to make them configurable in the sdkserver. * Changed the logging field into a type (from a string). * Updates to example yaml files. * Updated CRD validation. * Updates to the reference documentation for the new API fields.
1 parent 1b5e24d commit 03eb7b1

13 files changed

Lines changed: 351 additions & 120 deletions

File tree

‎cmd/sdk-server/main.go‎

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,22 @@ import (
4141
)
4242

4343
const (
44-
grpcPort = 59357
45-
httpPort = 59358
44+
defaultGRPCPort = 59357
45+
defaultHTTPPort = 59358
4646

4747
// specifically env vars
4848
gameServerNameEnv = "GAMESERVER_NAME"
4949
podNamespaceEnv = "POD_NAMESPACE"
5050

5151
// Flags (that can also be env vars)
52-
localFlag = "local"
53-
fileFlag = "file"
54-
testFlag = "test"
55-
addressFlag = "address"
56-
delayFlag = "delay"
57-
timeoutFlag = "timeout"
52+
localFlag = "local"
53+
fileFlag = "file"
54+
testFlag = "test"
55+
addressFlag = "address"
56+
delayFlag = "delay"
57+
timeoutFlag = "timeout"
58+
grpcPortFlag = "grpc-port"
59+
httpPortFlag = "http-port"
5860
)
5961

6062
var (
@@ -64,15 +66,8 @@ var (
6466
func main() {
6567
ctlConf := parseEnvFlags()
6668
logger.WithField("version", pkg.Version).
67-
WithField("grpcPort", grpcPort).WithField("httpPort", httpPort).
6869
WithField("ctlConf", ctlConf).Info("Starting sdk sidecar")
6970

70-
grpcEndpoint := fmt.Sprintf("%s:%d", ctlConf.Address, grpcPort)
71-
lis, err := net.Listen("tcp", grpcEndpoint)
72-
if err != nil {
73-
logger.WithField("grpcPort", grpcPort).WithField("Address", ctlConf.Address).Fatalf("Could not listen on grpcPort")
74-
}
75-
7671
if ctlConf.Delay > 0 {
7772
logger.Infof("Waiting %d seconds before starting", ctlConf.Delay)
7873
time.Sleep(time.Duration(ctlConf.Delay) * time.Second)
@@ -88,7 +83,7 @@ func main() {
8883

8984
mux := gwruntime.NewServeMux()
9085
httpServer := &http.Server{
91-
Addr: fmt.Sprintf("%s:%d", ctlConf.Address, httpPort),
86+
Addr: fmt.Sprintf("%s:%d", ctlConf.Address, ctlConf.HTTPPort),
9287
Handler: mux,
9388
}
9489
defer httpServer.Close() // nolint: errcheck
@@ -123,7 +118,7 @@ func main() {
123118
}
124119
} else {
125120
var config *rest.Config
126-
config, err = rest.InClusterConfig()
121+
config, err := rest.InClusterConfig()
127122
if err != nil {
128123
logger.WithError(err).Fatal("Could not create in cluster config")
129124
}
@@ -156,7 +151,8 @@ func main() {
156151
sdk.RegisterSDKServer(grpcServer, s)
157152
}
158153

159-
go runGrpc(grpcServer, lis)
154+
grpcEndpoint := fmt.Sprintf("%s:%d", ctlConf.Address, ctlConf.GRPCPort)
155+
go runGrpc(grpcServer, grpcEndpoint)
160156
go runGateway(ctx, grpcEndpoint, mux, httpServer)
161157

162158
select {
@@ -203,8 +199,13 @@ func registerTestSdkServer(grpcServer *grpc.Server, ctlConf config) (localSDK *s
203199
}
204200

205201
// runGrpc runs the grpc service
206-
func runGrpc(grpcServer *grpc.Server, lis net.Listener) {
207-
logger.Info("Starting SDKServer grpc service...")
202+
func runGrpc(grpcServer *grpc.Server, grpcEndpoint string) {
203+
lis, err := net.Listen("tcp", grpcEndpoint)
204+
if err != nil {
205+
logger.WithField("grpcEndpoint", grpcEndpoint).Fatal("Could not listen on grpc endpoint")
206+
}
207+
208+
logger.WithField("grpcEndpoint", grpcEndpoint).Info("Starting SDKServer grpc service...")
208209
if err := grpcServer.Serve(lis); err != nil {
209210
logger.WithError(err).Fatal("Could not serve grpc server")
210211
}
@@ -221,7 +222,7 @@ func runGateway(ctx context.Context, grpcEndpoint string, mux *gwruntime.ServeMu
221222
logger.WithError(err).Fatal("Could not register grpc-gateway")
222223
}
223224

224-
logger.Info("Starting SDKServer grpc-gateway...")
225+
logger.WithField("grpcEndpoint", grpcEndpoint).Info("Starting SDKServer grpc-gateway...")
225226
if err := httpServer.ListenAndServe(); err != nil {
226227
if err == http.ErrServerClosed {
227228
logger.WithError(err).Info("http server closed")
@@ -241,10 +242,14 @@ func parseEnvFlags() config {
241242
viper.SetDefault(addressFlag, "localhost")
242243
viper.SetDefault(delayFlag, 0)
243244
viper.SetDefault(timeoutFlag, 0)
245+
viper.SetDefault(grpcPortFlag, defaultGRPCPort)
246+
viper.SetDefault(httpPortFlag, defaultHTTPPort)
244247
pflag.Bool(localFlag, viper.GetBool(localFlag),
245248
"Set this, or LOCAL env, to 'true' to run this binary in local development mode. Defaults to 'false'")
246249
pflag.StringP(fileFlag, "f", viper.GetString(fileFlag), "Set this, or FILE env var to the path of a local yaml or json file that contains your GameServer resoure configuration")
247250
pflag.String(addressFlag, viper.GetString(addressFlag), "The Address to bind the server grpcPort to. Defaults to 'localhost'")
251+
pflag.Int(grpcPortFlag, viper.GetInt(grpcPortFlag), fmt.Sprintf("Port on which to bind the gRPC server. Defaults to %d", defaultGRPCPort))
252+
pflag.Int(httpPortFlag, viper.GetInt(httpPortFlag), fmt.Sprintf("Port on which to bind the HTTP server. Defaults to %d", defaultHTTPPort))
248253
pflag.Int(delayFlag, viper.GetInt(delayFlag), "Time to delay (in seconds) before starting to execute main. Useful for tests")
249254
pflag.Int(timeoutFlag, viper.GetInt(timeoutFlag), "Time of execution (in seconds) before close. Useful for tests")
250255
pflag.String(testFlag, viper.GetString(testFlag), "List functions which shoud be called during the SDK Conformance test run.")
@@ -258,6 +263,8 @@ func parseEnvFlags() config {
258263
runtime.Must(viper.BindEnv(podNamespaceEnv))
259264
runtime.Must(viper.BindEnv(delayFlag))
260265
runtime.Must(viper.BindEnv(timeoutFlag))
266+
runtime.Must(viper.BindEnv(grpcPortFlag))
267+
runtime.Must(viper.BindEnv(httpPortFlag))
261268
runtime.Must(viper.BindPFlags(pflag.CommandLine))
262269

263270
return config{
@@ -267,6 +274,8 @@ func parseEnvFlags() config {
267274
Delay: viper.GetInt(delayFlag),
268275
Timeout: viper.GetInt(timeoutFlag),
269276
Test: viper.GetString(testFlag),
277+
GRPCPort: viper.GetInt(grpcPortFlag),
278+
HTTPPort: viper.GetInt(httpPortFlag),
270279
}
271280
}
272281

@@ -278,4 +287,6 @@ type config struct {
278287
Delay int
279288
Timeout int
280289
Test string
290+
GRPCPort int
291+
HTTPPort int
281292
}

‎examples/fleet.yaml‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ spec:
6262
health:
6363
initialDelaySeconds: 30
6464
periodSeconds: 60
65-
# logging parameters for game server sidecar
66-
logging:
67-
sdkServer: Info
65+
# Parameters for game server sidecar
66+
sdkServer:
67+
# sdkServer log level parameter has three options:
68+
# - "Info" (default) The SDK server will output all messages except for debug messages
69+
# - "Debug" The SDK server will output all messages including debug messages
70+
# - "Error" The SDK server will only output error messages
71+
logLevel: Info
6872
# The GameServer's Pod template
6973
template:
7074
spec:

‎examples/gameserver.yaml‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,20 @@ spec:
6060
# Minimum consecutive failures for the health probe to be considered failed after having succeeded.
6161
# Defaults to 3. Minimum value is 1
6262
failureThreshold: 3
63-
# logging parameters for game server sidecar
64-
logging:
65-
# sdkServer logging parameter has three options:
63+
# Parameters for game server sidecar
64+
sdkServer:
65+
# sdkServer log level parameter has three options:
6666
# - "Info" (default) The SDK server will output all messages except for debug messages
6767
# - "Debug" The SDK server will output all messages including debug messages
6868
# - "Error" The SDK server will only output error messages
69-
sdkServer: Info
69+
logLevel: Info
70+
# grpcPort and httpPort control what ports the sdkserver listens on.
71+
# The defaults in Agones 1.0 used high port numbers (in the ephemeral port
72+
# range on most systems) which can conflict with other TCP connections
73+
# within the pod. It is recommended to set these to a non-ephemeral port
74+
# and the default port will be changed in a future release of Agones.
75+
grpcPort: 9357
76+
httpPort: 9358
7077
# Pod template configuration
7178
# https://v1-12.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.12/#podtemplate-v1-core
7279
template:

‎install/helm/agones/templates/crds/_gameserverspecvalidation.yaml‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,39 @@ properties:
9292
type: integer
9393
minimum: 1
9494
maximum: 65535
95-
logging:
95+
sdkServer:
9696
type: object
97-
title: Define logging levels for agones system components
97+
title: Parameters for the SDK Server (sidecar)
9898
properties:
99-
sdkServer:
99+
logLevel:
100100
type: string
101101
description: |
102-
sdkServer logging parameter has three options:
102+
sdkServer log level parameter has three options:
103103
- "Info" (default) The SDK server will output all messages except for debug messages
104104
- "Debug" The SDK server will output all messages including debug messages
105105
- "Error" The SDK server will only output error messages
106106
enum:
107107
- Error
108108
- Info
109109
- Debug
110+
grpcPort:
111+
title: The port on which the SDK server binds the gRPC server to accept incoming connections
112+
description: |
113+
The default gRPC port in Agones 1.0 was 59357 which is in the ephemeral port range and can
114+
encounter conflicts in rare cases. The default will be changed to 9357 in a future release
115+
of Agones.
116+
type: integer
117+
minimum: 1
118+
maximum: 65535
119+
httpPort:
120+
title: The port on which the SDK server binds the HTTP gRPC gateway server to accept incoming connections
121+
description: |
122+
The default HTTP port in Agones 1.0 was 59358 which is in the ephemeral port range and can
123+
encounter conflicts in rare cases. The default will be changed to 9358 in a future release
124+
of Agones.
125+
type: integer
126+
minimum: 1
127+
maximum: 65535
110128
scheduling:
111129
type: string
112130
enum:

‎install/yaml/install.yaml‎

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,39 @@ spec:
339339
type: integer
340340
minimum: 1
341341
maximum: 65535
342-
logging:
342+
sdkServer:
343343
type: object
344-
title: Define logging levels for agones system components
344+
title: Parameters for the SDK Server (sidecar)
345345
properties:
346-
sdkServer:
346+
logLevel:
347347
type: string
348348
description: |
349-
sdkServer logging parameter has three options:
349+
sdkServer log level parameter has three options:
350350
- "Info" (default) The SDK server will output all messages except for debug messages
351351
- "Debug" The SDK server will output all messages including debug messages
352352
- "Error" The SDK server will only output error messages
353353
enum:
354354
- Error
355355
- Info
356356
- Debug
357+
grpcPort:
358+
title: The port on which the SDK server binds the gRPC server to accept incoming connections
359+
description: |
360+
The default gRPC port in Agones 1.0 was 59357 which is in the ephemeral port range and can
361+
encounter conflicts in rare cases. The default will be changed to 9357 in a future release
362+
of Agones.
363+
type: integer
364+
minimum: 1
365+
maximum: 65535
366+
httpPort:
367+
title: The port on which the SDK server binds the HTTP gRPC gateway server to accept incoming connections
368+
description: |
369+
The default HTTP port in Agones 1.0 was 59358 which is in the ephemeral port range and can
370+
encounter conflicts in rare cases. The default will be changed to 9358 in a future release
371+
of Agones.
372+
type: integer
373+
minimum: 1
374+
maximum: 65535
357375
scheduling:
358376
type: string
359377
enum:
@@ -609,21 +627,39 @@ spec:
609627
type: integer
610628
minimum: 1
611629
maximum: 65535
612-
logging:
630+
sdkServer:
613631
type: object
614-
title: Define logging levels for agones system components
632+
title: Parameters for the SDK Server (sidecar)
615633
properties:
616-
sdkServer:
634+
logLevel:
617635
type: string
618636
description: |
619-
sdkServer logging parameter has three options:
637+
sdkServer log level parameter has three options:
620638
- "Info" (default) The SDK server will output all messages except for debug messages
621639
- "Debug" The SDK server will output all messages including debug messages
622640
- "Error" The SDK server will only output error messages
623641
enum:
624642
- Error
625643
- Info
626644
- Debug
645+
grpcPort:
646+
title: The port on which the SDK server binds the gRPC server to accept incoming connections
647+
description: |
648+
The default gRPC port in Agones 1.0 was 59357 which is in the ephemeral port range and can
649+
encounter conflicts in rare cases. The default will be changed to 9357 in a future release
650+
of Agones.
651+
type: integer
652+
minimum: 1
653+
maximum: 65535
654+
httpPort:
655+
title: The port on which the SDK server binds the HTTP gRPC gateway server to accept incoming connections
656+
description: |
657+
The default HTTP port in Agones 1.0 was 59358 which is in the ephemeral port range and can
658+
encounter conflicts in rare cases. The default will be changed to 9358 in a future release
659+
of Agones.
660+
type: integer
661+
minimum: 1
662+
maximum: 65535
627663
scheduling:
628664
type: string
629665
enum:
@@ -893,21 +929,39 @@ spec:
893929
type: integer
894930
minimum: 1
895931
maximum: 65535
896-
logging:
932+
sdkServer:
897933
type: object
898-
title: Define logging levels for agones system components
934+
title: Parameters for the SDK Server (sidecar)
899935
properties:
900-
sdkServer:
936+
logLevel:
901937
type: string
902938
description: |
903-
sdkServer logging parameter has three options:
939+
sdkServer log level parameter has three options:
904940
- "Info" (default) The SDK server will output all messages except for debug messages
905941
- "Debug" The SDK server will output all messages including debug messages
906942
- "Error" The SDK server will only output error messages
907943
enum:
908944
- Error
909945
- Info
910946
- Debug
947+
grpcPort:
948+
title: The port on which the SDK server binds the gRPC server to accept incoming connections
949+
description: |
950+
The default gRPC port in Agones 1.0 was 59357 which is in the ephemeral port range and can
951+
encounter conflicts in rare cases. The default will be changed to 9357 in a future release
952+
of Agones.
953+
type: integer
954+
minimum: 1
955+
maximum: 65535
956+
httpPort:
957+
title: The port on which the SDK server binds the HTTP gRPC gateway server to accept incoming connections
958+
description: |
959+
The default HTTP port in Agones 1.0 was 59358 which is in the ephemeral port range and can
960+
encounter conflicts in rare cases. The default will be changed to 9358 in a future release
961+
of Agones.
962+
type: integer
963+
minimum: 1
964+
maximum: 65535
911965
scheduling:
912966
type: string
913967
enum:

0 commit comments

Comments
 (0)