Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroducing empty check for metric template references. #1224

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/controller/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (c *Controller) alert(canary *flaggerv1.Canary, message string, metadata bo

// determine alert provider namespace
providerNamespace := canary.GetNamespace()
if alert.ProviderRef.Namespace != canary.Namespace {
if alert.ProviderRef.Namespace != canary.Namespace && alert.ProviderRef.Namespace != "" {
providerNamespace = alert.ProviderRef.Namespace
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/scheduler_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *Controller) checkMetricProviderAvailability(canary *flaggerv1.Canary) e

if metric.TemplateRef != nil {
namespace := canary.Namespace
if metric.TemplateRef.Namespace != canary.Namespace {
if metric.TemplateRef.Namespace != canary.Namespace && metric.TemplateRef.Namespace != "" {
namespace = metric.TemplateRef.Namespace
}

Expand Down Expand Up @@ -238,7 +238,7 @@ func (c *Controller) runMetricChecks(canary *flaggerv1.Canary) bool {
for _, metric := range canary.GetAnalysis().Metrics {
if metric.TemplateRef != nil {
namespace := canary.Namespace
if metric.TemplateRef.Namespace != canary.Namespace {
if metric.TemplateRef.Namespace != canary.Namespace && metric.TemplateRef.Namespace != "" {
namespace = metric.TemplateRef.Namespace
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/controller/scheduler_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
"github.com/fluxcd/flagger/pkg/metrics/observers"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestController_checkMetricProviderAvailability(t *testing.T) {
Expand Down Expand Up @@ -66,4 +67,18 @@ func TestController_checkMetricProviderAvailability(t *testing.T) {
}
require.NoError(t, ctrl.checkMetricProviderAvailability(canary))
})

t.Run("intraNamespaceTemplateRef", func(t *testing.T) {
ctrl := newDeploymentFixture(nil).ctrl
analysis := &flaggerv1.CanaryAnalysis{Metrics: []flaggerv1.CanaryMetric{{
Name: "", TemplateRef: &flaggerv1.CrossNamespaceObjectReference{
Name: "envoy",
},
}}}
canary := &flaggerv1.Canary{
ObjectMeta: metav1.ObjectMeta{Namespace: "default"},
Spec: flaggerv1.CanarySpec{Analysis: analysis},
}
require.NoError(t, ctrl.checkMetricProviderAvailability(canary))
})
}