Skip to content

Commit e5ef033

Browse files
dhaiducekopenshift-merge-bot[bot]
authored andcommitted
Fix dependency logic considering dots in names
There was an assumption a dot in a name meant it contained the namespace. But this doesn't make sense if the namespace is also provided. ref: https://issues.redhat.com/browse/ACM-14241 Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
1 parent 97476a5 commit e5ef033

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

controllers/propagator/replication.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,21 @@ func (r *Propagator) canonicalizeDependencies(
182182
})
183183
}
184184
} else if depIsPolicy(dep) {
185-
split := strings.Split(dep.Name, ".")
186-
if len(split) == 2 { // assume it's already in the correct <namespace>.<name> format
187-
deps = append(deps, dep)
188-
} else {
189-
if dep.Namespace == "" {
190-
// use the namespace from the dependent policy when otherwise not provided
191-
dep.Namespace = defaultNamespace
185+
if dep.Namespace == "" {
186+
split := strings.Split(dep.Name, ".")
187+
if len(split) >= 2 { // assume the name is already in the correct <namespace>.<name> format
188+
deps = append(deps, dep)
189+
190+
continue
192191
}
192+
// use the namespace from the dependent policy when otherwise not provided
193+
dep.Namespace = defaultNamespace
194+
}
193195

194-
dep.Name = dep.Namespace + "." + dep.Name
195-
dep.Namespace = ""
196+
dep.Name = dep.Namespace + "." + dep.Name
197+
dep.Namespace = ""
196198

197-
deps = append(deps, dep)
198-
}
199+
deps = append(deps, dep)
199200
} else {
200201
deps = append(deps, dep)
201202
}

controllers/propagator/replication_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,14 @@ func TestCanonicalizeDependencies(t *testing.T) {
185185
input: []policiesv1.PolicyDependency{
186186
depPol("red", "colors", "Compliant"),
187187
depPol("blue", "colors", "NonCompliant"),
188+
depPol("1.2", "colors", "NonCompliant"),
189+
depPol("colors.1.2", "", "NonCompliant"),
188190
},
189191
want: []policiesv1.PolicyDependency{
190192
depPol("colors.red", "", "Compliant"),
191193
depPol("colors.blue", "", "NonCompliant"),
194+
depPol("colors.1.2", "", "NonCompliant"),
195+
depPol("colors.1.2", "", "NonCompliant"),
192196
},
193197
},
194198
"policies without namespaces": {
@@ -225,7 +229,7 @@ func TestCanonicalizeDependencies(t *testing.T) {
225229
}
226230

227231
if !reflect.DeepEqual(test.want, got) {
228-
t.Fatalf("expected: %v, got: %v", test.want, got)
232+
t.Fatalf("%s\nexpected:\n%v\ngot:\n%v", name, test.want, got)
229233
}
230234
})
231235
}

0 commit comments

Comments
 (0)