mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Merge pull request #21865 from piosz/cluster-autoscaling-cleanup
Cluster autoscaling cleanup
This commit is contained in:
@@ -648,43 +648,6 @@ func validateIngressBackend(backend *extensions.IngressBackend, fldPath *field.P
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func validateClusterAutoscalerSpec(spec extensions.ClusterAutoscalerSpec, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
if spec.MinNodes < 0 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("minNodes"), spec.MinNodes, "must be greater than or equal to 0"))
|
||||
}
|
||||
if spec.MaxNodes < spec.MinNodes {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("maxNodes"), spec.MaxNodes, "must be greater than or equal to `minNodes`"))
|
||||
}
|
||||
if len(spec.TargetUtilization) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("targetUtilization"), ""))
|
||||
}
|
||||
for _, target := range spec.TargetUtilization {
|
||||
if len(target.Resource) == 0 {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("targetUtilization", "resource"), ""))
|
||||
}
|
||||
if target.Value <= 0 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("targetUtilization", "value"), target.Value, "must be greater than 0"))
|
||||
}
|
||||
if target.Value > 1 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("targetUtilization", "value"), target.Value, "must be less than or equal to 1"))
|
||||
}
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidateClusterAutoscaler(autoscaler *extensions.ClusterAutoscaler) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
if autoscaler.Name != "ClusterAutoscaler" {
|
||||
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "name"), autoscaler.Name, "must be 'ClusterAutoscaler'"))
|
||||
}
|
||||
if autoscaler.Namespace != api.NamespaceDefault {
|
||||
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "namespace"), autoscaler.Namespace, "must be 'default'"))
|
||||
}
|
||||
allErrs = append(allErrs, validateClusterAutoscalerSpec(autoscaler.Spec, field.NewPath("spec"))...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidateScale(scale *extensions.Scale) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&scale.ObjectMeta, true, apivalidation.NameIsDNSSubdomain, field.NewPath("metadata"))...)
|
||||
|
||||
@@ -1358,120 +1358,6 @@ func TestValidateIngressStatusUpdate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateClusterAutoscaler(t *testing.T) {
|
||||
successCases := []extensions.ClusterAutoscaler{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "ClusterAutoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.ClusterAutoscalerSpec{
|
||||
MinNodes: 1,
|
||||
MaxNodes: 5,
|
||||
TargetUtilization: []extensions.NodeUtilization{
|
||||
{
|
||||
Resource: extensions.CpuRequest,
|
||||
Value: 0.7,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, successCase := range successCases {
|
||||
if errs := ValidateClusterAutoscaler(&successCase); len(errs) != 0 {
|
||||
t.Errorf("expected success: %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
errorCases := map[string]extensions.ClusterAutoscaler{
|
||||
"must be 'ClusterAutoscaler'": {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "TestClusterAutoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.ClusterAutoscalerSpec{
|
||||
MinNodes: 1,
|
||||
MaxNodes: 5,
|
||||
TargetUtilization: []extensions.NodeUtilization{
|
||||
{
|
||||
Resource: extensions.CpuRequest,
|
||||
Value: 0.7,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"must be 'default'": {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "ClusterAutoscaler",
|
||||
Namespace: "test",
|
||||
},
|
||||
Spec: extensions.ClusterAutoscalerSpec{
|
||||
MinNodes: 1,
|
||||
MaxNodes: 5,
|
||||
TargetUtilization: []extensions.NodeUtilization{
|
||||
{
|
||||
Resource: extensions.CpuRequest,
|
||||
Value: 0.7,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
`must be greater than or equal to 0`: {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "ClusterAutoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.ClusterAutoscalerSpec{
|
||||
MinNodes: -1,
|
||||
MaxNodes: 5,
|
||||
TargetUtilization: []extensions.NodeUtilization{
|
||||
{
|
||||
Resource: extensions.CpuRequest,
|
||||
Value: 0.7,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"must be greater than or equal to `minNodes`": {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "ClusterAutoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.ClusterAutoscalerSpec{
|
||||
MinNodes: 10,
|
||||
MaxNodes: 5,
|
||||
TargetUtilization: []extensions.NodeUtilization{
|
||||
{
|
||||
Resource: extensions.CpuRequest,
|
||||
Value: 0.7,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"Required value": {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "ClusterAutoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.ClusterAutoscalerSpec{
|
||||
MinNodes: 1,
|
||||
MaxNodes: 5,
|
||||
TargetUtilization: []extensions.NodeUtilization{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for k, v := range errorCases {
|
||||
errs := ValidateClusterAutoscaler(&v)
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("[%s] expected failure", k)
|
||||
} else if !strings.Contains(errs[0].Error(), k) {
|
||||
t.Errorf("unexpected error: %v, expected: %q", errs[0], k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateScale(t *testing.T) {
|
||||
successCases := []extensions.Scale{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user