-
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
Migrate Admission Controller Validation to CEL #7690
base: master
Are you sure you want to change the base?
Changes from 2 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 |
---|---|---|
|
@@ -112,25 +112,8 @@ func parseVPA(raw []byte) (*vpa_types.VerticalPodAutoscaler, error) { | |
|
||
// ValidateVPA checks the correctness of VPA Spec and returns an error if there is a problem. | ||
func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error { | ||
if vpa.Spec.UpdatePolicy != nil { | ||
mode := vpa.Spec.UpdatePolicy.UpdateMode | ||
if mode == nil { | ||
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 don't see any checks added regarding 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. In the CRD itself I saw this: So added in here: ea90c23 |
||
return fmt.Errorf("UpdateMode is required if UpdatePolicy is used") | ||
} | ||
if _, found := possibleUpdateModes[*mode]; !found { | ||
return fmt.Errorf("unexpected UpdateMode value %s", *mode) | ||
} | ||
|
||
if minReplicas := vpa.Spec.UpdatePolicy.MinReplicas; minReplicas != nil && *minReplicas <= 0 { | ||
return fmt.Errorf("MinReplicas has to be positive, got %v", *minReplicas) | ||
} | ||
} | ||
|
||
if vpa.Spec.ResourcePolicy != nil { | ||
for _, policy := range vpa.Spec.ResourcePolicy.ContainerPolicies { | ||
if policy.ContainerName == "" { | ||
return fmt.Errorf("ContainerPolicies.ContainerName is required") | ||
} | ||
mode := policy.Mode | ||
if mode != nil { | ||
if _, found := possibleScalingModes[*mode]; !found { | ||
|
@@ -152,23 +135,8 @@ func ValidateVPA(vpa *vpa_types.VerticalPodAutoscaler, isCreate bool) error { | |
return fmt.Errorf("MaxAllowed: %v", err) | ||
} | ||
} | ||
ControlledValues := policy.ControlledValues | ||
if mode != nil && ControlledValues != nil { | ||
if *mode == vpa_types.ContainerScalingModeOff && *ControlledValues == vpa_types.ContainerControlledValuesRequestsAndLimits { | ||
return fmt.Errorf("ControlledValues shouldn't be specified if container scaling mode is off.") | ||
} | ||
} | ||
} | ||
} | ||
|
||
if isCreate && vpa.Spec.TargetRef == nil { | ||
return fmt.Errorf("TargetRef is required. If you're using v1beta1 version of the API, please migrate to v1") | ||
} | ||
|
||
if len(vpa.Spec.Recommenders) > 1 { | ||
return fmt.Errorf("The current version of VPA object shouldn't specify more than one recommenders.") | ||
} | ||
|
||
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.
I don't think you can introduce new CRD validations without increasing the apiVersion.
Additionally,
containerName: '*'
is explicitly supported as a catch-all solution, seeautoscaler/vertical-pod-autoscaler/pkg/utils/vpa/api.go
Lines 216 to 218 in adda3d4
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.
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.
Added in: 9ea4821