Skip to content

Commit

Permalink
Merge branch 'googleforgames:main' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhongyi authored Jun 4, 2024
2 parents 84f92fb + c4b3596 commit 0f61c3c
Show file tree
Hide file tree
Showing 22 changed files with 1,999 additions and 2,716 deletions.
2 changes: 1 addition & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ GS_TEST_IMAGE ?= us-docker.pkg.dev/agones-images/examples/simple-game-server:0.3
BETA_FEATURE_GATES ?= "CountsAndLists=true&DisableResyncOnSDKServer=true"

# Enable all alpha feature gates. Keep in sync with `false` (alpha) entries in pkg/util/runtime/features.go:featureDefaults
ALPHA_FEATURE_GATES ?= "PlayerAllocationFilter=true&PlayerTracking=true&RollingUpdateFix=true&PortRanges=true&PortPolicyNone=true&Example=true"
ALPHA_FEATURE_GATES ?= "PlayerAllocationFilter=true&PlayerTracking=true&RollingUpdateFix=true&PortRanges=true&PortPolicyNone=true&AutopilotPassthroughPort=true&Example=true"

# Build with Windows support
WITH_WINDOWS=1
Expand Down
3 changes: 2 additions & 1 deletion build/includes/sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ run-sdk-conformance-test-cpp:
$(MAKE) run-sdk-conformance-test SDK_FOLDER=cpp GRPC_PORT=9003 HTTP_PORT=9103

run-sdk-conformance-test-node:
$(MAKE) run-sdk-conformance-test SDK_FOLDER=node GRPC_PORT=9002 HTTP_PORT=9102
# run with on-by-default (Beta) feature flags enabled. If running locally first run `SDK_FOLDER=node make test-sdk` to build dependencies.
$(MAKE) run-sdk-conformance-test SDK_FOLDER=node GRPC_PORT=9002 HTTP_PORT=9102 TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(COUNTS_AND_LISTS_TESTS)

run-sdk-conformance-test-go:
# run with on-by-default (Beta) feature flags enabled
Expand Down
2 changes: 1 addition & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ steps:
declare -A versionsAndRegions=( [1.27]=us-east1 [1.28]=us-west1 [1.29]=europe-west1 )
# Keep in sync with (the inverse of) pkg/util/runtime/features.go:featureDefaults
featureWithGate="PlayerAllocationFilter=true&PlayerTracking=true&CountsAndLists=false&RollingUpdateFix=true&PortRanges=true&PortPolicyNone=true&DisableResyncOnSDKServer=false&Example=true"
featureWithGate="PlayerAllocationFilter=true&PlayerTracking=true&CountsAndLists=false&RollingUpdateFix=true&PortRanges=true&PortPolicyNone=true&DisableResyncOnSDKServer=false&AutopilotPassthroughPort=true&Example=true"
featureWithoutGate=""
# Use this if specific feature gates can only be supported on specific Kubernetes versions.
Expand Down
19 changes: 10 additions & 9 deletions examples/nodejs-simple/package-lock.json

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

121 changes: 100 additions & 21 deletions examples/nodejs-simple/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {setTimeout} = require('timers/promises');
const DEFAULT_TIMEOUT = 60;
const MAX_TIMEOUT = 2147483;

const connect = async (timeout, enableAlpha) => {
const connect = async (timeout, enableAlpha, enableBeta) => {
let agonesSDK = new AgonesSDK();

let lifetimeInterval;
Expand Down Expand Up @@ -56,32 +56,37 @@ const connect = async (timeout, enableAlpha) => {
process.exit(0);
});

await setTimeout(10000);
await setTimeout(5000);
console.log('Setting a label');
await agonesSDK.setLabel('test-label', 'test-value');

await setTimeout(10000);
await setTimeout(5000);
console.log('Setting an annotation');
await agonesSDK.setAnnotation('test-annotation', 'test value');

await setTimeout(10000);
await setTimeout(5000);
console.log('Marking server as ready...');
await agonesSDK.ready();

await setTimeout(10000);
await setTimeout(5000);
console.log('Allocating');
await agonesSDK.allocate();

await setTimeout(10000);
await setTimeout(5000);
console.log('Reserving for 10 seconds');
await agonesSDK.reserve(10);
await setTimeout(20000);
await setTimeout(15000);

if (enableAlpha) {
console.log('Running alpha suite');
await runAlphaSuite(agonesSDK);
}

if (enableBeta) {
console.log('Running beta suite');
await runBetaSuite(agonesSDK);
}

if (timeout === 0) {
do {
await setTimeout(MAX_TIMEOUT);
Expand All @@ -93,12 +98,12 @@ const connect = async (timeout, enableAlpha) => {
console.log('Shutting down...');
agonesSDK.shutdown();

await setTimeout(10000);
await setTimeout(5000);
console.log('Closing connection to SDK server');
clearInterval(healthInterval);
agonesSDK.close();

await setTimeout(10000);
await setTimeout(5000);
console.log('Exiting');
clearInterval(lifetimeInterval);

Expand All @@ -113,58 +118,126 @@ const connect = async (timeout, enableAlpha) => {
};

const runAlphaSuite = async (agonesSDK) => {
await setTimeout(10000);
await setTimeout(5000);
console.log('Setting capacity');
await agonesSDK.alpha.setPlayerCapacity(64);

await setTimeout(10000);
await setTimeout(5000);
console.log('Getting capacity');
let result = await agonesSDK.alpha.getPlayerCapacity();
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Connecting a player');
result = await agonesSDK.alpha.playerConnect('firstPlayerID');
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Connecting a duplicate player');
result = await agonesSDK.alpha.playerConnect('firstPlayerID');
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Connecting another player');
await agonesSDK.alpha.playerConnect('secondPlayerID');

await setTimeout(10000);
await setTimeout(5000);
console.log('Getting player count');
result = await agonesSDK.alpha.getPlayerCount();
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Finding if firstPlayerID connected');
result = await agonesSDK.alpha.isPlayerConnected('firstPlayerID');
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Getting connected players');
result = await agonesSDK.alpha.getConnectedPlayers();
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Disconnecting a player');
result = await agonesSDK.alpha.playerDisconnect('firstPlayerID');
console.log(`result: ${result}`);

await setTimeout(10000);
await setTimeout(5000);
console.log('Disconnecting the same player');
result = await agonesSDK.alpha.playerDisconnect('firstPlayerID');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Setting counter capacity');
result = await agonesSDK.alpha.setCounterCapacity('testCounter', 10);
console.log(`result: ${result}`);
};

const runBetaSuite = async (agonesSDK) => {
let result;

await setTimeout(5000);
console.log('Getting counter count');
result = await agonesSDK.beta.getCounterCount('rooms');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Incrementing counter');
await agonesSDK.beta.incrementCounter('rooms', 1);

await setTimeout(5000);
console.log('Decrementing counter');
await agonesSDK.beta.decrementCounter('rooms', 1);

await setTimeout(5000);
console.log('Setting counter count');
await agonesSDK.beta.setCounterCount('rooms', 2);

await setTimeout(5000);
console.log('Getting counter capacity');
result = await agonesSDK.beta.getCounterCapacity('rooms');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Setting counter capacity');
await agonesSDK.beta.setCounterCapacity('rooms', 200);

await setTimeout(5000);
console.log('Getting list capacity');
result = await agonesSDK.beta.getListCapacity('players');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Setting list capacity');
await agonesSDK.beta.setListCapacity('players', 10);

await setTimeout(5000);
console.log('Getting list contains');
result = await agonesSDK.beta.listContains('players', 'test0');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Getting list length');
result = await agonesSDK.beta.getListLength('players');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Getting list values');
result = await agonesSDK.beta.getListValues('players');
console.log(`result: ${result}`);

await setTimeout(5000);
console.log('Appending list value');
await agonesSDK.beta.appendListValue('players', 'test3');

await setTimeout(5000);
console.log('Deleting list value');
await agonesSDK.beta.deleteListValue('players', 'test3');
};

let args = process.argv.slice(2);
let timeout = DEFAULT_TIMEOUT;
let enableAlpha = false;
let enableBeta = false;

for (let arg of args) {
let [argName, argValue] = arg.split('=');
Expand All @@ -173,7 +246,8 @@ for (let arg of args) {
Options:
--timeout=...\t\tshutdown timeout in seconds. Use 0 to never shut down
--alpha\t\t\tenable alpha features`);
--alpha\t\t\tenable alpha features
--beta\t\t\tenable beta features`);
return;
}
if (argName === '--timeout') {
Expand All @@ -194,6 +268,11 @@ Options:
console.log('Enabling alpha features!');
enableAlpha = true;
}

if (argName === '--beta') {
console.log('Enabling beta features!');
enableBeta = true;
}
}

connect(timeout, enableAlpha);
connect(timeout, enableAlpha, enableBeta);
2 changes: 1 addition & 1 deletion install/helm/agones/defaultfeaturegates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CountsAndLists: true
DisableResyncOnSDKServer: true

# Alpha features
AutopilotPassthroughPort: false
GKEAutopilotExtendedDurationPods: false
PlayerAllocationFilter: false
PlayerTracking: false
Expand All @@ -27,7 +28,6 @@ PortRanges: false
PortPolicyNone: false

# Dev features
FeatureAutopilotPassthroughPort: false

# Example feature
Example: false
19 changes: 19 additions & 0 deletions pkg/apis/agones/v1/gameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ const (
// NodePodIP identifies an IP address from a pod.
NodePodIP corev1.NodeAddressType = "PodIP"

// PassthroughPortAssignmentAnnotation is an annotation to keep track of game server container and its Passthrough ports indices
PassthroughPortAssignmentAnnotation = "agones.dev/container-passthrough-port-assignment"

// True is the string "true" to appease the goconst lint.
True = "true"
// False is the string "false" to appease the goconst lint.
Expand Down Expand Up @@ -738,8 +741,11 @@ func (gs *GameServer) Pod(apiHooks APIHooks, sidecars ...corev1.Container) (*cor
}

gs.podObjectMeta(pod)

passthroughContainerPortMap := make(map[string][]int)
for _, p := range gs.Spec.Ports {
var hostPort int32
portIdx := 0

if !runtime.FeatureEnabled(runtime.FeaturePortPolicyNone) || p.PortPolicy != None {
hostPort = p.HostPort
Expand All @@ -751,14 +757,27 @@ func (gs *GameServer) Pod(apiHooks APIHooks, sidecars ...corev1.Container) (*cor
Protocol: p.Protocol,
}
err := gs.ApplyToPodContainer(pod, *p.Container, func(c corev1.Container) corev1.Container {
portIdx = len(c.Ports)
c.Ports = append(c.Ports, cp)

return c
})
if err != nil {
return nil, err
}
if runtime.FeatureEnabled(runtime.FeatureAutopilotPassthroughPort) && p.PortPolicy == Passthrough {
passthroughContainerPortMap[*p.Container] = append(passthroughContainerPortMap[*p.Container], portIdx)
}
}

if len(passthroughContainerPortMap) != 0 {
containerToPassthroughMapJSON, err := json.Marshal(passthroughContainerPortMap)
if err != nil {
return nil, err
}
pod.ObjectMeta.Annotations[PassthroughPortAssignmentAnnotation] = string(containerToPassthroughMapJSON)
}

// Put the sidecars at the start of the list of containers so that the kubelet starts them first.
containers := make([]corev1.Container, 0, len(sidecars)+len(pod.Spec.Containers))
containers = append(containers, sidecars...)
Expand Down
Loading

0 comments on commit 0f61c3c

Please sign in to comment.