Skip to content

Commit 1b8dc5d

Browse files
authored
Handles cases where a namespace that is not a sub-namespace is mixed in (#12)
Signed-off-by: utam0k <utam0k@preferred.jp>
1 parent 5ed7787 commit 1b8dc5d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

internal/forest/namespacehrq.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ func (n *Namespace) UseResources(rqName string, newUsage v1.ResourceList) error
188188

189189
nsQuota, ok := ns.quotas[rqName]
190190
if !ok {
191-
return fmt.Errorf("no quota found for %q", rqName)
191+
// This is a parent or above namespace.
192+
continue
192193
}
193194

194195
// Get the new subtree usage and remove no longer limited usages.

test/e2e/pfn_hrq_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,16 @@ func setScopedHRQ(nm, nsnm string, resourceList corev1.ResourceList, scopeSelect
178178
}
179179

180180
func setUpParentAndChild() (string, string, func()) {
181-
parentNs := createNS("hrq-test-parent-")
182-
childNs := createSubNS(parentNs)
181+
// There was the case where bug has occurred when there is a grandchildren namespace, so We'll make one.
182+
rootNs := createNS("root-")
183+
parentNs := createSubNS(rootNs, "parent-")
184+
childNs := createSubNS(parentNs, "child-")
183185
cleanup := func() {
186+
MustRunWithTimeout(cleanupTimeout, "kubectl annotate ns", rootNs , "hnc.x-k8s.io/subnamespace-of-")
184187
MustRunWithTimeout(cleanupTimeout, "kubectl annotate ns", parentNs, "hnc.x-k8s.io/subnamespace-of-")
185188
MustRunWithTimeout(cleanupTimeout, "kubectl annotate ns", childNs, "hnc.x-k8s.io/subnamespace-of-")
186189
var wg sync.WaitGroup
187-
for _, ns := range []string{parentNs, childNs} {
190+
for _, ns := range []string{rootNs, parentNs, childNs} {
188191
wg.Add(1)
189192
go func(ns string) {
190193
MustRun("kubectl delete ns", ns)
@@ -204,8 +207,8 @@ func createNS(prefix string) string {
204207
return nsName
205208
}
206209

207-
func createSubNS(parent string) string {
208-
nsName := "hrq-test-child-" + uuid.New().String()
210+
func createSubNS(parent, prefix string) string {
211+
nsName := prefix + uuid.New().String()
209212
MustRun("kubectl hns create", nsName, "-n", parent)
210213
return nsName
211214
}

0 commit comments

Comments
 (0)