fix: default namespace for cross-namespace ref validation

When cross-namespace references are disabled, ensure that UpstreamRef,
MetricTemplateRef, and AlertProviderRef default to the canary's namespace
if their namespace field is empty. This aligns the validation logic with
the rest of the controller and prevents false positives when the namespace
is omitted.

Fixes #1827

Signed-off-by: Barrera, Angel <angelbarrerasanchez@protonmail.com>
This commit is contained in:
Barrera, Angel
2025-10-08 09:16:29 +02:00
parent 0743ef72b3
commit eeeac3543a
2 changed files with 46 additions and 5 deletions
+22
View File
@@ -70,6 +70,28 @@ func TestController_verifyCanary(t *testing.T) {
},
wantErr: true,
},
{
name: "MetricTemplate in same namespace with no namespace specified should not return an error",
canary: flaggerv1.Canary{
ObjectMeta: metav1.ObjectMeta{
Name: "cd-1",
Namespace: "default",
},
Spec: flaggerv1.CanarySpec{
Analysis: &flaggerv1.CanaryAnalysis{
Metrics: []flaggerv1.CanaryMetric{
{
TemplateRef: &flaggerv1.CrossNamespaceObjectReference{
Name: "mt-1",
Namespace: "",
},
},
},
},
},
},
wantErr: false,
},
{
name: "AlertProvider in a different namespace should return an error",
canary: flaggerv1.Canary{