Skip to content

Commit 0999434

Browse files
zachsmith1claude
andcommitted
fix: skip quota enforcement for resources outside project context
The admission plugin now skips ResourceClaim creation when no consumer (project) context can be determined. Quota is enforced per-project, so resources created in the root control plane are not subject to quota. Previously, creating Notes, ConfigMaps, or Secrets outside a project control plane would fail with "Insufficient quota" because the claim had no consumerRef and couldn't match any AllowanceBucket. Also add test-specific ResourceGrants to the note-multicluster-subject and clusternote-multicluster-subject e2e tests so they have quota allocated in their project control planes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7f5c1ec commit 0999434

5 files changed

Lines changed: 85 additions & 0 deletions

File tree

internal/quota/admission/plugin.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,17 @@ func (p *ResourceQuotaEnforcementPlugin) createResourceClaim(ctx context.Context
704704
}
705705
}
706706

707+
// Skip claim creation when no consumer can be determined. Quota is
708+
// enforced per-project, so resources created outside a project context
709+
// (e.g. in the root control plane) are not subject to quota.
710+
if claim.Spec.ConsumerRef.Kind == "" || claim.Spec.ConsumerRef.Name == "" {
711+
p.logger.V(2).Info("Skipping ResourceClaim creation: no consumer context (not in a project control plane)",
712+
"claimName", claimName,
713+
"namespace", namespace,
714+
"resourceName", attrs.GetName())
715+
return nil
716+
}
717+
707718
if claim.Labels == nil {
708719
claim.Labels = make(map[string]string)
709720
}

test/notes/clusternote-multicluster-subject/chainsaw-test.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ spec:
5353
name: Ready
5454
value: 'true'
5555

56+
- name: setup-quota-grant
57+
description: Provision quota for the project so resources can be created
58+
cluster: project
59+
try:
60+
- apply:
61+
file: test-data/quota-grant.yaml
62+
- wait:
63+
apiVersion: quota.miloapis.com/v1alpha1
64+
kind: ResourceGrant
65+
name: test-clusternotes-quota-grant
66+
namespace: milo-system
67+
timeout: 30s
68+
for:
69+
condition:
70+
name: Active
71+
value: 'True'
72+
5673
- name: create-namespace-in-project
5774
description: Create cluster-scoped Namespace in project control plane
5875
cluster: project
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: quota.miloapis.com/v1alpha1
2+
kind: ResourceGrant
3+
metadata:
4+
name: test-clusternotes-quota-grant
5+
namespace: milo-system
6+
spec:
7+
consumerRef:
8+
apiGroup: resourcemanager.miloapis.com
9+
kind: Project
10+
name: cn-mc-test-project-1
11+
allowances:
12+
- resourceType: notes.miloapis.com/notes
13+
buckets:
14+
- amount: 100
15+
- resourceType: core.miloapis.com/configmaps
16+
buckets:
17+
- amount: 100
18+
- resourceType: core.miloapis.com/secrets
19+
buckets:
20+
- amount: 100

test/notes/note-multicluster-subject/chainsaw-test.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ spec:
5252
name: Ready
5353
value: 'true'
5454

55+
- name: setup-quota-grant
56+
description: Provision quota for the project so resources can be created
57+
cluster: project
58+
try:
59+
- apply:
60+
file: test-data/quota-grant.yaml
61+
- wait:
62+
apiVersion: quota.miloapis.com/v1alpha1
63+
kind: ResourceGrant
64+
name: test-notes-quota-grant
65+
namespace: milo-system
66+
timeout: 30s
67+
for:
68+
condition:
69+
name: Active
70+
value: 'True'
71+
5572
- name: create-configmap-in-project
5673
description: Create ConfigMap resource in project control plane
5774
cluster: project
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: quota.miloapis.com/v1alpha1
2+
kind: ResourceGrant
3+
metadata:
4+
name: test-notes-quota-grant
5+
namespace: milo-system
6+
spec:
7+
consumerRef:
8+
apiGroup: resourcemanager.miloapis.com
9+
kind: Project
10+
name: note-mc-test-project-1
11+
allowances:
12+
- resourceType: notes.miloapis.com/notes
13+
buckets:
14+
- amount: 100
15+
- resourceType: core.miloapis.com/configmaps
16+
buckets:
17+
- amount: 100
18+
- resourceType: core.miloapis.com/secrets
19+
buckets:
20+
- amount: 100

0 commit comments

Comments
 (0)