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

Forbid creating VPA objects without targetRef #1785

Merged
merged 1 commit into from
Mar 12, 2019

Conversation

kgolab
Copy link
Collaborator

@kgolab kgolab commented Mar 12, 2019

Follow-up to #1783 .

It's a bit of a poor man's solution since we don't have the version nor v1beta1 fields at hand so I've used (lack of) TargetRef for validation.
Moreover, the validation can be by-passed by updating the object but I guess at that point the user has been already warned.

An attempt to create v1beta1 object (or simply v1beta2 w/o TargetRef) ends up with:

Error from server (InternalError): error when creating "b1.yaml": Internal error occurred: admission webhook "vpa.k8s.io" denied the request: TargetRef is required

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 12, 2019
@kgolab
Copy link
Collaborator Author

kgolab commented Mar 12, 2019

/assign bskiba@

@@ -178,16 +178,22 @@ func validateVPA(vpa *vpa_types.VerticalPodAutoscaler) error {
}
}

if isCreate {
Copy link
Member

Choose a reason for hiding this comment

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

You can fold the two ifs into one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I started with a more complicated code and haven't cleaned this. Fixed.

@@ -147,7 +147,7 @@ var (
}
)

func validateVPA(vpa *vpa_types.VerticalPodAutoscaler) error {
func validateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I am inclined to pass ar.Request.Operation instead of boolean but you can ignore my inclination :)

Copy link
Collaborator Author

@kgolab kgolab Mar 12, 2019

Choose a reason for hiding this comment

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

Since you don't mind I'll choose "ignore" this time.

@bskiba
Copy link
Member

bskiba commented Mar 12, 2019

Nits only

@bskiba
Copy link
Member

bskiba commented Mar 12, 2019

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 12, 2019
@@ -178,16 +178,22 @@ func validateVPA(vpa *vpa_types.VerticalPodAutoscaler) error {
}
}

if isCreate {
if vpa.Spec.TargetRef == nil {
return fmt.Errorf("TargetRef is required")
Copy link
Member

Choose a reason for hiding this comment

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

Actually one more thing, can you make this more descriptive? Sth like, you are trying to use an unsupported version of the api, please migrate to v1beta2 and use targetRef to specify pods to autoscale

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reworded.
Since we're not sure of the API version used here, it makes the message a bit long but maybe it's for the best.

@kgolab kgolab force-pushed the kg-vpa-invalidate-v1beta1 branch from ac8288e to 6ec53d4 Compare March 12, 2019 16:58
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 12, 2019
@kgolab
Copy link
Collaborator Author

kgolab commented Mar 12, 2019

@bskiba , please take another look.

@bskiba
Copy link
Member

bskiba commented Mar 12, 2019

Thanks!
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 12, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bskiba

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 12, 2019
@k8s-ci-robot k8s-ci-robot merged commit 0e8e303 into kubernetes:master Mar 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants