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

Make sure target annotations can exceed the configured default values. #5991

Merged
merged 1 commit into from
Nov 11, 2019
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
20 changes: 11 additions & 9 deletions pkg/reconciler/autoscaling/resources/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@ func ResolveMetricTarget(pa *v1alpha1.PodAutoscaler, config *autoscaler.Config)
tu = config.ContainerConcurrencyTargetFraction
}

// Use the target provided via annotation, if applicable.
if annotationTarget, ok := pa.Target(); ok {
total = annotationTarget
if pa.Metric() == autoscaling.Concurrency && pa.Spec.ContainerConcurrency != 0 {
// We pick the smaller value between container concurrency and the annotationTarget
// to make sure the autoscaler does not aim for a higher concurrency than the application
// can handle per containerConcurrency.
total = math.Min(annotationTarget, float64(pa.Spec.ContainerConcurrency))
}
}

if v, ok := pa.TargetUtilization(); ok {
tu = v
}
target = math.Max(1, total*tu)

// Use the target provided via annotation, if applicable.
if annotationTarget, ok := pa.Target(); ok {
// We pick the smaller value between the calculated target and the annotationTarget
// to make sure the autoscaler does not aim for a higher concurrency than the application
// can handle per containerConcurrency.
target = math.Max(1, math.Min(target, annotationTarget*tu))
total = math.Min(annotationTarget, total)
}

return target, total
}
11 changes: 8 additions & 3 deletions pkg/reconciler/autoscaling/resources/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ func TestResolveMetricTarget(t *testing.T) {
pa: pa(WithPAContainerConcurrency(10), WithTargetAnnotation("1")),
wantTgt: 1,
wantTot: 1,
}, {
name: "with target annotation greater than default (ok)",
pa: pa(WithTargetAnnotation("500")),
wantTgt: 500,
wantTot: 500,
}, {
name: "with target annotation greater than container concurrency (ignore annotation for safety)",
pa: pa(WithPAContainerConcurrency(1), WithTargetAnnotation("10")),
Expand All @@ -152,10 +157,10 @@ func TestResolveMetricTarget(t *testing.T) {
wantTgt: 150,
wantTot: 200,
}, {
name: "RPS: with target annotation greater than default (ignore annotation for safety)",
name: "RPS: with target annotation greater than default",
pa: pa(WithMetricAnnotation(autoscaling.RPS), WithTargetAnnotation("300")),
wantTgt: 140,
wantTot: 200,
wantTgt: 210,
wantTot: 300,
}}

for _, tc := range cases {
Expand Down