Skip to content

Commit

Permalink
Add metric templates to controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Feb 8, 2020
1 parent 8f99e58 commit 80c488a
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
},
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
},
Expand Down Expand Up @@ -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
}

0 comments on commit 80c488a

Please sign in to comment.