-
Notifications
You must be signed in to change notification settings - Fork 459
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
[HPA] Move maxReplicas and minReplicas to AutoscalerSpec #1302
Changes from all commits
efc8b83
a3332c3
bc15ac7
9497898
cc3b520
909493b
bde02df
daff09c
33bb00f
006ec9e
8a53679
020a52c
4602daa
d9e9ae8
8a6f4bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: deprecation | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action) | ||
component: Autoscaler | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: This PR moves MaxReplicas and MinReplicas to .Spec.Autoscaler | ||
|
||
# One or more tracking issues related to the change | ||
issues: | ||
- 1115 | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,11 +67,22 @@ func (r *OpenTelemetryCollector) Default() { | |
r.Spec.TargetAllocator.Replicas = &one | ||
} | ||
|
||
if r.Spec.MaxReplicas != nil { | ||
if r.Spec.MaxReplicas != nil || (r.Spec.Autoscaler != nil && r.Spec.Autoscaler.MaxReplicas != nil) { | ||
if r.Spec.Autoscaler == nil { | ||
r.Spec.Autoscaler = &AutoscalerSpec{} | ||
} | ||
|
||
if r.Spec.Autoscaler.MaxReplicas == nil { | ||
r.Spec.Autoscaler.MaxReplicas = r.Spec.MaxReplicas | ||
} | ||
if r.Spec.Autoscaler.MinReplicas == nil { | ||
if r.Spec.MinReplicas != nil { | ||
r.Spec.Autoscaler.MinReplicas = r.Spec.MinReplicas | ||
} else { | ||
r.Spec.Autoscaler.MinReplicas = r.Spec.Replicas | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure that this is correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I believe the logic is correct, but maybe there's something I'm missing?
Wondering your thoughts and why this might not be the desired logic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Originally I thought that the idea here is to totally decouple these two. But it's reasonable to default to the |
||
} | ||
} | ||
|
||
if r.Spec.Autoscaler.TargetMemoryUtilization == nil && r.Spec.Autoscaler.TargetCPUUtilization == nil { | ||
defaultCPUTarget := int32(90) | ||
r.Spec.Autoscaler.TargetCPUUtilization = &defaultCPUTarget | ||
|
@@ -149,21 +160,45 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error { | |
} | ||
} | ||
|
||
maxReplicas := new(int32) | ||
if r.Spec.Autoscaler != nil && r.Spec.Autoscaler.MaxReplicas != nil { | ||
maxReplicas = r.Spec.Autoscaler.MaxReplicas | ||
} | ||
|
||
// check deprecated .Spec.MaxReplicas if maxReplicas is not set | ||
if *maxReplicas == 0 { | ||
maxReplicas = r.Spec.MaxReplicas | ||
} | ||
|
||
minReplicas := new(int32) | ||
if r.Spec.Autoscaler != nil && r.Spec.Autoscaler.MinReplicas != nil { | ||
minReplicas = r.Spec.Autoscaler.MinReplicas | ||
} | ||
|
||
// check deprecated .Spec.MinReplicas if minReplicas is not set | ||
if *minReplicas == 0 { | ||
if r.Spec.MinReplicas != nil { | ||
minReplicas = r.Spec.MinReplicas | ||
} else { | ||
minReplicas = r.Spec.Replicas | ||
} | ||
} | ||
|
||
// validate autoscale with horizontal pod autoscaler | ||
if r.Spec.MaxReplicas != nil { | ||
if *r.Spec.MaxReplicas < int32(1) { | ||
if maxReplicas != nil { | ||
if *maxReplicas < int32(1) { | ||
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, maxReplicas should be defined and one or more") | ||
} | ||
|
||
if r.Spec.Replicas != nil && *r.Spec.Replicas > *r.Spec.MaxReplicas { | ||
if r.Spec.Replicas != nil && *r.Spec.Replicas > *maxReplicas { | ||
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, replicas must not be greater than maxReplicas") | ||
} | ||
|
||
if r.Spec.MinReplicas != nil && *r.Spec.MinReplicas > *r.Spec.MaxReplicas { | ||
if minReplicas != nil && *minReplicas > *maxReplicas { | ||
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, minReplicas must not be greater than maxReplicas") | ||
} | ||
|
||
if r.Spec.MinReplicas != nil && *r.Spec.MinReplicas < int32(1) { | ||
if minReplicas != nil && *minReplicas < int32(1) { | ||
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, minReplicas should be one or more") | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
resources: | ||
- manager.yaml | ||
- manager.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test case for this in the webhook unit test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test case already covers the case when r.Spec.Autoscaler.MaxReplicas == nil. I have now added test case for when r.Spec.Autoscaler.MaxReplicas != nil