Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Fix a nil pointer issue in HC webhook when setting as root #1121

Merged
merged 1 commit into from
Sep 18, 2020
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
5 changes: 5 additions & 0 deletions incubator/hnc/internal/validators/hierarchy.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ func (v *Hierarchy) checkParent(ns, curParent, newParent *forest.Namespace) admi

// getConflictingObjects returns a list of namespaced objects if there's any conflict.
func (v *Hierarchy) getConflictingObjects(newParent, ns *forest.Namespace) []string {
// If the new parent is nil, early exit since it's impossible to introduce
// new naming conflicts.
if newParent == nil {
return nil
}
// Traverse all the types with 'Propagate' mode to find any conflicts.
conflicts := []string{}
for _, t := range v.Forest.GetTypeSyncers() {
Expand Down
1 change: 1 addition & 0 deletions incubator/hnc/internal/validators/hierarchy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func TestChangeParentWithConflict(t *testing.T) {
{name: "ok: no conflict in ancestors", nnm: "a", pnm: "c"},
{name: "conflict in subtree leaf and the new parent", nnm: "c", pnm: "a", fail: true},
{name: "conflict in subtree leaf and a new ancestor (not the parent)", nnm: "c", pnm: "b", fail: true},
{name: "ok: set a namespace as root", nnm: "d", pnm: ""},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down