-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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 external metric type to HPA API #60096
Changes from 1 commit
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 |
---|---|---|
|
@@ -115,7 +115,7 @@ func validateMetrics(metrics []autoscaling.MetricSpec, fldPath *field.Path) fiel | |
return allErrs | ||
} | ||
|
||
var validMetricSourceTypes = sets.NewString(string(autoscaling.ObjectMetricSourceType), string(autoscaling.PodsMetricSourceType), string(autoscaling.ResourceMetricSourceType)) | ||
var validMetricSourceTypes = sets.NewString(string(autoscaling.ObjectMetricSourceType), string(autoscaling.PodsMetricSourceType), string(autoscaling.ResourceMetricSourceType), string(autoscaling.ExternalMetricSourceType)) | ||
var validMetricSourceTypesList = validMetricSourceTypes.List() | ||
|
||
func validateMetricSpec(spec autoscaling.MetricSpec, fldPath *field.Path) field.ErrorList { | ||
|
@@ -137,6 +137,13 @@ func validateMetricSpec(spec autoscaling.MetricSpec, fldPath *field.Path) field. | |
} | ||
} | ||
|
||
if spec.External != nil { | ||
typesPresent.Insert("external") | ||
if typesPresent.Len() == 1 { | ||
allErrs = append(allErrs, validateExternalSource(spec.External, fldPath.Child("external"))...) | ||
} | ||
} | ||
|
||
if spec.Pods != nil { | ||
typesPresent.Insert("pods") | ||
if typesPresent.Len() == 1 { | ||
|
@@ -183,6 +190,32 @@ func validateObjectSource(src *autoscaling.ObjectMetricSource, fldPath *field.Pa | |
return allErrs | ||
} | ||
|
||
func validateExternalSource(src *autoscaling.ExternalMetricSource, fldPath *field.Path) field.ErrorList { | ||
allErrs := field.ErrorList{} | ||
|
||
if len(src.MetricName) == 0 { | ||
allErrs = append(allErrs, field.Required(fldPath.Child("metricName"), "must specify a metric name")) | ||
} | ||
|
||
if src.TargetValue == nil && src.TargetAverageValue == nil { | ||
allErrs = append(allErrs, field.Required(fldPath.Child("targetValue"), "must set either a target value for metric or a per-pod target")) | ||
} | ||
|
||
if src.TargetValue != nil && src.TargetAverageValue != nil { | ||
allErrs = append(allErrs, field.Forbidden(fldPath.Child("targetValue"), "may not set both a target value for metric and a per-pod target")) | ||
} | ||
|
||
if src.TargetAverageValue != nil && src.TargetAverageValue.Sign() != 1 { | ||
allErrs = append(allErrs, field.Invalid(fldPath.Child("targetAverageValue"), src.TargetAverageValue, "must be positive")) | ||
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. we'll want to re-evaluate this later, because it's not strictly true for custom metrics 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. Sure. I'm not sure what the specific use-case is and how do we want to handle metric value changing signs, but in general I see no reason not to allow it later on. |
||
} | ||
|
||
if src.TargetValue != nil && src.TargetValue.Sign() != 1 { | ||
allErrs = append(allErrs, field.Invalid(fldPath.Child("targetValue"), src.TargetValue, "must be positive")) | ||
} | ||
|
||
return allErrs | ||
} | ||
|
||
func validatePodsSource(src *autoscaling.PodsMetricSource, fldPath *field.Path) field.ErrorList { | ||
allErrs := field.ErrorList{} | ||
|
||
|
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.
since this will be used as a single path segment in URL-building, this should be validated with
path.IsValidPathSegmentName