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

feature: sidecar support #191

Merged
merged 1 commit into from
Oct 15, 2023
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
3 changes: 2 additions & 1 deletion api/v1beta2/tortoise_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ type RecommendedContainerResources struct {
// ContainerName is the name of target container.
ContainerName string `json:"containerName" protobuf:"bytes,1,name=containerName"`
// RecommendedResource is the recommendation calculated by the tortoise.
//
// If AutoscalingPolicy is vertical, it's the same value as the VPA suggests.
// If AutoscalingPolicy is horizontal, it's basically the same value as the current resource request.
// But, when the number of replicas are too small or too large,
Expand Down Expand Up @@ -324,7 +325,7 @@ type ContainerRecommendationFromVPA struct {
// MaxRecommendation is the max recommendation value from VPA in a certain period (1 week).
// Tortoise generates all recommendation based on this MaxRecommendation.
MaxRecommendation map[v1.ResourceName]ResourceQuantity `json:"maxRecommendation" protobuf:"bytes,2,name=maxRecommendation"`
// Recommendation is the latest recommendation value from VPA.
// Recommendation is the recommendation value from VPA that the tortoise controller observed in the last reconciliation..
Recommendation map[v1.ResourceName]ResourceQuantity `json:"recommendation" protobuf:"bytes,3,name=recommendation"`
}

Expand Down
16 changes: 14 additions & 2 deletions api/v1beta2/tortoise_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/mercari/tortoise/pkg/annotation"
)

// log is for logging in this package.
Expand Down Expand Up @@ -83,8 +85,18 @@ func (r *Tortoise) Default() {
return
}

if len(d.Spec.Template.Spec.Containers) != len(r.Spec.ResourcePolicy) {
for _, c := range d.Spec.Template.Spec.Containers {
containers := d.Spec.Template.Spec.DeepCopy().Containers
if d.Annotations != nil {
if v, ok := d.Annotations[annotation.IstioSidecarInjectionAnnotation]; ok && v == "true" {
// If the deployment has the sidecar injection annotation, the Pods will have the sidecar container in addition.
containers = append(d.Spec.Template.Spec.Containers, v1.Container{
Name: "istio-proxy",
})
}
}

if len(containers) != len(r.Spec.ResourcePolicy) {
for _, c := range containers {
policyExist := false
for _, p := range r.Spec.ResourcePolicy {
if c.Name == p.ContainerName {
Expand Down
13 changes: 7 additions & 6 deletions config/crd/bases/autoscaling.mercari.com_tortoises.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,9 @@ spec:
format: date-time
type: string
type: object
description: Recommendation is the latest recommendation
value from VPA.
description: Recommendation is the recommendation value
from VPA that the tortoise controller observed in the
last reconciliation..
type: object
required:
- containerName
Expand Down Expand Up @@ -1132,15 +1133,15 @@ spec:
- 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: RecommendedResource is the recommendation
calculated by the tortoise. If AutoscalingPolicy is
vertical, it's the same value as the VPA suggests.
description: "RecommendedResource is the recommendation
calculated by the tortoise. \n If AutoscalingPolicy
is vertical, it's the same value as the VPA suggests.
If AutoscalingPolicy is horizontal, it's basically
the same value as the current resource request. But,
when the number of replicas are too small or too large,
tortoise may try to increase/decrease the amount of
resources given to the container, so that the number
of replicas won't be very small or very large.
of replicas won't be very small or very large."
type: object
containerName:
description: ContainerName is the name of target container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ status:
cpu: "3"
memory: 3Gi
upperBound:
cpu: "5"
memory: 5Gi
cpu: "350m"
memory: 3.5Gi
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ status:
- containerName: app
maxRecommendation:
cpu:
quantity: "3"
quantity: "10"
updatedAt: null
memory:
quantity: 3Gi
quantity: 10Gi
updatedAt: null
recommendation:
cpu:
quantity: "3"
quantity: "10"
updatedAt: null
memory:
quantity: 3Gi
quantity: 10Gi
updatedAt: null
- containerName: istio-proxy
maxRecommendation:
cpu:
quantity: "3"
quantity: "4"
updatedAt: null
memory:
quantity: 3Gi
quantity: 4Gi
updatedAt: null
recommendation:
cpu:
quantity: "3"
quantity: "4"
updatedAt: null
memory:
quantity: 3Gi
quantity: 4Gi
updatedAt: null
recommendations:
horizontal:
Expand All @@ -71,12 +71,12 @@ status:
vertical:
containerResourceRecommendation:
- RecommendedResource:
cpu: "3"
memory: 3Gi
cpu: "10"
memory: 10Gi
containerName: app
- RecommendedResource:
cpu: "3"
memory: 3Gi
cpu: "4"
memory: 4Gi
containerName: istio-proxy
targets:
verticalPodAutoscalers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ status:
cpu: "3"
memory: 3Gi
upperBound:
cpu: "5"
memory: 5Gi
cpu: "350m"
memory: 3.5Gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
metadata:
annotations:
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true"
tortoises.autoscaling.mercari.com/tortoise-name: mercari
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: 20
metrics:
- containerResource:
container: app
name: cpu
target:
averageUtilization: 50
type: Utilization
type: ContainerResource
- containerResource:
container: istio-proxy
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,108 @@
metadata:
name: mercari
namespace: default
spec:
resourcePolicy:
- autoscalingPolicy:
cpu: Horizontal
memory: Vertical
containerName: app
- autoscalingPolicy:
cpu: Horizontal
memory: Vertical
containerName: istio-proxy
targetRefs:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: mercari-app
status:
conditions:
tortoiseConditions:
- message: "HPA target utilization is updated"
reason: HPATargetUtilizationUpdated
status: "True"
type: HPATargetUtilizationUpdated
containerRecommendationFromVPA:
- containerName: app
maxRecommendation:
cpu:
quantity: "3"
updatedAt: null
memory:
quantity: 3Gi
updatedAt: null
recommendation:
cpu:
quantity: "3"
updatedAt: null
memory:
quantity: 3Gi
updatedAt: null
- containerName: istio-proxy
maxRecommendation:
cpu:
quantity: "3"
updatedAt: null
memory:
quantity: 3Gi
updatedAt: null
recommendation:
cpu:
quantity: "3"
updatedAt: null
memory:
quantity: 3Gi
updatedAt: null
recommendations:
horizontal:
maxReplicas:
- from: 0
timezone: Local
to: 24
updatedAt: "2023-10-06T01:15:46Z"
value: 20
minReplicas:
- from: 0
timezone: Local
to: 24
updatedAt: "2023-10-06T01:15:46Z"
value: 5
targetUtilizations:
- containerName: app
targetUtilization:
cpu: 50
- containerName: istio-proxy
targetUtilization:
cpu: 75
vertical:
containerResourceRecommendation:
- RecommendedResource:
cpu: "6"
memory: 3Gi
containerName: app
- RecommendedResource:
cpu: "4"
memory: 3Gi
containerName: istio-proxy
targets:
horizontalPodAutoscaler: tortoise-hpa-mercari
verticalPodAutoscalers:
- name: tortoise-updater-mercari
role: Updater
- name: tortoise-monitor-mercari
role: Monitor
tortoisePhase: Working
containerResourcePhases:
- containerName: "app"
resourcePhases:
cpu:
phase: Working
memory:
phase: Working
- containerName: "istio-proxy"
resourcePhases:
cpu:
phase: Working
memory:
phase: Working
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
metadata:
annotations:
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true"
tortoises.autoscaling.mercari.com/tortoise-name: mercari
name: tortoise-monitor-mercari
namespace: default
spec:
resourcePolicy:
containerPolicies:
- containerName: app
- containerName: istio-proxy
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
- containerName: istio-proxy
lowerBound:
cpu: "3"
memory: 3Gi
target:
cpu: "3"
memory: 3Gi
upperBound:
cpu: "5"
memory: 5Gi
Loading
Loading