diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index ef3006e52..3e3247d19 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -49,7 +49,7 @@ func SetupMocks(c *flaggerv1.Canary) Mocks { if c == nil { c = newTestCanary() } - flaggerClient := fakeFlagger.NewSimpleClientset(c) + flaggerClient := fakeFlagger.NewSimpleClientset(c, newTestMetricTemplate()) // init kube clientset and register mock objects kubeClient := fake.NewSimpleClientset( @@ -266,10 +266,13 @@ func newTestCanary() *flaggerv1.Canary { Name: "custom", ThresholdRange: &flaggerv1.CanaryThresholdRange{ Min: toFloatPtr(0), - Max: toFloatPtr(500000), + Max: toFloatPtr(100), }, Interval: "1m", - Query: "fake", + TemplateRef: &flaggerv1.MetricTemplateRef{ + Name: "envoy", + Namespace: "default", + }, }, }, }, @@ -334,6 +337,15 @@ func newTestCanaryAB() *flaggerv1.Canary { Threshold: 500000, Interval: "1m", }, + { + Name: "custom", + ThresholdRange: &flaggerv1.CanaryThresholdRange{ + Min: toFloatPtr(0), + Max: toFloatPtr(500000), + }, + Interval: "1m", + Query: "fake", + }, }, }, }, @@ -657,3 +669,23 @@ func newTestHPA() *hpav2.HorizontalPodAutoscaler { return h } + +func newTestMetricTemplate() *flaggerv1.MetricTemplate { + provider := flaggerv1.MetricTemplateProvider{ + Type: "prometheus", + Address: "fake", + } + + template := &flaggerv1.MetricTemplate{ + TypeMeta: metav1.TypeMeta{APIVersion: flaggerv1.SchemeGroupVersion.String()}, + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "envoy", + }, + Spec: flaggerv1.MetricTemplateSpec{ + Provider: provider, + Query: `sum(envoy_cluster_upstream_rq{envoy_cluster_name=~"{{ namespace }}_{{ target }}"})`, + }, + } + return template +}