Skip to content

Commit

Permalink
remove unnecessary check for chain policy (already check the negation…
Browse files Browse the repository at this point in the history
… of this statement above)
  • Loading branch information
indexjoseph committed Jul 31, 2024
1 parent e56c992 commit 4ee6a56
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions pkg/apis/autoscaling/v1/fleetautoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,7 @@ func (c *ChainPolicy) ValidateChainPolicy(fldPath *field.Path) field.ErrorList {
// Ensure that chain entry has a policy
hasValidPolicy := entry.Buffer == nil && entry.Webhook == nil && entry.Counter == nil && entry.List == nil && entry.Schedule == nil
if entry.Type == "" || hasValidPolicy {
allErrs = append(allErrs, field.Required(fldPath.Index(i), "policy is missing"))
}
// Ensure the chain entry's policy is not a chain policy (to avoid nested chain policies)
if entry.Chain != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Index(i), entry.FleetAutoscalerPolicy.Type, "chain policy cannot be used in chain policy"))
allErrs = append(allErrs, field.Required(fldPath.Index(i), "valid policy is missing"))
}
// Validate the chain entry's policy
allErrs = append(allErrs, entry.FleetAutoscalerPolicy.ValidatePolicy(fldPath.Index(i).Child("policy"))...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/autoscaling/v1/fleetautoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func TestFleetAutoscalerChainValidateUpdate(t *testing.T) {
}
}),
featureFlags: string(runtime.FeatureScheduledAutoscaler) + "=true",
wantLength: 2,
wantLength: 1,
wantField: "spec.policy.chain[1]",
},
"invalid nested policy format": {
Expand Down

0 comments on commit 4ee6a56

Please sign in to comment.