Skip to content

Commit

Permalink
implement MaxAllocatedResources and MaxReplicas in Tortoise (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho authored Mar 28, 2024
1 parent 2125c80 commit 097a5c9
Show file tree
Hide file tree
Showing 18 changed files with 1,438 additions and 552 deletions.
13 changes: 12 additions & 1 deletion api/v1beta3/tortoise_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ type TortoiseSpec struct {
// The AutoscalingPolicy field is mutable; you can modify it at any time, whether from an empty state to populated or vice versa.
// +optional
AutoscalingPolicy []ContainerAutoscalingPolicy `json:"autoscalingPolicy,omitempty" protobuf:"bytes,5,opt,name=autoscalingPolicy"`
// MaxReplicas is the maximum number of MaxReplicas that Tortoise will give to HPA.
// If nil, Tortoise uses the cluster wide default value, which can be configured via the admin config.
// +optional
MaxReplicas *int32 `json:"maxReplicas,omitempty" protobuf:"bytes,6,opt,name=maxReplicas"`
}

type ContainerAutoscalingPolicy struct {
Expand All @@ -100,14 +104,21 @@ type ContainerResourcePolicy struct {
// ContainerName is the name of target container.
ContainerName string `json:"containerName" protobuf:"bytes,1,name=containerName"`
// MinAllocatedResources is the minimum amount of resources which is given to the container.
// Tortoise never set the resources request on the container than MinAllocatedResources.
// Tortoise never set the resources request on the container less than MinAllocatedResources.
// If nil, Tortoise uses the cluster wide default value, which can be configured via the admin config.
//
// If empty, tortoise may reduce the resource request to the value which is suggested from VPA.
// Given the VPA suggests values based on the historical resource usage,
// you have no choice but to use MinAllocatedResources to pre-scaling your Pods,
// for example, when maybe your application change will result in consuming resources more than the past.
// +optional
MinAllocatedResources v1.ResourceList `json:"minAllocatedResources,omitempty" protobuf:"bytes,2,opt,name=minAllocatedResources"`

// MaxAllocatedResources is the maximum amount of resources which is given to the container.
// Tortoise never set the resources request on the container more than MaxAllocatedResources.
// If nil, Tortoise uses the cluster wide default value, which can be configured via the admin config.
// +optional
MaxAllocatedResources v1.ResourceList `json:"maxAllocatedResources,omitempty" protobuf:"bytes,3,opt,name=maxAllocatedResources"`
}

// +kubebuilder:validation:Enum=DeleteAll;NoDelete
Expand Down
12 changes: 12 additions & 0 deletions api/v1beta3/zz_generated.deepcopy.go

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

34 changes: 27 additions & 7 deletions config/crd/bases/autoscaling.mercari.com_tortoises.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ spec:
- DeleteAll
- NoDelete
type: string
maxReplicas:
description: MaxReplicas is the maximum number of MaxReplicas that
Tortoise will give to HPA. If nil, Tortoise uses the cluster wide
default value, which can be configured via the admin config.
format: int32
type: integer
resourcePolicy:
description: ResourcePolicy contains the policy how each resource
is updated.
Expand All @@ -111,6 +117,19 @@ spec:
containerName:
description: ContainerName is the name of target container.
type: string
maxAllocatedResources:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: MaxAllocatedResources is the maximum amount of
resources which is given to the container. Tortoise never
set the resources request on the container more than MaxAllocatedResources.
If nil, Tortoise uses the cluster wide default value, which
can be configured via the admin config.
type: object
minAllocatedResources:
additionalProperties:
anyOf:
Expand All @@ -120,13 +139,14 @@ spec:
x-kubernetes-int-or-string: true
description: "MinAllocatedResources is the minimum amount of
resources which is given to the container. Tortoise never
set the resources request on the container than MinAllocatedResources.
\n If empty, tortoise may reduce the resource request to the
value which is suggested from VPA. Given the VPA suggests
values based on the historical resource usage, you have no
choice but to use MinAllocatedResources to pre-scaling your
Pods, for example, when maybe your application change will
result in consuming resources more than the past."
set the resources request on the container less than MinAllocatedResources.
If nil, Tortoise uses the cluster wide default value, which
can be configured via the admin config. \n If empty, tortoise
may reduce the resource request to the value which is suggested
from VPA. Given the VPA suggests values based on the historical
resource usage, you have no choice but to use MinAllocatedResources
to pre-scaling your Pods, for example, when maybe your application
change will result in consuming resources more than the past."
type: object
required:
- containerName
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
metadata:
name: mercari-app
namespace: default
spec:
selector:
matchLabels:
app: mercari
strategy: {}
template:
metadata:
annotations:
kubectl.kubernetes.io/restartedAt: "2023-01-01T00:00:00Z"
creationTimestamp: null
labels:
app: mercari
spec:
containers:
- image: awesome-mercari-app-image
name: app
resources:
requests:
cpu: "4"
memory: 4Gi
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
metadata:
annotations:
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true"
name: tortoise-hpa-mercari
namespace: default
spec:
behavior:
scaleDown:
policies:
- periodSeconds: 90
type: Percent
value: 2
selectPolicy: Max
scaleUp:
policies:
- periodSeconds: 60
type: Percent
value: 100
selectPolicy: Max
stabilizationWindowSeconds: 0
maxReplicas: 10
metrics:
- external:
metric:
name: hoge-kept-metric
target:
type: Value
value: "1"
type: External
- containerResource:
container: app
name: cpu
target:
averageUtilization: 75
type: Utilization
type: ContainerResource
minReplicas: 5
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: mercari-app
status:
currentMetrics: null
desiredReplicas: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
metadata:
finalizers:
- tortoise.autoscaling.mercari.com/finalizer
name: mercari
namespace: default
spec:
maxReplicas: 10
resourcePolicy:
- containerName: app
maxAllocatedResources:
cpu: "1"
memory: 1Gi
targetRefs:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: mercari-app
status:
autoscalingPolicy:
- containerName: app
policy:
cpu: Horizontal
memory: Vertical
conditions:
containerRecommendationFromVPA:
- containerName: app
maxRecommendation:
cpu:
quantity: "3"
updatedAt: "2023-01-01T00:00:00Z"
memory:
quantity: 3Gi
updatedAt: "2023-01-01T00:00:00Z"
recommendation:
cpu:
quantity: "3"
updatedAt: "2023-01-01T00:00:00Z"
memory:
quantity: 3Gi
updatedAt: "2023-01-01T00:00:00Z"
containerResourceRequests:
- containerName: app
resource:
cpu: "1"
memory: 1Gi
tortoiseConditions:
- lastTransitionTime: "2023-01-01T00:00:00Z"
lastUpdateTime: "2023-01-01T00:00:00Z"
message: the current number of replicas is not bigger than the preferred max
replica number
reason: ScaledUpBasedOnPreferredMaxReplicas
status: "False"
type: ScaledUpBasedOnPreferredMaxReplicas
- lastTransitionTime: "2023-01-01T00:00:00Z"
lastUpdateTime: "2023-01-01T00:00:00Z"
message: HPA target utilization is updated
reason: HPATargetUtilizationUpdated
status: "True"
type: HPATargetUtilizationUpdated
- lastTransitionTime: "2023-01-01T00:00:00Z"
lastUpdateTime: "2023-01-01T00:00:00Z"
message: The recommendation is provided
status: "True"
type: VerticalRecommendationUpdated
- lastTransitionTime: "2023-01-01T00:00:00Z"
lastUpdateTime: "2023-01-01T00:00:00Z"
status: "False"
type: FailedToReconcile
containerResourcePhases:
- containerName: app
resourcePhases:
cpu:
lastTransitionTime: null
phase: Working
memory:
lastTransitionTime: "2023-01-01T00:00:00Z"
phase: Working
recommendations:
horizontal:
maxReplicas:
- from: 0
timezone: Local
to: 24
updatedAt: "2023-01-01T00:00:00Z"
value: 20
minReplicas:
- from: 0
timezone: Local
to: 24
updatedAt: "2023-01-01T00:00:00Z"
value: 5
targetUtilizations:
- containerName: app
targetUtilization:
cpu: 75
vertical:
containerResourceRecommendation:
- RecommendedResource:
cpu: "1"
memory: 1Gi
containerName: app
targets:
horizontalPodAutoscaler: tortoise-hpa-mercari
scaleTargetRef:
kind: ""
name: ""
verticalPodAutoscalers:
- name: tortoise-monitor-mercari
role: Monitor
tortoisePhase: Working
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
metadata:
annotations:
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true"
name: tortoise-monitor-mercari
namespace: default
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: mercari-app
updatePolicy:
updateMode: "Off"
status:
conditions:
- lastTransitionTime: null
status: "True"
type: RecommendationProvided
recommendation:
containerRecommendations:
- containerName: app
lowerBound:
cpu: "3"
memory: 3Gi
target:
cpu: "3"
memory: 3Gi
upperBound:
cpu: "5"
memory: 5Gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
metadata:
name: mercari-app
namespace: default
spec:
selector:
matchLabels:
app: mercari
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: mercari
spec:
containers:
- image: awesome-mercari-app-image
name: app
resources:
requests:
cpu: "4"
memory: 4Gi
replicas: 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
metadata:
annotations:
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true"
name: tortoise-hpa-mercari
namespace: default
spec:
behavior:
scaleDown:
policies:
- periodSeconds: 90
type: Percent
value: 2
selectPolicy: Max
scaleUp:
policies:
- periodSeconds: 60
type: Percent
value: 100
selectPolicy: Max
stabilizationWindowSeconds: 0
maxReplicas: 100
metrics:
- external:
metric:
name: hoge-kept-metric
target:
type: Value
value: "1"
type: External
- external:
metric:
name: hoge-exclude-metric
target:
type: Value
value: "1"
type: External
- containerResource:
container: app
name: cpu
target:
averageUtilization: 50
type: Utilization
type: ContainerResource
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: mercari-app

Loading

0 comments on commit 097a5c9

Please sign in to comment.