mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Reintroducing the old empty check for metric template references. Reverting removal in commit 7df1beef85 to support the optianl namespace. Adding test for future valdiation.
Signed-off-by: Nick Freyaldenhoven <freyaldenhovennc@gmail.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
@@ -66,4 +67,19 @@ 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))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user