Skip to content

Commit

Permalink
feat: Add API Changes and Validation for FleetAutoscaler Chain Policy (
Browse files Browse the repository at this point in the history
…googleforgames#3893)

* Validation for new `FleetAutoscaler` `Chain` policy 
* Minor fixes to CRD for `Fleetautoscaler` `Chain` policy
  • Loading branch information
indexjoseph authored Jul 29, 2024
1 parent 46c5ef9 commit 1ebec58
Show file tree
Hide file tree
Showing 30 changed files with 4,858 additions and 1,849 deletions.
76 changes: 42 additions & 34 deletions examples/chainfleetautoscaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
# [Stage:Dev]
# [FeatureFlag:ScheduledAutoscaler]
# Example of a FleetAutoscaler - this is used to scale a Fleet based on a schedule.
# Example of a FleetAutoscaler - this is used to scale a Fleet based on a chain.
#

#
Expand All @@ -27,65 +27,73 @@ kind: FleetAutoscaler
metadata:
name: chain-fleet-autoscaler
spec:
fleetName: fleet-example
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.
type: Schedule # Schedule based policy.
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"
# The policy becomes eligible for application starting on Feb 20, 2100 at 4:04 PM EST. If not set, the policy will immediately be eligible for application.
start: "2100-02-20T16:04:04-05:00"
# The policy becomes ineligible for application on Feb 23, 2100 at 4:04 PM EST. If not set, the policy will always be eligible for application (after the start time).
end: "2100-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).
# (Only eligible starting on Feb 20, 2100 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
# 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
type: Schedule # Schedule based policy.
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"
# The policy becomes eligible for application starting on Feb 24, 2100 at 4:05 PM EST. If not set, the policy will immediately be eligible for application.
start: "2100-02-24T16:04:05-05:00"
# The policy becomes ineligible for application starting on Feb 26, 2100 at 4:05 PM EST. If not set, the policy will always be eligible for application (after the start time).
end: "2100-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)
# (Only eligible starting on Feb 24, 2100 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
# 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
type: Buffer
buffer:
bufferSize: 5
minReplicas: 100
maxReplicas: 2000
# The autoscaling sync strategy, this will determine how frequent any schedules within the chain is evaluated.
sync:
# type of the sync. for now, only FixedInterval is available
type: FixedInterval
# parameters of the fixedInterval sync
fixedInterval:
# the time in seconds between each auto scaling
seconds: 30
62 changes: 62 additions & 0 deletions examples/schedulefleetautoscaler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
# 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: schedule-fleet-autoscaler
spec:
fleetName: fleet-example
policy:
# Schedule based policy for autoscaling.
type: Schedule
schedule:
between:
# The policy becomes eligible for application starting on July 4th, 2024 at 4:04 PM PST. If not set, the policy will immediately be eligible for application.
start: "2024-07-04T16:04:04-07:00"
# The policy becomes ineligible for application on Sept 21, 2100 at 4:04 PM PST. If not set, the policy will always be eligible for application (after the start time).
end: "2100-09-21T16:04:04-07:00"
activePeriod:
# Timezone to be used for the startCron field. Defaults to UTC if not set.
timezone: "America/Los_Angeles"
# Start applying the policy everyday at 1:00 AM PST. If not set, the policy will always be applied in the .between window.
# (Only eligible starting on Feb 20, 2100 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
# The autoscaling sync strategy, this will determine how frequent the schedule is evaluated.
sync:
# type of the sync. for now, only FixedInterval is available
type: FixedInterval
# parameters of the fixedInterval sync
fixedInterval:
# the time in seconds between each auto scaling
seconds: 30
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.9.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
53 changes: 34 additions & 19 deletions install/helm/agones/templates/crds/_fleetautoscalerpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@
---
{{/* schema for a fleet autoscaler policy */}}
{{- define "fleetautoscaler.policy" }}
{{- if .includePolicy }}
policy:
type: object
required:
- type
properties:
{{- end }}
type:
type: string
enum:
- Buffer
- Webhook
- Counter
- List
{{- if .includeSchedulePolicy }}
- Schedule
{{- end }}
{{- if .includeChainPolicy }}
- Chain
{{- end }}
Expand Down Expand Up @@ -112,6 +117,33 @@ policy:
anyOf:
- type: integer
- type: string
{{- if .includeSchedulePolicy }}
schedule: # Defines when the policy is applied.
type: object
nullable: true
required:
- policy
properties:
between:
type: object
nullable: true
properties:
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
nullable: true
properties:
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 "includeSchedulePolicy" false "includePolicy" true) | indent 8 }}
{{- end }}
{{- if .includeChainPolicy }}
chain:
type: array
Expand All @@ -120,27 +152,10 @@ policy:
type: object
nullable: true
required:
- policy
- type
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.
{{- include "fleetautoscaler.policy" (dict "includeChainPolicy" false "includeSchedulePolicy" true "includePolicy" false) | indent 6 }} # Defines which policy to apply during the active period. Required.
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion install/helm/agones/templates/crds/fleetautoscaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
maxLength: 63
pattern: "^[a-z0-9]([-\\.a-z0-9]*[a-z0-9])?$"
{{- $featureGates := include "agones.featureGates" . | fromYaml }}
{{- include "fleetautoscaler.policy" (dict "includeChainPolicy" $featureGates.ScheduledAutoscaler) | indent 16 }}
{{- include "fleetautoscaler.policy" (dict "includeChainPolicy" $featureGates.ScheduledAutoscaler "includeSchedulePolicy" $featureGates.ScheduledAutoscaler "includePolicy" true) | indent 16 }}
sync:
type: object
required:
Expand Down
Loading

0 comments on commit 1ebec58

Please sign in to comment.