Move internal types of hpa from pkg/apis/extensions to pkg/apis/autoscaling
This commit is contained in:
@@ -24,301 +24,9 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/controller/podautoscaler"
|
||||
"k8s.io/kubernetes/pkg/util/intstr"
|
||||
)
|
||||
|
||||
func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
successCases := []extensions.HorizontalPodAutoscaler{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: 70},
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
Annotations: map[string]string{
|
||||
podautoscaler.HpaCustomMetricsTargetAnnotationName: "{\"items\":[{\"name\":\"qps\",\"value\":\"20\"}]}",
|
||||
},
|
||||
},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, successCase := range successCases {
|
||||
if errs := ValidateHorizontalPodAutoscaler(&successCase); len(errs) != 0 {
|
||||
t.Errorf("expected success: %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
errorCases := []struct {
|
||||
horizontalPodAutoscaler extensions.HorizontalPodAutoscaler
|
||||
msg string
|
||||
}{
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{Name: "myautoscaler", Namespace: api.NamespaceDefault},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{Name: "myrc", Subresource: "scale"},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: 70},
|
||||
},
|
||||
},
|
||||
msg: "scaleRef.kind: Required",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{Name: "myautoscaler", Namespace: api.NamespaceDefault},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{Kind: "..", Name: "myrc", Subresource: "scale"},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: 70},
|
||||
},
|
||||
},
|
||||
msg: "scaleRef.kind: Invalid",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{Name: "myautoscaler", Namespace: api.NamespaceDefault},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{Kind: "ReplicationController", Subresource: "scale"},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: 70},
|
||||
},
|
||||
},
|
||||
msg: "scaleRef.name: Required",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{Name: "myautoscaler", Namespace: api.NamespaceDefault},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{Kind: "ReplicationController", Name: "..", Subresource: "scale"},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: 70},
|
||||
},
|
||||
},
|
||||
msg: "scaleRef.name: Invalid",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{Name: "myautoscaler", Namespace: api.NamespaceDefault},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{Kind: "ReplicationController", Name: "myrc", Subresource: ""},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: 70},
|
||||
},
|
||||
},
|
||||
msg: "scaleRef.subresource: Required",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{Name: "myautoscaler", Namespace: api.NamespaceDefault},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{Kind: "ReplicationController", Name: "myrc", Subresource: ".."},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: 70},
|
||||
},
|
||||
},
|
||||
msg: "scaleRef.subresource: Invalid",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{Name: "myautoscaler", Namespace: api.NamespaceDefault},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{Kind: "ReplicationController", Name: "myrc", Subresource: "randomsubresource"},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: 70},
|
||||
},
|
||||
},
|
||||
msg: "scaleRef.subresource: Unsupported",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinReplicas: newInt32(-1),
|
||||
MaxReplicas: 5,
|
||||
},
|
||||
},
|
||||
msg: "must be greater than 0",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinReplicas: newInt32(7),
|
||||
MaxReplicas: 5,
|
||||
},
|
||||
},
|
||||
msg: "must be greater than or equal to `minReplicas`",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
CPUUtilization: &extensions.CPUTargetUtilization{TargetPercentage: -70},
|
||||
},
|
||||
},
|
||||
msg: "must be greater than 0",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
Annotations: map[string]string{
|
||||
podautoscaler.HpaCustomMetricsTargetAnnotationName: "broken",
|
||||
},
|
||||
},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
},
|
||||
},
|
||||
msg: "failed to parse custom metrics target annotation",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
Annotations: map[string]string{
|
||||
podautoscaler.HpaCustomMetricsTargetAnnotationName: "{}",
|
||||
},
|
||||
},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
},
|
||||
},
|
||||
msg: "custom metrics target must not be empty",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
Annotations: map[string]string{
|
||||
podautoscaler.HpaCustomMetricsTargetAnnotationName: "{\"items\":[{\"value\":\"20\"}]}",
|
||||
},
|
||||
},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
},
|
||||
},
|
||||
msg: "missing custom metric target name",
|
||||
},
|
||||
{
|
||||
horizontalPodAutoscaler: extensions.HorizontalPodAutoscaler{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
Annotations: map[string]string{
|
||||
podautoscaler.HpaCustomMetricsTargetAnnotationName: "{\"items\":[{\"name\":\"qps\",\"value\":\"0\"}]}",
|
||||
},
|
||||
},
|
||||
Spec: extensions.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: extensions.SubresourceReference{
|
||||
Kind: "ReplicationController",
|
||||
Name: "myrc",
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinReplicas: newInt32(1),
|
||||
MaxReplicas: 5,
|
||||
},
|
||||
},
|
||||
msg: "custom metric target value must be greater than 0",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range errorCases {
|
||||
errs := ValidateHorizontalPodAutoscaler(&c.horizontalPodAutoscaler)
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("expected failure for %q", c.msg)
|
||||
} else if !strings.Contains(errs[0].Error(), c.msg) {
|
||||
t.Errorf("unexpected error: %q, expected: %q", errs[0], c.msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateDaemonSetStatusUpdate(t *testing.T) {
|
||||
type dsUpdateTest struct {
|
||||
old extensions.DaemonSet
|
||||
@@ -1709,12 +1417,6 @@ func TestValidateReplicaSet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newInt32(val int32) *int32 {
|
||||
p := new(int32)
|
||||
*p = val
|
||||
return p
|
||||
}
|
||||
|
||||
func TestValidatePodSecurityPolicy(t *testing.T) {
|
||||
validSCC := func() *extensions.PodSecurityPolicy {
|
||||
return &extensions.PodSecurityPolicy{
|
||||
|
Reference in New Issue
Block a user