-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add resource validation #4798
Add resource validation #4798
Conversation
|
Welcome @mowangdk! |
1ed2ae4
to
68d7593
Compare
68d7593
to
4ce04dd
Compare
@jbartosik PTAL |
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.
Thank you for the change. I left a few comments. (Also I'll respond faster in the future)
vertical-pod-autoscaler/pkg/admission-controller/resource/vpa/handler.go
Outdated
Show resolved
Hide resolved
vertical-pod-autoscaler/pkg/admission-controller/resource/vpa/handler.go
Outdated
Show resolved
Hide resolved
vertical-pod-autoscaler/pkg/admission-controller/resource/vpa/handler_test.go
Show resolved
Hide resolved
4ce04dd
to
93febe6
Compare
93febe6
to
48b4e45
Compare
@jbartosik comments fixed, ptal |
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.
Thank you. I think this is close to being ready for submit.
There is one change needed (validate resolution of max even if there is no corresponding min). I also left a few requests for smaller improvements.
expectError: fmt.Errorf("Memory [%v] must be a whole number of bytes", resource.MustParse("100m")), | ||
}, | ||
{ | ||
name: "bad manAllowed cpu value", |
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.
typo: s/manAllowed/maxAllowed/
@@ -36,6 +37,7 @@ func TestValidateVPA(t *testing.T) { | |||
badMinReplicas := int32(0) | |||
validMinReplicas := int32(1) | |||
badScalingMode := vpa_types.ContainerScalingMode("bad") | |||
badCPUValue := resource.MustParse("187500u") |
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 use resource.MustParse("187500u") directly, like with other values.
vertical-pod-autoscaler/pkg/admission-controller/resource/vpa/handler_test.go
Show resolved
Hide resolved
if found && max.Cmp(min) < 0 { | ||
return fmt.Errorf("max resource for %v is lower than min", resource) | ||
if found { | ||
if err := validate(resource, max); err != nil { |
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.
We should check if max has correct resolution in a loop:
for resource, min := range policy.MaxAllowed {
if err := validate(resource, max); err != nil {
//...
current implementation doesn't validate max when min is not specified.
@@ -133,9 +136,17 @@ func validateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error { | |||
} | |||
} | |||
for resource, min := range policy.MinAllowed { | |||
if err := validate(resource, min); err != nil { | |||
return err |
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.
It would be nice to mention in the error message which field has improper value.
You can add this information here:
return fmt.Errorf("MinAllowed: %s", err)
or pass the name of the field to validate
so it can include it in the error message it returns.
@@ -157,3 +168,27 @@ func validateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error { | |||
|
|||
return nil | |||
} | |||
|
|||
func validate(name corev1.ResourceName, val apires.Quantity) error { |
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 make the name more specific. For example validateResourceResolution
dfc6601
to
9a80be0
Compare
@jbartosik ptal, There is no way to call string() directly on |
Thanks, just a couple small comments. Please squash commits.
I think you can do this the same way you're handling other resource amounts. |
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.
Looks good, only a few small comments left:
- No need to change if
- Consistent approach to amounts in unit tests
- Please squash commits
vertical-pod-autoscaler/pkg/admission-controller/resource/vpa/handler.go
Outdated
Show resolved
Hide resolved
9a80be0
to
c85142b
Compare
c85142b
to
82f6707
Compare
@jbartosik make some changes according to your comments, ptal |
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.
Thank you
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jbartosik, mowangdk The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Which component this PR applies to?
vertical-pod-autoscaler
What type of PR is this?
/kind bug
What this PR does / why we need it:
Add Validation for VPA
Which issue(s) this PR fixes:
Fixes #4790
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: