Skip to content

Commit

Permalink
allow empty autoscalingPolicy tortoise (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho authored Dec 25, 2023
1 parent 08f7142 commit 48ec800
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ You don't need a rearing cage, but need VPA in your Kubernetes cluster before in
Many developers are working in Mercari, and not all of them are the experts of Kubernetes.
The platform has many tools and guides to simplify the task of optimizing resource requests,
but it takes a lot of human effort because the situation around the applications gets changed very frequently and we have to keep optimizing them every time.
(e.g., the implementation change could change the resource consumption, the amount of traffic could be changed, etc)
(e.g., the implementation change could change the way of consuming resources, the amount of traffic could be changed, etc)

Also, there are another important component to be optimized for the optimization, which is HorizontalPodAutoscaler.
Also, there are another important component to be optimized for the K8s resource optimization, which is HorizontalPodAutoscaler.
It’s not a simple problem which we just set the target utilization as high as possible –
there are many scenarios where the actual resource utilization doesn’t reach the target resource utilization
(because of multiple containers, minReplicas, container’s size etc).
(because of multiple containers, minReplicas, unbalanced container’s size etc).

To reduce the human effort to keep optimizing the workloads,
the platform team start to have Tortoise , which is designed to simplify the interface of autoscaling.
the platform team start to have Tortoise, which is designed to simplify the interface of autoscaling for users.

It aims to move the responsibility of optimizing the workloads from the application teams to tortoises.
Application teams just need to set up Tortoise, and the platform team will never bother them again for the resource optimization -
Expand Down
12 changes: 12 additions & 0 deletions api/v1beta3/testdata/mutating/no-autoscaling-policy/after.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: autoscaling.mercari.com/v1beta3
kind: Tortoise
metadata:
name: tortoise-sample
namespace: default
spec:
updateMode: "Off"
deletionPolicy: "NoDelete"
targetRefs:
scaleTargetRef:
kind: Deployment
name: sample
12 changes: 12 additions & 0 deletions api/v1beta3/testdata/mutating/no-autoscaling-policy/before.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: autoscaling.mercari.com/v1beta3
kind: Tortoise
metadata:
name: tortoise-sample
namespace: default
spec:
updateMode: "Off"
deletionPolicy: "NoDelete"
targetRefs:
scaleTargetRef:
kind: Deployment
name: sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample
namespace: default
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
annotations:
sidecar.istio.io/inject: "true"
labels:
app: nginx
spec:
containers:
- name: hoge
image: hoge:1.0.0
ports:
- containerPort: 81
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
6 changes: 5 additions & 1 deletion api/v1beta3/testdata/mutating/with-istio/before.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ spec:
targetRefs:
scaleTargetRef:
kind: Deployment
name: sample
name: sample
autoscalingPolicy:
- containerName: hoge
policy:
cpu: "Off"
8 changes: 4 additions & 4 deletions api/v1beta3/tortoise_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func TortoiseDefaultHPAName(tortoiseName string) string {
func (r *Tortoise) defaultAutoscalingPolicy() {
ctx := context.Background()

if r.Spec.AutoscalingPolicy == nil {
return
}

// TODO: support other resources.
if r.Spec.TargetRefs.ScaleTargetRef.Kind == "Deployment" {
d, err := ClientService.GetDeploymentOnTortoise(ctx, r)
Expand Down Expand Up @@ -163,10 +167,6 @@ func validateTortoise(t *Tortoise) error {
return fmt.Errorf("%s: emergency mode is only available for tortoises with Running phase", fieldPath.Child("updateMode"))
}

if !hasHorizontal(t) && t.Spec.TargetRefs.HorizontalPodAutoscalerName != nil {
return fmt.Errorf("%s: at least one policy should be Horizontal when HorizontalPodAutoscalerName isn't nil", fieldPath.Child("resourcePolicy", "autoscalingPolicy"))
}

return nil
}

Expand Down
3 changes: 3 additions & 0 deletions api/v1beta3/tortoise_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ var _ = Describe("Tortoise Webhook", func() {
It("nothing to do", func() {
mutateTest(filepath.Join("testdata", "mutating", "nothing-to-do", "before.yaml"), filepath.Join("testdata", "mutating", "nothing-to-do", "after.yaml"), filepath.Join("testdata", "mutating", "nothing-to-do", "deployment.yaml"), "")
})
It("nothing to do (empty autoscaling policy)", func() {
mutateTest(filepath.Join("testdata", "mutating", "no-autoscaling-policy", "before.yaml"), filepath.Join("testdata", "mutating", "no-autoscaling-policy", "after.yaml"), filepath.Join("testdata", "mutating", "no-autoscaling-policy", "deployment.yaml"), "")
})
It("should mutate a Tortoise with istio", func() {
mutateTest(filepath.Join("testdata", "mutating", "with-istio", "before.yaml"), filepath.Join("testdata", "mutating", "with-istio", "after.yaml"), filepath.Join("testdata", "mutating", "with-istio", "deployment.yaml"), "")
})
Expand Down

0 comments on commit 48ec800

Please sign in to comment.