Skip to content

Commit

Permalink
Cover cases for HPA generation with segments.
Browse files Browse the repository at this point in the history
Signed-off-by: Rodrigo Reis <rodrigo.gargravarr@gmail.com>
  • Loading branch information
gargravarr committed Feb 16, 2024
1 parent 2fa0119 commit b12351b
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions pkg/core/stack_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
autoscaling "k8s.io/api/autoscaling/v2"
v1 "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
Expand Down Expand Up @@ -1404,6 +1405,85 @@ func TestGenerateHPA(t *testing.T) {
}
}

func TestGenerateHPAToSegment(t *testing.T) {
for _, tc := range []struct {
name string
minReplicas int32
maxReplicas int32
metricType zv1.AutoscalerMetricType
metricValue int64
expectedRef string
}{
{
name: "HPA metric points to ingress segment",
minReplicas: 1,
maxReplicas: 2,
metricType: zv1.IngressAutoscalerMetric,
metricValue: 20,
expectedRef: "foo-v1-traffic-segment",
},
{
name: "HPA metric points to routeGroup segment",
minReplicas: 1,
maxReplicas: 2,
metricType: zv1.RouteGroupAutoscalerMetric,
metricValue: 20,
expectedRef: "foo-v1-traffic-segment",
},
} {
t.Run(tc.name, func(t *testing.T) {
metricValue := resource.NewQuantity(
tc.metricValue,
resource.DecimalSI,
)

autoScalerContainer := &StackContainer{
Stack: &zv1.Stack{
ObjectMeta: testStackMeta,
Spec: zv1.StackSpecInternal{
StackSpec: zv1.StackSpec{
PodTemplate: zv1.PodTemplateSpec{
EmbeddedObjectMeta: zv1.EmbeddedObjectMeta{
Labels: map[string]string{
"pod-label": "pod-foo",
},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "foo",
Image: "ghcr.io/zalando/skipper:latest",
},
},
},
},
Autoscaler: &zv1.Autoscaler{
MinReplicas: &tc.minReplicas,
MaxReplicas: tc.maxReplicas,
Metrics: []zv1.AutoscalerMetrics{
{
Type: tc.metricType,
Average: metricValue,
},
},
},
},
},
},
}

hpa, err := autoScalerContainer.GenerateHPAToSegment()
require.NoError(t, err)
require.NotEmpty(t, hpa.Spec.Metrics)
require.Equal(
t,
tc.expectedRef,
hpa.Spec.Metrics[0].Object.DescribedObject.Name,
)
})
}
}

func TestGenerateStackStatus(t *testing.T) {
hourAgo := time.Now().Add(-time.Hour)

Expand Down

0 comments on commit b12351b

Please sign in to comment.