Skip to content

Commit

Permalink
feat: Add CRD Changes and Feature Flag for chain policy (#3880)
Browse files Browse the repository at this point in the history
* Define and add CRD changes for new fleetautoscaler chain policy
* Adds `ScheduledAutoscaler` feature gate
  • Loading branch information
indexjoseph authored Jul 10, 2024
1 parent 31ed93e commit a1a031c
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 95 deletions.
91 changes: 91 additions & 0 deletions examples/chainfleetautoscaler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
# Copyright 2024 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# [Stage:Dev]
# [FeatureFlag:ScheduledAutoscaler]
# Example of a FleetAutoscaler - this is used to scale a Fleet based on a schedule.
#

#
# For a full reference and details: https://agones.dev/site/docs/reference/fleetautoscaler/
#
apiVersion: autoscaling.agones.dev/v1
kind: FleetAutoscaler
metadata:
name: chain-fleet-autoscaler
spec:
policy:
# Chain based policy for autoscaling.
type: Chain
chain:
# Id of chain entry. If not set, the Id will be defaulted to the index of the entry within the chain.
- id: "weekday"
type: Schedule # Schedule based condition.
schedule:
between:
# The policy becomes eligible for application starting on Feb 20, 2024 at 4:04 PM EST. If not set, the policy will immediately be eligible for application.
start: "2024-02-20T16:04:04-05:00"
# The policy becomes ineligible for application on Feb 23, 2024 at 4:04 PM EST. If not set, the policy will always be eligible for application (after the start time).
end: "2024-02-23T16:04:04-05:00"
activePeriod:
# Timezone to be used for the startCron field. Defaults to UTC if not set.
timezone: "America/New_York"
# Start applying the policy everyday at 1:00 AM EST. If not set, the policy will always be applied in the .between window.
# (Only eligible starting on Feb 20, 2024 at 4:04 PM).
startCron: "0 1 * * 0"
# Only apply the policy for 5 hours. If not set, the duration will be defaulted to always/indefinite.
duration: "5h"
# Policy to be applied during the activePeriod. Required.
policy:
type: Buffer
buffer:
bufferSize: 50
minReplicas: 100
maxReplicas: 2000
# Id of chain entry. If not set, the Id will be defaulted to the index of the entry within the chain list.
- id: "weekend"
type: Schedule
schedule:
between:
# The policy becomes eligible for application starting on Feb 24, 2024 at 4:05 PM EST. If not set, the policy will immediately be eligible for application.
start: "2024-02-24T16:04:05-05:00"
# The policy becomes ineligible for application starting on Feb 26, 2024 at 4:05 PM EST. If not set, the policy will always be eligible for application (after the start time).
end: "2024-02-26T16:04:05-05:00"
activePeriod:
# Timezone to be used for the startCron field. Defaults to UTC if not set.
timezone: "America/New_York"
# Start applying the policy everyday at 1:00 AM EST. If not set, the policy will always be applied in the .between window.
# (Only eligible starting on Feb 24, 2024 at 4:05 PM EST)
startCron: "0 1 * * 0"
# Only apply the policy for 7 hours. If not set the duration will be defaulted to always/indefinite.
duration: "7h"
# Policy to be applied during the activePeriod. Required.
policy:
type: Counter
counter:
key: rooms
bufferSize: 10
minCapacity: 500
maxCapacity: 1000
# Id of chain entry. If not set, the Id will be defaulted to the index of the entry within the chain list.
- id: "default"
# Policy will always be applied when no other policy is applicable. Required.
policy:
type: Buffer
buffer:
bufferSize: 5
minReplicas: 100
maxReplicas: 2000
1 change: 1 addition & 0 deletions install/helm/agones/defaultfeaturegates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ PortRanges: false
PortPolicyNone: false

# Dev features
ScheduledAutoscaler: false

# Example feature
Example: false
146 changes: 146 additions & 0 deletions install/helm/agones/templates/crds/_fleetautoscalerpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Copyright 2024 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
{{/* schema for a fleet autoscaler policy */}}
{{- define "fleetautoscaler.policy" }}
policy:
type: object
required:
- type
properties:
type:
type: string
enum:
- Buffer
- Webhook
- Counter
- List
{{- if .includeChainPolicy }}
- Chain
{{- end }}
buffer:
type: object
nullable: true
required:
- maxReplicas
properties:
minReplicas:
type: integer
minimum: 0
maxReplicas:
type: integer
minimum: 1
bufferSize:
x-kubernetes-int-or-string: true
anyOf:
- type: integer
- type: string
webhook:
type: object
nullable: true
properties:
url:
type: string
service:
type: object
required:
- namespace
- name
properties:
namespace:
type: string
name:
type: string
path:
type: string
port:
type: integer
caBundle:
type: string
format: byte
counter:
type: object
nullable: true
required:
- key
- bufferSize
- maxCapacity
properties:
key: # The name of the Counter.
type: string
minCapacity: # Minimum aggregate counter capacity that can be provided by this FleetAutoscaler. If not specified, the actual minimum capacity will be bufferSize.
type: integer
minimum: 0
maxCapacity: # Maximum aggregate counter capacity that can be provided by this FleetAutoscaler. Required.
type: integer
minimum: 1
bufferSize: # Size of a buffer of counted items that are available in the Fleet (available capacity). It can be specified either in absolute (i.e. 5) or percentage format (i.e. 5%).
x-kubernetes-int-or-string: true
anyOf:
- type: integer
- type: string
list:
type: object
nullable: true
required:
- key
- bufferSize
- maxCapacity
properties:
key: # The name of the List.
type: string
minCapacity: # Minimum aggregate list capacity that can be provided by this FleetAutoscaler. If not specified, the actual minimum capacity will be bufferSize.
type: integer
minimum: 0
maxCapacity: # Maximum aggregate list capacity that can be provided by this FleetAutoscaler. Required.
type: integer
minimum: 1
bufferSize: # Size of a buffer based on the list capacity that is available over the current aggregate list length in the Fleet. It can be specified either in absolute (i.e. 5) or percentage format (i.e. 5%).
x-kubernetes-int-or-string: true
anyOf:
- type: integer
- type: string
{{- if .includeChainPolicy }}
chain:
type: array
nullable: true
items:
type: object
nullable: true
required:
- policy
properties:
id: # The Id of a chain entry.
type: string
schedule: # Defines when the policy is applied.
type: object
properties:
between:
type: object
start: # Defines when to start evaluating the active period, must conform to RFC3339.
type: string
end: # Defines when to stop evaluating the active period, must conform to RFC3339.
type: string
activePeriod:
type: object
timezone: # Timezone to be used for the startCron field, must conform with the IANA Time Zone database (e.g. America/New_York).
type: string
startCron: # Cron expression defining when to start applying the policy. All TZ/CRON_TZ specification within startCron will be rejected, please use the timezone field above to specify a timezone. Must conform with UNIX CRON syntax.
type: string
duration: # The length of time the policy should be applied for (e.g. 2h45m).
type: string
{{- include "fleetautoscaler.policy" (dict "includeChainPolicy" false) | indent 12 }} # Defines which policy to apply during the active period. Required.
{{- end }}
{{- end }}
96 changes: 2 additions & 94 deletions install/helm/agones/templates/crds/fleetautoscaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,100 +55,8 @@ spec:
minLength: 1
maxLength: 63
pattern: "^[a-z0-9]([-\\.a-z0-9]*[a-z0-9])?$"
policy:
type: object
required:
- type
properties:
type:
type: string
enum:
- Buffer
- Webhook
- Counter
- List
buffer:
type: object
nullable: true
required:
- maxReplicas
properties:
minReplicas:
type: integer
minimum: 0
maxReplicas:
type: integer
minimum: 1
bufferSize:
x-kubernetes-int-or-string: true
anyOf:
- type: integer
- type: string
webhook:
type: object
nullable: true
properties:
url:
type: string
service:
type: object
required:
- namespace
- name
properties:
namespace:
type: string
name:
type: string
path:
type: string
port:
type: integer
caBundle:
type: string
format: byte
counter:
type: object
nullable: true
required:
- key
- bufferSize
- maxCapacity
properties:
key: # The name of the Counter.
type: string
minCapacity: # Minimum aggregate counter capacity that can be provided by this FleetAutoscaler. If not specified, the actual minimum capacity will be bufferSize.
type: integer
minimum: 0
maxCapacity: # Maximum aggregate counter capacity that can be provided by this FleetAutoscaler. Required.
type: integer
minimum: 1
bufferSize: # Size of a buffer of counted items that are available in the Fleet (available capacity). It can be specified either in absolute (i.e. 5) or percentage format (i.e. 5%).
x-kubernetes-int-or-string: true
anyOf:
- type: integer
- type: string
list:
type: object
nullable: true
required:
- key
- bufferSize
- maxCapacity
properties:
key: # The name of the List.
type: string
minCapacity: # Minimum aggregate list capacity that can be provided by this FleetAutoscaler. If not specified, the actual minimum capacity will be bufferSize.
type: integer
minimum: 0
maxCapacity: # Maximum aggregate list capacity that can be provided by this FleetAutoscaler. Required.
type: integer
minimum: 1
bufferSize: # Size of a buffer based on the list capacity that is available over the current aggregate list length in the Fleet. It can be specified either in absolute (i.e. 5) or percentage format (i.e. 5%).
x-kubernetes-int-or-string: true
anyOf:
- type: integer
- type: string
{{- $featureGates := include "agones.featureGates" . | fromYaml }}
{{- include "fleetautoscaler.policy" (dict "includeChainPolicy" $featureGates.ScheduledAutoscaler) | indent 16 }}
sync:
type: object
required:
Expand Down
2 changes: 1 addition & 1 deletion install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5672,7 +5672,7 @@ spec:
type: string
minLength: 1
maxLength: 63
pattern: "^[a-z0-9]([-\\.a-z0-9]*[a-z0-9])?$"
pattern: "^[a-z0-9]([-\\.a-z0-9]*[a-z0-9])?$"
policy:
type: object
required:
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/runtime/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const (
////////////////
// Dev features

// FeatureScheduledAutoscaler is a feature flag to enable/disable scheduled fleet autoscaling.
FeatureScheduledAutoscaler Feature = "ScheduledAutoscaler"

////////////////
// Example feature

Expand Down Expand Up @@ -141,6 +144,7 @@ var (
FeaturePortPolicyNone: false,

// Dev features
FeatureScheduledAutoscaler: false,

// Example feature
FeatureExample: false,
Expand Down

0 comments on commit a1a031c

Please sign in to comment.