-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[VPA] Enable multiple revive rules - 4 #9155
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ import ( | |
| "github.com/stretchr/testify/assert" | ||
| admissionv1 "k8s.io/api/admission/v1" | ||
| apiv1 "k8s.io/api/core/v1" | ||
| v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
Contributor
Author
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. Based on the comments here, have enabled the "redundant-import-alias" rule |
||
| "k8s.io/apimachinery/pkg/runtime" | ||
|
|
||
| resource_admission "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource" | ||
|
|
@@ -184,7 +184,7 @@ func TestGetPatches(t *testing.T) { | |
| fvm := &fakeVpaMatcher{vpa: tc.vpa} | ||
| h := NewResourceHandler(fppp, fvm, tc.calculators) | ||
| patches, err := h.GetPatches(context.Background(), &admissionv1.AdmissionRequest{ | ||
| Resource: v1.GroupVersionResource{ | ||
| Resource: metav1.GroupVersionResource{ | ||
| Version: "v1", | ||
| }, | ||
| Namespace: tc.namespace, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,8 @@ import ( | |
| "errors" | ||
| "fmt" | ||
|
|
||
| v1 "k8s.io/api/admission/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
|
Member
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. I'm taking a look at the kubernetes repo, and it seems that this package is often called
Contributor
Author
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. When I looked across the repo, most of the places we have used apiv1, so I have used this to make it consistent.
Member
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.
Contributor
Author
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. WIll be making the changes, Thanks! |
||
| admissionv1 "k8s.io/api/admission/v1" | ||
| apiv1 "k8s.io/api/core/v1" | ||
| apires "k8s.io/apimachinery/pkg/api/resource" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/klog/v2" | ||
|
|
@@ -67,8 +67,8 @@ func (h *resourceHandler) DisallowIncorrectObjects() bool { | |
| } | ||
|
|
||
| // GetPatches builds patches for VPA in given admission request. | ||
| func (h *resourceHandler) GetPatches(_ context.Context, ar *v1.AdmissionRequest) ([]resource.PatchRecord, error) { | ||
| raw, isCreate := ar.Object.Raw, ar.Operation == v1.Create | ||
| func (h *resourceHandler) GetPatches(_ context.Context, ar *admissionv1.AdmissionRequest) ([]resource.PatchRecord, error) { | ||
| raw, isCreate := ar.Object.Raw, ar.Operation == admissionv1.Create | ||
| vpa, err := parseVPA(raw) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -158,18 +158,18 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error { | |
| return fmt.Errorf("unexpected Mode value %s", *mode) | ||
| } | ||
| } | ||
| for resource, min := range policy.MinAllowed { | ||
| if err := validateResourceResolution(resource, min); err != nil { | ||
| for resource, minAllowed := range policy.MinAllowed { | ||
| if err := validateResourceResolution(resource, minAllowed); err != nil { | ||
| return fmt.Errorf("minAllowed: %v", err) | ||
| } | ||
| max, found := policy.MaxAllowed[resource] | ||
| if found && max.Cmp(min) < 0 { | ||
| maxAllowed, found := policy.MaxAllowed[resource] | ||
| if found && maxAllowed.Cmp(minAllowed) < 0 { | ||
| return fmt.Errorf("max resource for %v is lower than min", resource) | ||
| } | ||
| } | ||
|
|
||
| for resource, max := range policy.MaxAllowed { | ||
| if err := validateResourceResolution(resource, max); err != nil { | ||
| for resource, maxAllowed := range policy.MaxAllowed { | ||
| if err := validateResourceResolution(resource, maxAllowed); err != nil { | ||
| return fmt.Errorf("maxAllowed: %v", err) | ||
| } | ||
| } | ||
|
|
@@ -193,11 +193,11 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error { | |
| return nil | ||
| } | ||
|
|
||
| func validateResourceResolution(name corev1.ResourceName, val apires.Quantity) error { | ||
| func validateResourceResolution(name apiv1.ResourceName, val apires.Quantity) error { | ||
| switch name { | ||
| case corev1.ResourceCPU: | ||
| case apiv1.ResourceCPU: | ||
| return validateCPUResolution(val) | ||
| case corev1.ResourceMemory: | ||
| case apiv1.ResourceMemory: | ||
| return validateMemoryResolution(val) | ||
| } | ||
| return 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.
Should this be
admissionv1?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.
oops my bad, I will update it