mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
Fresh dep ensure
This commit is contained in:
13
vendor/k8s.io/kubernetes/pkg/apis/autoscaling/validation/BUILD
generated
vendored
13
vendor/k8s.io/kubernetes/pkg/apis/autoscaling/validation/BUILD
generated
vendored
@ -13,9 +13,10 @@ go_library(
|
||||
deps = [
|
||||
"//pkg/apis/autoscaling:go_default_library",
|
||||
"//pkg/apis/core/validation:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/validation/path:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/validation:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/validation/path:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@ -26,9 +27,9 @@ go_test(
|
||||
deps = [
|
||||
"//pkg/apis/autoscaling:go_default_library",
|
||||
"//pkg/apis/core:go_default_library",
|
||||
"//pkg/util/pointer:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
113
vendor/k8s.io/kubernetes/pkg/apis/autoscaling/validation/validation.go
generated
vendored
113
vendor/k8s.io/kubernetes/pkg/apis/autoscaling/validation/validation.go
generated
vendored
@ -19,6 +19,7 @@ package validation
|
||||
import (
|
||||
"strings"
|
||||
|
||||
apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation"
|
||||
pathvalidation "k8s.io/apimachinery/pkg/api/validation/path"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
@ -28,7 +29,7 @@ import (
|
||||
|
||||
func ValidateScale(scale *autoscaling.Scale) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&scale.ObjectMeta, true, apivalidation.NameIsDNSSubdomain, field.NewPath("metadata"))...)
|
||||
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&scale.ObjectMeta, true, apimachineryvalidation.NameIsDNSSubdomain, field.NewPath("metadata"))...)
|
||||
|
||||
if scale.Spec.Replicas < 0 {
|
||||
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "replicas"), scale.Spec.Replicas, "must be greater than or equal to 0"))
|
||||
@ -177,14 +178,16 @@ func validateMetricSpec(spec autoscaling.MetricSpec, fldPath *field.Path) field.
|
||||
func validateObjectSource(src *autoscaling.ObjectMetricSource, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
|
||||
allErrs = append(allErrs, ValidateCrossVersionObjectReference(src.Target, fldPath.Child("target"))...)
|
||||
|
||||
if len(src.MetricName) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("metricName"), "must specify a metric name"))
|
||||
allErrs = append(allErrs, ValidateCrossVersionObjectReference(src.DescribedObject, fldPath.Child("describedObject"))...)
|
||||
allErrs = append(allErrs, validateMetricIdentifier(src.Metric, fldPath.Child("metric"))...)
|
||||
if &src.Target == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("target"), "must specify a metric target"))
|
||||
} else {
|
||||
allErrs = append(allErrs, validateMetricTarget(src.Target, fldPath.Child("target"))...)
|
||||
}
|
||||
|
||||
if src.TargetValue.Sign() != 1 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("targetValue"), "must specify a positive target value"))
|
||||
if src.Target.Value == nil && src.Target.AverageValue == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("target").Child("averageValue"), "must set either a target value or averageValue"))
|
||||
}
|
||||
|
||||
return allErrs
|
||||
@ -193,28 +196,19 @@ func validateObjectSource(src *autoscaling.ObjectMetricSource, fldPath *field.Pa
|
||||
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"))
|
||||
allErrs = append(allErrs, validateMetricIdentifier(src.Metric, fldPath.Child("metric"))...)
|
||||
if &src.Target == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("target"), "must specify a metric target"))
|
||||
} else {
|
||||
for _, msg := range pathvalidation.IsValidPathSegmentName(src.MetricName) {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("metricName"), src.MetricName, msg))
|
||||
}
|
||||
allErrs = append(allErrs, validateMetricTarget(src.Target, fldPath.Child("target"))...)
|
||||
}
|
||||
|
||||
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.Target.Value == nil && src.Target.AverageValue == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("target").Child("averageValue"), "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"))
|
||||
}
|
||||
|
||||
if src.TargetValue != nil && src.TargetValue.Sign() != 1 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("targetValue"), src.TargetValue, "must be positive"))
|
||||
if src.Target.Value != nil && src.Target.AverageValue != nil {
|
||||
allErrs = append(allErrs, field.Forbidden(fldPath.Child("target").Child("value"), "may not set both a target value for metric and a per-pod target"))
|
||||
}
|
||||
|
||||
return allErrs
|
||||
@ -223,12 +217,15 @@ func validateExternalSource(src *autoscaling.ExternalMetricSource, fldPath *fiel
|
||||
func validatePodsSource(src *autoscaling.PodsMetricSource, 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"))
|
||||
allErrs = append(allErrs, validateMetricIdentifier(src.Metric, fldPath.Child("metric"))...)
|
||||
if &src.Target == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("target"), "must specify a metric target"))
|
||||
} else {
|
||||
allErrs = append(allErrs, validateMetricTarget(src.Target, fldPath.Child("target"))...)
|
||||
}
|
||||
|
||||
if src.TargetAverageValue.Sign() != 1 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("targetAverageValue"), "must specify a positive target value"))
|
||||
if src.Target.AverageValue == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("target").Child("averageValue"), "must specify a positive target averageValue"))
|
||||
}
|
||||
|
||||
return allErrs
|
||||
@ -240,22 +237,60 @@ func validateResourceSource(src *autoscaling.ResourceMetricSource, fldPath *fiel
|
||||
if len(src.Name) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("name"), "must specify a resource name"))
|
||||
}
|
||||
|
||||
if src.TargetAverageUtilization == nil && src.TargetAverageValue == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("targetAverageUtilization"), "must set either a target raw value or a target utilization"))
|
||||
if &src.Target == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("target"), "must specify a metric target"))
|
||||
} else {
|
||||
allErrs = append(allErrs, validateMetricTarget(src.Target, fldPath.Child("target"))...)
|
||||
}
|
||||
|
||||
if src.TargetAverageUtilization != nil && *src.TargetAverageUtilization < 1 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("targetAverageUtilization"), src.TargetAverageUtilization, "must be greater than 0"))
|
||||
if src.Target.AverageUtilization == nil && src.Target.AverageValue == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("target").Child("averageUtilization"), "must set either a target raw value or a target utilization"))
|
||||
}
|
||||
|
||||
if src.TargetAverageUtilization != nil && src.TargetAverageValue != nil {
|
||||
allErrs = append(allErrs, field.Forbidden(fldPath.Child("targetAverageValue"), "may not set both a target raw value and a target utilization"))
|
||||
}
|
||||
|
||||
if src.TargetAverageValue != nil && src.TargetAverageValue.Sign() != 1 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("targetAverageValue"), src.TargetAverageValue, "must be positive"))
|
||||
if src.Target.AverageUtilization != nil && src.Target.AverageValue != nil {
|
||||
allErrs = append(allErrs, field.Forbidden(fldPath.Child("target").Child("averageValue"), "may not set both a target raw value and a target utilization"))
|
||||
}
|
||||
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func validateMetricTarget(mt autoscaling.MetricTarget, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
|
||||
if len(mt.Type) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("type"), "must specify a metric target type"))
|
||||
}
|
||||
|
||||
if mt.Type != autoscaling.UtilizationMetricType &&
|
||||
mt.Type != autoscaling.ValueMetricType &&
|
||||
mt.Type != autoscaling.AverageValueMetricType {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("type"), mt.Type, "must be either Utilization, Value, or AverageValue"))
|
||||
}
|
||||
|
||||
if mt.Value != nil && mt.Value.Sign() != 1 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("value"), mt.Value, "must be positive"))
|
||||
}
|
||||
|
||||
if mt.AverageValue != nil && mt.AverageValue.Sign() != 1 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("averageValue"), mt.AverageValue, "must be positive"))
|
||||
}
|
||||
|
||||
if mt.AverageUtilization != nil && *mt.AverageUtilization < 1 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("averageUtilization"), mt.AverageUtilization, "must be greater than 0"))
|
||||
}
|
||||
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func validateMetricIdentifier(id autoscaling.MetricIdentifier, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
|
||||
if len(id.Name) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("name"), "must specify a metric name"))
|
||||
} else {
|
||||
for _, msg := range pathvalidation.IsValidPathSegmentName(id.Name) {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), id.Name, msg))
|
||||
}
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
395
vendor/k8s.io/kubernetes/pkg/apis/autoscaling/validation/validation_test.go
generated
vendored
395
vendor/k8s.io/kubernetes/pkg/apis/autoscaling/validation/validation_test.go
generated
vendored
@ -24,7 +24,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
utilpointer "k8s.io/kubernetes/pkg/util/pointer"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
func TestValidateScale(t *testing.T) {
|
||||
@ -92,6 +92,10 @@ func TestValidateScale(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
metricLabelSelector, err := metav1.ParseToLabelSelector("label=value")
|
||||
if err != nil {
|
||||
t.Errorf("unable to parse label selector: %v", err)
|
||||
}
|
||||
successCases := []autoscaling.HorizontalPodAutoscaler{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
@ -110,7 +114,10 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageUtilization: utilpointer.Int32Ptr(70),
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: utilpointer.Int32Ptr(70),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -146,8 +153,11 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
Name: api.ResourceCPU,
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -169,8 +179,13 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.PodsMetricSourceType,
|
||||
Pods: &autoscaling.PodsMetricSource{
|
||||
MetricName: "somemetric",
|
||||
TargetAverageValue: *resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -192,12 +207,17 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ObjectMetricSourceType,
|
||||
Object: &autoscaling.ObjectMetricSource{
|
||||
Target: autoscaling.CrossVersionObjectReference{
|
||||
DescribedObject: autoscaling.CrossVersionObjectReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
},
|
||||
MetricName: "somemetric",
|
||||
TargetValue: *resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -219,13 +239,14 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricName: "somemetric",
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
TargetValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -247,13 +268,14 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricName: "somemetric",
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
TargetAverageValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -282,7 +304,10 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageUtilization: utilpointer.Int32Ptr(70),
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: utilpointer.Int32Ptr(70),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -302,7 +327,10 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageUtilization: utilpointer.Int32Ptr(70),
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: utilpointer.Int32Ptr(70),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -322,7 +350,10 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageUtilization: utilpointer.Int32Ptr(70),
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: utilpointer.Int32Ptr(70),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -342,7 +373,10 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageUtilization: utilpointer.Int32Ptr(70),
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: utilpointer.Int32Ptr(70),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -393,8 +427,11 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageUtilization: utilpointer.Int32Ptr(70),
|
||||
TargetAverageValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: utilpointer.Int32Ptr(70),
|
||||
AverageValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -413,7 +450,10 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
TargetAverageUtilization: utilpointer.Int32Ptr(70),
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: utilpointer.Int32Ptr(70),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -433,7 +473,10 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageUtilization: utilpointer.Int32Ptr(-10),
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: utilpointer.Int32Ptr(-10),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -453,6 +496,9 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -471,7 +517,11 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.PodsMetricSourceType,
|
||||
Pods: &autoscaling.PodsMetricSource{
|
||||
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -490,36 +540,18 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.PodsMetricSourceType,
|
||||
Pods: &autoscaling.PodsMetricSource{
|
||||
MetricName: "somemetric",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
msg: "must specify a positive target value",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: autoscaling.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myautoscaler", Namespace: metav1.NamespaceDefault},
|
||||
Spec: autoscaling.HorizontalPodAutoscalerSpec{
|
||||
ScaleTargetRef: autoscaling.CrossVersionObjectReference{Name: "myrc", Kind: "ReplicationController"},
|
||||
MinReplicas: utilpointer.Int32Ptr(1),
|
||||
MaxReplicas: 5,
|
||||
Metrics: []autoscaling.MetricSpec{
|
||||
{
|
||||
Type: autoscaling.ObjectMetricSourceType,
|
||||
Object: &autoscaling.ObjectMetricSource{
|
||||
Target: autoscaling.CrossVersionObjectReference{
|
||||
Name: "myrc",
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
},
|
||||
MetricName: "somemetric",
|
||||
TargetValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
msg: "target.kind: Required",
|
||||
msg: "must specify a positive target averageValue",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: autoscaling.HorizontalPodAutoscaler{
|
||||
@ -532,11 +564,70 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ObjectMetricSourceType,
|
||||
Object: &autoscaling.ObjectMetricSource{
|
||||
Target: autoscaling.CrossVersionObjectReference{
|
||||
DescribedObject: autoscaling.CrossVersionObjectReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
},
|
||||
TargetValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
msg: "must set either a target value or averageValue",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: autoscaling.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myautoscaler", Namespace: metav1.NamespaceDefault},
|
||||
Spec: autoscaling.HorizontalPodAutoscalerSpec{
|
||||
ScaleTargetRef: autoscaling.CrossVersionObjectReference{Name: "myrc", Kind: "ReplicationController"},
|
||||
MinReplicas: utilpointer.Int32Ptr(1),
|
||||
MaxReplicas: 5,
|
||||
Metrics: []autoscaling.MetricSpec{
|
||||
{
|
||||
Type: autoscaling.ObjectMetricSourceType,
|
||||
Object: &autoscaling.ObjectMetricSource{
|
||||
DescribedObject: autoscaling.CrossVersionObjectReference{
|
||||
Name: "myrc",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
msg: "object.describedObject.kind: Required",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: autoscaling.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myautoscaler", Namespace: metav1.NamespaceDefault},
|
||||
Spec: autoscaling.HorizontalPodAutoscalerSpec{
|
||||
ScaleTargetRef: autoscaling.CrossVersionObjectReference{Name: "myrc", Kind: "ReplicationController"},
|
||||
MinReplicas: utilpointer.Int32Ptr(1),
|
||||
MaxReplicas: 5,
|
||||
Metrics: []autoscaling.MetricSpec{
|
||||
{
|
||||
Type: autoscaling.ObjectMetricSourceType,
|
||||
Object: &autoscaling.ObjectMetricSource{
|
||||
DescribedObject: autoscaling.CrossVersionObjectReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -555,12 +646,13 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
TargetValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -579,13 +671,14 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricName: "foo/../",
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "foo/../",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
TargetValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -605,11 +698,12 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricName: "somemetric",
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -629,13 +723,14 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricName: "somemetric",
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(-300, resource.DecimalSI),
|
||||
},
|
||||
TargetValue: resource.NewMilliQuantity(-300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -654,13 +749,14 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricName: "somemetric",
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(-300, resource.DecimalSI),
|
||||
},
|
||||
TargetAverageValue: resource.NewMilliQuantity(-300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -679,14 +775,15 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricName: "somemetric",
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
AverageValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
TargetValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
TargetAverageValue: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -694,6 +791,79 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
},
|
||||
msg: "may not set both a target value for metric and a per-pod target",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: autoscaling.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myautoscaler", Namespace: metav1.NamespaceDefault},
|
||||
Spec: autoscaling.HorizontalPodAutoscalerSpec{
|
||||
ScaleTargetRef: autoscaling.CrossVersionObjectReference{Name: "myrc", Kind: "ReplicationController"},
|
||||
MinReplicas: utilpointer.Int32Ptr(1),
|
||||
MaxReplicas: 5,
|
||||
Metrics: []autoscaling.MetricSpec{
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: "boogity",
|
||||
Value: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
msg: "must be either Utilization, Value, or AverageValue",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: autoscaling.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myautoscaler", Namespace: metav1.NamespaceDefault},
|
||||
Spec: autoscaling.HorizontalPodAutoscalerSpec{
|
||||
ScaleTargetRef: autoscaling.CrossVersionObjectReference{Name: "myrc", Kind: "ReplicationController"},
|
||||
MinReplicas: utilpointer.Int32Ptr(1),
|
||||
MaxReplicas: 5,
|
||||
Metrics: []autoscaling.MetricSpec{
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Value: resource.NewMilliQuantity(300, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
msg: "must specify a metric target type",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: autoscaling.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myautoscaler", Namespace: metav1.NamespaceDefault},
|
||||
Spec: autoscaling.HorizontalPodAutoscalerSpec{
|
||||
ScaleTargetRef: autoscaling.CrossVersionObjectReference{Name: "myrc", Kind: "ReplicationController"},
|
||||
MinReplicas: utilpointer.Int32Ptr(1),
|
||||
MaxReplicas: 5,
|
||||
Metrics: []autoscaling.MetricSpec{
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
msg: "must specify a metric target",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: autoscaling.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myautoscaler", Namespace: metav1.NamespaceDefault},
|
||||
@ -735,12 +905,20 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Name: api.ResourceCPU,
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
Pods: &autoscaling.PodsMetricSource{
|
||||
MetricName: "somemetric",
|
||||
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -762,24 +940,37 @@ func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
sourceTypes := map[autoscaling.MetricSourceType]autoscaling.MetricSpec{
|
||||
autoscaling.ResourceMetricSourceType: {
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Name: api.ResourceCPU,
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
autoscaling.PodsMetricSourceType: {
|
||||
Pods: &autoscaling.PodsMetricSource{
|
||||
MetricName: "somemetric",
|
||||
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
autoscaling.ObjectMetricSourceType: {
|
||||
Object: &autoscaling.ObjectMetricSource{
|
||||
Target: autoscaling.CrossVersionObjectReference{
|
||||
DescribedObject: autoscaling.CrossVersionObjectReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
},
|
||||
MetricName: "somemetric",
|
||||
TargetValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "somemetric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user