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

Commit

Permalink
Merge pull request #787 from yiqigao217/v5
Browse files Browse the repository at this point in the history
Allow cascadingDelete if any ancestor allows
  • Loading branch information
k8s-ci-robot committed Jun 5, 2020
2 parents c6b9e17 + 3fd32c7 commit add0b3c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 3 additions & 8 deletions incubator/hnc/internal/forest/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,17 @@ func (ns *Namespace) UpdateAllowCascadingDelete(acd bool) {
ns.allowCascadingDelete = acd
}

// AllowsCascadingDelete returns if the namespace's or any of the owner ancestors'
// AllowsCascadingDelete returns true if the namespace's or any of the ancestors'
// allowCascadingDelete field is set to true.
func (ns *Namespace) AllowsCascadingDelete() bool {
if ns.allowCascadingDelete == true {
return true
}
if !ns.IsSub {
if ns.parent == nil || ns.CycleNames() != nil {
return false
}

// This is a subnamespace so it must have a non-nil parent. If the parent is missing, it will
// return the default false.
//
// Subnamespaces can never be involved in cycles, since those can only occur at the "top" of a
// tree and subnamespaces cannot be roots by definition. So this line can't cause a stack
// overflow.
// This namespace is neither a root nor in a cycle, so this line can't cause a stack overflow.
return ns.parent.AllowsCascadingDelete()
}

Expand Down
6 changes: 4 additions & 2 deletions incubator/hnc/internal/validators/anchor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
)

func TestSubnamespaces(t *testing.T) {
// Two roots `a` and `b`, with `c` a subnamespace of `a`, and `d` a regular child of `b`
f := foresttest.Create("--Ab")
// Two roots `a` and `b`, with `c` a subnamespace of `a`, `e` a regular child of `c`,
// `f` a subnamespace of `e` and `d` a regular child of `b`
f := foresttest.Create("--AbcE")
h := &Anchor{Forest: f}
f.Get("c").UpdateAllowCascadingDelete(true)

Expand All @@ -25,6 +26,7 @@ func TestSubnamespaces(t *testing.T) {
}{
{name: "ok-create", op: v1beta1.Create, pnm: "a", cnm: "brumpf"},
{name: "ok-delete", op: v1beta1.Delete, pnm: "a", cnm: "c"},
{name: "ok-delete with allowCascadingDelete set in ancestor", op: v1beta1.Delete, pnm: "e", cnm: "f"},
{name: "create anchor in excluded ns", op: v1beta1.Create, pnm: "kube-system", cnm: "brumpf", fail: true},
{name: "create anchor with existing ns name", op: v1beta1.Create, pnm: "a", cnm: "b", fail: true},
{name: "create anchor for existing non-subns child", op: v1beta1.Create, pnm: "b", cnm: "d", fail: true},
Expand Down

0 comments on commit add0b3c

Please sign in to comment.