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

Validation added for initialScale greater than maxScale (#14153) #14682

Closed
wants to merge 1 commit into from

Conversation

yp969803
Copy link

Fixes #14153

Proposed Changes

  • Added a validation for initialScale > maxScale
  • As initialScale > maxScale not making sense at all. As it is not depending on traffic.

Release Note

none

@knative-prow knative-prow bot requested review from dprotaso and kauana November 29, 2023 19:04
@knative-prow knative-prow bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 29, 2023
Copy link

knative-prow bot commented Nov 29, 2023

Hi @yp969803. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow knative-prow bot added area/API API objects and controllers area/autoscale labels Nov 29, 2023
@dprotaso
Copy link
Member

dprotaso commented Dec 7, 2023

/ok-to-test

@knative-prow knative-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 7, 2023

func validateMaxInitialScale(config *autoscalerconfig.Config, m map[string]string) *apis.FieldError{

max,errs := getIntGE0(m,MaxScaleAnnotation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These annotations could be omitted from the revision so you would need to handle that

see

if k, v, ok := InitialScaleAnnotation.Get(m); ok {

yp969803 added a commit to yp969803/serving that referenced this pull request Jan 2, 2024
@knative-prow knative-prow bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 2, 2024
yp969803 added a commit to yp969803/serving that referenced this pull request Jan 2, 2024
@yp969803
Copy link
Author

yp969803 commented Jan 2, 2024

@dprotaso i have added the further annotations can you review

Copy link

codecov bot commented Jan 12, 2024

Codecov Report

Attention: 29 lines in your changes are missing coverage. Please review.

Comparison is base (81149da) 86.05% compared to head (2579cc1) 85.81%.
Report is 39 commits behind head on main.

❗ Current head 2579cc1 differs from pull request most recent head 6ef38fa. Consider uploading reports for the commit 6ef38fa to get more accurate results

Files Patch % Lines
pkg/apis/autoscaling/annotation_validation.go 0.00% 29 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14682      +/-   ##
==========================================
- Coverage   86.05%   85.81%   -0.24%     
==========================================
  Files         197      197              
  Lines       14937    14974      +37     
==========================================
- Hits        12854    12850       -4     
- Misses       1774     1810      +36     
- Partials      309      314       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 286 to 300
if (initial<0){
errs=errs.Also(&apis.FieldError{
Message: fmt.Sprintf("initial-scale=%d should be greater than 0", initial),
Paths: []string{MaxScaleAnnotationKey,InitialScaleAnnotationKey},
})
}else if !config.AllowZeroInitialScale && initial==0 {
errs=errs.Also(&apis.FieldError{
Message: fmt.Sprintf("initial-scale=%d not allowed by cluster", initial),
Paths: []string{MaxScaleAnnotationKey,InitialScaleAnnotationKey},
})
}else if max<=0{
errs=errs.Also(&apis.FieldError{
Message: fmt.Sprintf("max-scale=%d should be greate than 0",max),
Paths: []string{MaxScaleAnnotationKey,InitialScaleAnnotationKey},
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these assertions are needed - we validate InitialScale here

func validateInitialScale(config *autoscalerconfig.Config, m map[string]string) *apis.FieldError {

We validate max scale here

func validateMinMaxScale(config *autoscalerconfig.Config, m map[string]string) *apis.FieldError {

We just need to perform validation if initial scale and max scale are present then do the comparison.

See here for examples:

func validateMinMaxScale(config *autoscalerconfig.Config, m map[string]string) *apis.FieldError {

pkg/apis/autoscaling/annotation_validation.go Outdated Show resolved Hide resolved
Copy link

knative-prow bot commented Jan 16, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yp969803
Once this PR has been reviewed and has the lgtm label, please ask for approval from dprotaso. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

yp969803 added a commit to yp969803/serving that referenced this pull request Jan 16, 2024
@knative-prow knative-prow bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 16, 2024
@yp969803
Copy link
Author

@dprotaso i have updated the pr you can review, adding test is left

Copy link
Member

@dprotaso dprotaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the CI jobs

  • code doesn't compile
  • you'll need to use gofmt to format the code (linter is complaining)

Secondly, please add a unit test

Comment on lines 294 to 299
if initial > max {
return &apis.FieldError{
Message: fmt.Sprintf("max-scale=%d is less than initial-scale=%d", max, initial),
Paths: []string{MaxScaleAnnotationKey,InitialScaleAnnotationKey},
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails when the max scale annotation is not present since max will be equal to zero

yp969803 added a commit to yp969803/serving that referenced this pull request Jan 16, 2024
yp969803 added a commit to yp969803/serving that referenced this pull request Jan 16, 2024
@knative-prow knative-prow bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 16, 2024
@yp969803
Copy link
Author

@dprotaso updated the pr and added the unit test

Copy link

knative-prow bot commented Jan 18, 2024

@yp969803: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
unit-tests_serving_main 6ef38fa link true /test unit-tests

Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@yp969803
Copy link
Author

@dprotaso any stuff left?

@dprotaso
Copy link
Member

CI is failing - see the GitHub checks - I'll wait for them to go green before reviewing again

@dprotaso
Copy link
Member

Hey @yp969803 the unit tests that are failing is the code you've modified can you take a look?

@dprotaso
Copy link
Member

dprotaso commented Mar 5, 2024

Going to close this out due to inactivity.

@dprotaso dprotaso closed this Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/API API objects and controllers area/autoscale ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autoscaler max-scale is ignored when initial-scale is set to a greater value
2 participants