Skip to content

Commit

Permalink
add metadata to agones webhook autoscaler request
Browse files Browse the repository at this point in the history
  • Loading branch information
swermin committed Aug 24, 2024
1 parent a78b18b commit 9ec84ce
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 3 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 ?= "AutopilotPassthroughPort=true&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 ?= "FleetAutoscaleRequestMetaData=true&PlayerAllocationFilter=true&PlayerTracking=true&RollingUpdateFix=true&PortRanges=true&PortPolicyNone=true&Example=true"

# Build with Windows support
WITH_WINDOWS=1
Expand Down
2 changes: 1 addition & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ steps:
declare -A versionsAndRegions=( [1.28]=us-west1 [1.29]=europe-west1 [1.30]=asia-east1 )
# 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&AutopilotPassthroughPort=false&Example=true"
featureWithGate="FleetAutoscaleRequestMetaData=true&PlayerAllocationFilter=true&PlayerTracking=true&CountsAndLists=false&RollingUpdateFix=true&PortRanges=true&PortPolicyNone=true&DisableResyncOnSDKServer=false&AutopilotPassthroughPort=false&Example=true"
featureWithoutGate=""
# Use this if specific feature gates can only be supported on specific Kubernetes versions.
Expand Down
1 change: 1 addition & 0 deletions install/helm/agones/defaultfeaturegates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CountsAndLists: true
DisableResyncOnSDKServer: true

# Alpha features
FleetAutoscaleRequestMetaData: false
GKEAutopilotExtendedDurationPods: false
PlayerAllocationFilter: false
PlayerTracking: false
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/autoscaling/v1/fleetautoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ type FleetAutoscaleRequest struct {
Namespace string `json:"namespace"`
// The Fleet's status values
Status agonesv1.FleetStatus `json:"status"`
// Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
MetaData *metav1.ObjectMeta `json:"metadata,omitempty"`
}

// FleetAutoscaleResponse defines the response of webhook autoscaler endpoint
Expand Down
9 changes: 9 additions & 0 deletions pkg/fleetautoscalers/fleetautoscalers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/pkg/errors"
"github.com/robfig/cron/v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/uuid"

Expand Down Expand Up @@ -172,6 +173,14 @@ func applyWebhookPolicy(w *autoscalingv1.WebhookPolicy, f *agonesv1.Fleet) (repl
Response: nil,
}

if runtime.FeatureEnabled(runtime.FeatureFleetAutoscaleRequestMetaData) {
faReq.Request.MetaData = &metav1.ObjectMeta{
Name: f.ObjectMeta.Name,
Labels: f.ObjectMeta.Labels,
Annotations: f.ObjectMeta.Annotations,
}
}

b, err := json.Marshal(faReq)
if err != nil {
return 0, false, err
Expand Down
6 changes: 5 additions & 1 deletion pkg/util/runtime/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ const (
////////////////
// Alpha features

// FeatureFleetAutoscaleRequestMetaData is a feature flag that enables/disables fleet metadata on webhook autoscaler request.
FeatureFleetAutoscaleRequestMetaData Feature = "FleetAutoscaleRequestMetaData"

// FeatureGKEAutopilotExtendedDurationPods enables the use of Extended Duration pods
// when Agones is running on Autopilot. Available on 1.28+ only.
FeatureGKEAutopilotExtendedDurationPods = "GKEAutopilotExtendedDurationPods"
FeatureGKEAutopilotExtendedDurationPods Feature = "GKEAutopilotExtendedDurationPods"

// FeaturePlayerAllocationFilter is a feature flag that enables the ability for Allocations to filter based on
// player capacity.
Expand Down Expand Up @@ -133,6 +136,7 @@ var (
FeatureDisableResyncOnSDKServer: true,

// Alpha features
FeatureFleetAutoscaleRequestMetaData: false,
FeatureGKEAutopilotExtendedDurationPods: false,
FeaturePlayerAllocationFilter: false,
FeaturePlayerTracking: false,
Expand Down
2 changes: 2 additions & 0 deletions site/content/en/docs/Reference/fleetautoscaler.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ type FleetAutoscaleRequest struct {
Namespace string `json:"namespace"`
// The Fleet's status values
Status v1.FleetStatus `json:"status"`
// Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
MetaData *metav1.ObjectMeta `json:"metadata,omitempty"`
}

type FleetAutoscaleResponse struct {
Expand Down

0 comments on commit 9ec84ce

Please sign in to comment.