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

add metadata to agones webhook autoscaler request #3957

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
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&GKEAutopilotExtendedDurationPods=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&ScheduledAutoscaler=true&Example=true"
ALPHA_FEATURE_GATES ?= "PlayerAllocationFilter=true&FleetAutoscaleRequestMetaData=true&PlayerTracking=true&RollingUpdateFix=true&PortRanges=true&PortPolicyNone=true&ScheduledAutoscaler=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 @@ -440,7 +440,7 @@ steps:
declare -A versionsAndRegions=( [1.29]=europe-west1 [1.30]=asia-east1 [1.31]=us-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&ScheduledAutoscaler=true&DisableResyncOnSDKServer=false&AutopilotPassthroughPort=false&GKEAutopilotExtendedDurationPods=false&Example=true"
featureWithGate="PlayerAllocationFilter=true&FleetAutoscaleRequestMetaData=true&PlayerTracking=true&CountsAndLists=false&RollingUpdateFix=true&PortRanges=true&PortPolicyNone=true&ScheduledAutoscaler=true&DisableResyncOnSDKServer=false&AutopilotPassthroughPort=false&GKEAutopilotExtendedDurationPods=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 @@ -21,6 +21,7 @@ CountsAndLists: true
DisableResyncOnSDKServer: true

# Alpha features
FleetAutoscaleRequestMetaData: false
PlayerAllocationFilter: false
PlayerTracking: false
RollingUpdateFix: false
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/autoscaling/v1/fleetautoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ type FleetAutoscaleRequest struct {
Namespace string `json:"namespace"`
// The Fleet's status values
Status agonesv1.FleetStatus `json:"status"`
// Standard map labels; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels.
Labels map[string]string `json:"labels,omitempty"`
// Standard map annotations; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations.
Annotations map[string]string `json:"annotations,omitempty"`
}

// FleetAutoscaleResponse defines the response of webhook autoscaler endpoint
Expand Down
5 changes: 5 additions & 0 deletions pkg/fleetautoscalers/fleetautoscalers.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ func applyWebhookPolicy(w *autoscalingv1.WebhookPolicy, f *agonesv1.Fleet) (repl
Response: nil,
}

if runtime.FeatureEnabled(runtime.FeatureFleetAutoscaleRequestMetaData) {
faReq.Request.Annotations = f.ObjectMeta.Annotations
faReq.Request.Labels = f.ObjectMeta.Labels
}

b, err := json.Marshal(faReq)
if err != nil {
return 0, false, err
Expand Down
45 changes: 45 additions & 0 deletions pkg/fleetautoscalers/fleetautoscalers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -92,6 +93,15 @@ func (t testServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
faResp.Replicas = faReq.Status.Replicas * scaleFactor
}

// override value for tests
if faReq.Annotations != nil {
if value, ok := faReq.Annotations["fixedReplicas"]; ok {
faResp.Scale = true
replicas, _ := strconv.Atoi(value)
faResp.Replicas = int32(replicas)
}
}

review := &autoscalingv1.FleetAutoscaleReview{
Request: faReq,
Response: &faResp,
Expand Down Expand Up @@ -579,6 +589,41 @@ func TestApplyWebhookPolicy(t *testing.T) {
}
}

func TestApplyWebhookPolicyWithMetadata(t *testing.T) {
t.Parallel()

utilruntime.FeatureTestMutex.Lock()
defer utilruntime.FeatureTestMutex.Unlock()

err := utilruntime.ParseFeatures(string(utilruntime.FeatureFleetAutoscaleRequestMetaData) + "=true")
assert.NoError(t, err)
defer func() {
_ = utilruntime.ParseFeatures("")
}()

ts := testServer{}
server := httptest.NewServer(ts)
defer server.Close()

_, fleet := defaultWebhookFixtures()

fixedReplicas := int32(11)
fleet.ObjectMeta.Annotations = map[string]string{
"fixedReplicas": fmt.Sprintf("%d", fixedReplicas),
}

webhookPolicy := &autoscalingv1.WebhookPolicy{
Service: nil,
URL: &(server.URL),
}

replicas, limited, err := applyWebhookPolicy(webhookPolicy, fleet)

assert.Nil(t, err)
assert.False(t, limited)
assert.Equal(t, fixedReplicas, replicas)
}

func TestApplyWebhookPolicyNilFleet(t *testing.T) {
t.Parallel()

Expand Down
16 changes: 10 additions & 6 deletions pkg/util/runtime/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const (
////////////////
// Alpha features

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

// FeaturePlayerAllocationFilter is a feature flag that enables the ability for Allocations to filter based on
// player capacity.
FeaturePlayerAllocationFilter Feature = "PlayerAllocationFilter"
Expand Down Expand Up @@ -134,12 +137,13 @@ var (
FeatureDisableResyncOnSDKServer: true,

// Alpha features
FeaturePlayerAllocationFilter: false,
FeaturePlayerTracking: false,
FeatureRollingUpdateFix: false,
FeaturePortRanges: false,
FeaturePortPolicyNone: false,
FeatureScheduledAutoscaler: false,
FeatureFleetAutoscaleRequestMetaData: false,
FeaturePlayerAllocationFilter: false,
FeaturePlayerTracking: false,
FeatureRollingUpdateFix: false,
FeaturePortRanges: false,
FeaturePortPolicyNone: false,
FeatureScheduledAutoscaler: false,

// Dev features

Expand Down
20 changes: 20 additions & 0 deletions site/content/en/docs/Guides/feature-stages.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,25 @@ that can be found in the [Helm configuration]({{< ref "/docs/Installation/Instal

The current set of `alpha` and `beta` feature gates:

{{% feature expiryVersion="1.48.0" %}}

| Feature Name | Gate | Default | Stage | Since |
|-----------------------------------------------------------------------------------------------------------------------------|------------------------------------|----------|---------|--------|
| [CountsAndLists](https://github.com/googleforgames/agones/issues/2716) | `CountsAndLists` | Enabled | `Beta` | 1.41.0 |
| [DisableResyncOnSDKServer](https://github.com/googleforgames/agones/issues/3377) | `DisableResyncOnSDKServer` | Enabled | `Beta` | 1.40.0 |
| [Support Passthrough on GKE Autopilot](https://github.com/googleforgames/agones/issues/3721) | `AutopilotPassthroughPort` | Enabled | `Beta` | 1.43.0 |
| [Support for Extended Duration Pods on GKE Autopilot (*1.28+ only*)](https://github.com/googleforgames/agones/issues/3386) | `GKEAutopilotExtendedDurationPods` | Enabled | `Beta` | 1.44.0 |
| [GameServer player capacity filtering on GameServerAllocations](https://github.com/googleforgames/agones/issues/1239) | `PlayerAllocationFilter` | Disabled | `Alpha` | 1.14.0 |
| [Player Tracking]({{< ref "/docs/Guides/player-tracking.md" >}}) | `PlayerTracking` | Disabled | `Alpha` | 1.6.0 |
| [Rolling Update Fixes](https://github.com/googleforgames/agones/issues/3688) | `RollingUpdateFix` | Disabled | `Alpha` | 1.41.0 |
| [Multiple dynamic port ranges](https://github.com/googleforgames/agones/issues/1911) | `PortRanges` | Disabled | `Alpha` | 1.41.0 |
| [Port Policy None](https://github.com/googleforgames/agones/issues/3804) | `PortPolicyNone` | Disabled | `Alpha` | 1.41.0 |
| [Scheduled Fleet Autoscaling](https://github.com/googleforgames/agones/issues/3008) | `ScheduledAutoscaler` | Disabled | `Alpha` | 1.43.0 |
| Example Gate (not in use) | `Example` | Disabled | None | 0.13.0 |

{{% /feature %}}

{{% feature publishVersion="1.48.0" %}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mid table items tend to render badly, you may need to copy the whole table. But I'll run it and we can see what it looks like in preview.

(make site-server will give you a local version if you would like to try it).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

https://1d43bbe-dot-preview-dot-agones-images.appspot.com/site/docs/guides/feature-stages/#feature-gates

Going to have to copy the whole block, but otherwise, I think this is good to go.


| Feature Name | Gate | Default | Stage | Since |
|-----------------------------------------------------------------------------------------------------------------------------|------------------------------------|----------|---------|--------|
Expand All @@ -38,8 +56,10 @@ The current set of `alpha` and `beta` feature gates:
| [Multiple dynamic port ranges](https://github.com/googleforgames/agones/issues/1911) | `PortRanges` | Disabled | `Alpha` | 1.41.0 |
| [Port Policy None](https://github.com/googleforgames/agones/issues/3804) | `PortPolicyNone` | Disabled | `Alpha` | 1.41.0 |
| [Scheduled Fleet Autoscaling](https://github.com/googleforgames/agones/issues/3008) | `ScheduledAutoscaler` | Disabled | `Alpha` | 1.43.0 |
| [Extend Webhook autoscaler to send fleet metadata with the request](https://github.com/googleforgames/agones/issues/3951) | `FleetAutoscaleRequestMetaData` | Disabled | `Alpha` | 1.48.0 |
| Example Gate (not in use) | `Example` | Disabled | None | 0.13.0 |

{{% /feature %}}

[fleet-updates]: {{% relref "./fleet-updates.md#notifying-gameservers-on-fleet-updatedownscale" %}}

Expand Down
4 changes: 4 additions & 0 deletions site/content/en/docs/Reference/fleetautoscaler.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ type FleetAutoscaleRequest struct {
Namespace string `json:"namespace"`
// The Fleet's status values
Status v1.FleetStatus `json:"status"`
{{% feature publishVersion="1.48.0" %}}
// Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super late to this party, but new additions will need a feature shortcode. See https://agones.dev/site/docs/contribute/#within-a-page for an example.

Also an addition here: https://github.com/googleforgames/agones/blob/main/site/content/en/docs/Guides/feature-stages.md?plain=1#L41 (also feature shortcode - may need to copy the whole table).

This is because docs get published intermediately, so we need to hold back documentation on unreleased features.

MetaData *metav1.ObjectMeta `json:"metadata,omitempty"`
{{% /feature %}}
}

type FleetAutoscaleResponse struct {
Expand Down