Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdkserver port configuration #1078

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions cmd/sdk-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@ import (
)

const (
grpcPort = 59357
httpPort = 59358
defaultGRPCPort = 59357
defaultHTTPPort = 59358

// specifically env vars
gameServerNameEnv = "GAMESERVER_NAME"
podNamespaceEnv = "POD_NAMESPACE"

// Flags (that can also be env vars)
localFlag = "local"
fileFlag = "file"
testFlag = "test"
addressFlag = "address"
delayFlag = "delay"
timeoutFlag = "timeout"
localFlag = "local"
fileFlag = "file"
testFlag = "test"
addressFlag = "address"
delayFlag = "delay"
timeoutFlag = "timeout"
grpcPortFlag = "grpc-port"
httpPortFlag = "http-port"
)

var (
Expand All @@ -64,15 +66,8 @@ var (
func main() {
ctlConf := parseEnvFlags()
logger.WithField("version", pkg.Version).
WithField("grpcPort", grpcPort).WithField("httpPort", httpPort).
WithField("ctlConf", ctlConf).Info("Starting sdk sidecar")

grpcEndpoint := fmt.Sprintf("%s:%d", ctlConf.Address, grpcPort)
lis, err := net.Listen("tcp", grpcEndpoint)
if err != nil {
logger.WithField("grpcPort", grpcPort).WithField("Address", ctlConf.Address).Fatalf("Could not listen on grpcPort")
}

if ctlConf.Delay > 0 {
logger.Infof("Waiting %d seconds before starting", ctlConf.Delay)
time.Sleep(time.Duration(ctlConf.Delay) * time.Second)
Expand All @@ -88,7 +83,7 @@ func main() {

mux := gwruntime.NewServeMux()
httpServer := &http.Server{
Addr: fmt.Sprintf("%s:%d", ctlConf.Address, httpPort),
Addr: fmt.Sprintf("%s:%d", ctlConf.Address, ctlConf.HTTPPort),
Handler: mux,
}
defer httpServer.Close() // nolint: errcheck
Expand Down Expand Up @@ -123,7 +118,7 @@ func main() {
}
} else {
var config *rest.Config
config, err = rest.InClusterConfig()
config, err := rest.InClusterConfig()
if err != nil {
logger.WithError(err).Fatal("Could not create in cluster config")
}
Expand Down Expand Up @@ -156,7 +151,8 @@ func main() {
sdk.RegisterSDKServer(grpcServer, s)
}

go runGrpc(grpcServer, lis)
grpcEndpoint := fmt.Sprintf("%s:%d", ctlConf.Address, ctlConf.GRPCPort)
go runGrpc(grpcServer, grpcEndpoint)
go runGateway(ctx, grpcEndpoint, mux, httpServer)

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

// runGrpc runs the grpc service
func runGrpc(grpcServer *grpc.Server, lis net.Listener) {
logger.Info("Starting SDKServer grpc service...")
func runGrpc(grpcServer *grpc.Server, grpcEndpoint string) {
lis, err := net.Listen("tcp", grpcEndpoint)
if err != nil {
logger.WithField("grpcEndpoint", grpcEndpoint).Fatal("Could not listen on grpc endpoint")
}

logger.WithField("grpcEndpoint", grpcEndpoint).Info("Starting SDKServer grpc service...")
if err := grpcServer.Serve(lis); err != nil {
logger.WithError(err).Fatal("Could not serve grpc server")
}
Expand All @@ -221,7 +222,7 @@ func runGateway(ctx context.Context, grpcEndpoint string, mux *gwruntime.ServeMu
logger.WithError(err).Fatal("Could not register grpc-gateway")
}

logger.Info("Starting SDKServer grpc-gateway...")
logger.WithField("grpcEndpoint", grpcEndpoint).Info("Starting SDKServer grpc-gateway...")
if err := httpServer.ListenAndServe(); err != nil {
if err == http.ErrServerClosed {
logger.WithError(err).Info("http server closed")
Expand All @@ -241,10 +242,14 @@ func parseEnvFlags() config {
viper.SetDefault(addressFlag, "localhost")
viper.SetDefault(delayFlag, 0)
viper.SetDefault(timeoutFlag, 0)
viper.SetDefault(grpcPortFlag, defaultGRPCPort)
viper.SetDefault(httpPortFlag, defaultHTTPPort)
pflag.Bool(localFlag, viper.GetBool(localFlag),
"Set this, or LOCAL env, to 'true' to run this binary in local development mode. Defaults to 'false'")
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")
pflag.String(addressFlag, viper.GetString(addressFlag), "The Address to bind the server grpcPort to. Defaults to 'localhost'")
pflag.Int(grpcPortFlag, viper.GetInt(grpcPortFlag), fmt.Sprintf("Port on which to bind the gRPC server. Defaults to %d", defaultGRPCPort))
pflag.Int(httpPortFlag, viper.GetInt(httpPortFlag), fmt.Sprintf("Port on which to bind the HTTP server. Defaults to %d", defaultHTTPPort))
pflag.Int(delayFlag, viper.GetInt(delayFlag), "Time to delay (in seconds) before starting to execute main. Useful for tests")
pflag.Int(timeoutFlag, viper.GetInt(timeoutFlag), "Time of execution (in seconds) before close. Useful for tests")
pflag.String(testFlag, viper.GetString(testFlag), "List functions which shoud be called during the SDK Conformance test run.")
Expand All @@ -258,6 +263,8 @@ func parseEnvFlags() config {
runtime.Must(viper.BindEnv(podNamespaceEnv))
runtime.Must(viper.BindEnv(delayFlag))
runtime.Must(viper.BindEnv(timeoutFlag))
runtime.Must(viper.BindEnv(grpcPortFlag))
runtime.Must(viper.BindEnv(httpPortFlag))
runtime.Must(viper.BindPFlags(pflag.CommandLine))

return config{
Expand All @@ -267,6 +274,8 @@ func parseEnvFlags() config {
Delay: viper.GetInt(delayFlag),
Timeout: viper.GetInt(timeoutFlag),
Test: viper.GetString(testFlag),
GRPCPort: viper.GetInt(grpcPortFlag),
HTTPPort: viper.GetInt(httpPortFlag),
}
}

Expand All @@ -278,4 +287,6 @@ type config struct {
Delay int
Timeout int
Test string
GRPCPort int
HTTPPort int
}
10 changes: 7 additions & 3 deletions examples/fleet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ spec:
health:
initialDelaySeconds: 30
periodSeconds: 60
# logging parameters for game server sidecar
logging:
sdkServer: Info
# Parameters for game server sidecar
sdkServer:
# sdkServer log level parameter has three options:
# - "Info" (default) The SDK server will output all messages except for debug messages
# - "Debug" The SDK server will output all messages including debug messages
# - "Error" The SDK server will only output error messages
logLevel: Info
# The GameServer's Pod template
template:
spec:
Expand Down
15 changes: 11 additions & 4 deletions examples/gameserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,20 @@ spec:
# Minimum consecutive failures for the health probe to be considered failed after having succeeded.
# Defaults to 3. Minimum value is 1
failureThreshold: 3
# logging parameters for game server sidecar
logging:
# sdkServer logging parameter has three options:
# Parameters for game server sidecar
sdkServer:
# sdkServer log level parameter has three options:
# - "Info" (default) The SDK server will output all messages except for debug messages
# - "Debug" The SDK server will output all messages including debug messages
# - "Error" The SDK server will only output error messages
sdkServer: Info
logLevel: Info
# grpcPort and httpPort control what ports the sdkserver listens on.
# The defaults in Agones 1.0 used high port numbers (in the ephemeral port
# range on most systems) which can conflict with other TCP connections
# within the pod. It is recommended to set these to a non-ephemeral port
# and the default port will be changed in a future release of Agones.
grpcPort: 9357
httpPort: 9358
# Pod template configuration
# https://v1-12.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.12/#podtemplate-v1-core
template:
Expand Down
26 changes: 22 additions & 4 deletions install/helm/agones/templates/crds/_gameserverspecvalidation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,39 @@ properties:
type: integer
minimum: 1
maximum: 65535
logging:
sdkServer:
type: object
title: Define logging levels for agones system components
title: Parameters for the SDK Server (sidecar)
properties:
sdkServer:
logLevel:
type: string
description: |
sdkServer logging parameter has three options:
sdkServer log level parameter has three options:
- "Info" (default) The SDK server will output all messages except for debug messages
- "Debug" The SDK server will output all messages including debug messages
- "Error" The SDK server will only output error messages
enum:
- Error
- Info
- Debug
grpcPort:
title: The port on which the SDK server binds the gRPC server to accept incoming connections
description: |
The default gRPC port in Agones 1.0 was 59357 which is in the ephemeral port range and can
encounter conflicts in rare cases. The default will be changed to 9357 in a future release
of Agones.
type: integer
minimum: 1
maximum: 65535
httpPort:
title: The port on which the SDK server binds the HTTP gRPC gateway server to accept incoming connections
description: |
The default HTTP port in Agones 1.0 was 59358 which is in the ephemeral port range and can
encounter conflicts in rare cases. The default will be changed to 9358 in a future release
of Agones.
type: integer
minimum: 1
maximum: 65535
scheduling:
type: string
enum:
Expand Down
78 changes: 66 additions & 12 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -339,21 +339,39 @@ spec:
type: integer
minimum: 1
maximum: 65535
logging:
sdkServer:
type: object
title: Define logging levels for agones system components
title: Parameters for the SDK Server (sidecar)
properties:
sdkServer:
logLevel:
type: string
description: |
sdkServer logging parameter has three options:
sdkServer log level parameter has three options:
- "Info" (default) The SDK server will output all messages except for debug messages
- "Debug" The SDK server will output all messages including debug messages
- "Error" The SDK server will only output error messages
enum:
- Error
- Info
- Debug
grpcPort:
title: The port on which the SDK server binds the gRPC server to accept incoming connections
description: |
The default gRPC port in Agones 1.0 was 59357 which is in the ephemeral port range and can
encounter conflicts in rare cases. The default will be changed to 9357 in a future release
of Agones.
type: integer
minimum: 1
maximum: 65535
httpPort:
title: The port on which the SDK server binds the HTTP gRPC gateway server to accept incoming connections
description: |
The default HTTP port in Agones 1.0 was 59358 which is in the ephemeral port range and can
encounter conflicts in rare cases. The default will be changed to 9358 in a future release
of Agones.
type: integer
minimum: 1
maximum: 65535
scheduling:
type: string
enum:
Expand Down Expand Up @@ -609,21 +627,39 @@ spec:
type: integer
minimum: 1
maximum: 65535
logging:
sdkServer:
type: object
title: Define logging levels for agones system components
title: Parameters for the SDK Server (sidecar)
properties:
sdkServer:
logLevel:
type: string
description: |
sdkServer logging parameter has three options:
sdkServer log level parameter has three options:
- "Info" (default) The SDK server will output all messages except for debug messages
- "Debug" The SDK server will output all messages including debug messages
- "Error" The SDK server will only output error messages
enum:
- Error
- Info
- Debug
grpcPort:
title: The port on which the SDK server binds the gRPC server to accept incoming connections
description: |
The default gRPC port in Agones 1.0 was 59357 which is in the ephemeral port range and can
encounter conflicts in rare cases. The default will be changed to 9357 in a future release
of Agones.
type: integer
minimum: 1
maximum: 65535
httpPort:
title: The port on which the SDK server binds the HTTP gRPC gateway server to accept incoming connections
description: |
The default HTTP port in Agones 1.0 was 59358 which is in the ephemeral port range and can
encounter conflicts in rare cases. The default will be changed to 9358 in a future release
of Agones.
type: integer
minimum: 1
maximum: 65535
scheduling:
type: string
enum:
Expand Down Expand Up @@ -893,21 +929,39 @@ spec:
type: integer
minimum: 1
maximum: 65535
logging:
sdkServer:
type: object
title: Define logging levels for agones system components
title: Parameters for the SDK Server (sidecar)
properties:
sdkServer:
logLevel:
type: string
description: |
sdkServer logging parameter has three options:
sdkServer log level parameter has three options:
- "Info" (default) The SDK server will output all messages except for debug messages
- "Debug" The SDK server will output all messages including debug messages
- "Error" The SDK server will only output error messages
enum:
- Error
- Info
- Debug
grpcPort:
title: The port on which the SDK server binds the gRPC server to accept incoming connections
description: |
The default gRPC port in Agones 1.0 was 59357 which is in the ephemeral port range and can
encounter conflicts in rare cases. The default will be changed to 9357 in a future release
of Agones.
type: integer
minimum: 1
maximum: 65535
httpPort:
title: The port on which the SDK server binds the HTTP gRPC gateway server to accept incoming connections
description: |
The default HTTP port in Agones 1.0 was 59358 which is in the ephemeral port range and can
encounter conflicts in rare cases. The default will be changed to 9358 in a future release
of Agones.
type: integer
minimum: 1
maximum: 65535
scheduling:
type: string
enum:
Expand Down
Loading