Skip to content

Commit 473e47f

Browse files
authored
chore: dns quotas (#132)
This pull request introduces quota management for DNS resources in the `dns.networking.miloapis.com` service. It adds resource registrations, claim and grant policies, and organizes them using kustomize components to ensure correct application order. The changes enable automatic quota enforcement for DNS zones and record sets at the project and organization level, with special handling for personal organizations. Key changes: **Quota System Structure and Organization** - Added the `dns.networking.miloapis.com` service as a component to the main `kustomization.yaml` to integrate DNS quota management into the broader system. - Introduced a new `quota` component for the DNS service, further split into `registrations`, `grant-policies`, and `claim-policies` subcomponents, each with their own kustomization files for resource ordering. **Resource Registration** - Defined `ResourceRegistration` objects for `dnszones` and `dnsrecordsets`, specifying how quota is counted and which resources can claim against these quotas. **Quota Policies** - Added `ClaimCreationPolicy` resources for both `DNSZone` and `DNSRecordSet`, enforcing that these resources must be labeled with project and organization identifiers, and automatically generating quota claims upon creation. - Created a `GrantCreationPolicy` for allocating default DNS quotas to projects in personal organizations, with specific limits for DNS zones and record sets.
2 parents a8e2340 + 6f4e7b1 commit 473e47f

File tree

11 files changed

+224
-1
lines changed

11 files changed

+224
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: kustomize.config.k8s.io/v1alpha1
2+
kind: Component
3+
4+
# Use explicit sorting options so we can guarantee order in which resources are
5+
# applied.
6+
sortOptions:
7+
order: fifo
8+
9+
components:
10+
- quota/
11+
12+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: quota.miloapis.com/v1alpha1
2+
kind: ClaimCreationPolicy
3+
metadata:
4+
name: project-dnsrecordset-claim-policy
5+
labels:
6+
app.kubernetes.io/name: datum
7+
app.kubernetes.io/component: quota-system
8+
spec:
9+
trigger:
10+
resource:
11+
apiVersion: dns.networking.miloapis.com/v1alpha1
12+
kind: DNSRecordSet
13+
target:
14+
resourceClaimTemplate:
15+
metadata:
16+
name: "dnsrecordset-{{ trigger.metadata.name }}"
17+
namespace: "{{requestInfo.namespace}}"
18+
labels:
19+
app.kubernetes.io/name: datum
20+
app.kubernetes.io/component: quota-system
21+
annotations:
22+
kubernetes.io/description: "Automatic quota claim for DNSRecordSet creation"
23+
spec:
24+
requests:
25+
- resourceType: dns.networking.miloapis.com/dnsrecordsets
26+
amount: 1
27+
28+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: quota.miloapis.com/v1alpha1
2+
kind: ClaimCreationPolicy
3+
metadata:
4+
name: project-dnszone-claim-policy
5+
labels:
6+
app.kubernetes.io/name: datum
7+
app.kubernetes.io/component: quota-system
8+
spec:
9+
trigger:
10+
resource:
11+
apiVersion: dns.networking.miloapis.com/v1alpha1
12+
kind: DNSZone
13+
target:
14+
resourceClaimTemplate:
15+
metadata:
16+
name: "dnszone-{{ trigger.metadata.name }}"
17+
namespace: "{{requestInfo.namespace}}"
18+
labels:
19+
app.kubernetes.io/name: datum
20+
app.kubernetes.io/component: quota-system
21+
annotations:
22+
kubernetes.io/description: "Automatic quota claim for DNSZone creation"
23+
spec:
24+
requests:
25+
- resourceType: dns.networking.miloapis.com/dnszones
26+
amount: 1
27+
28+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: kustomize.config.k8s.io/v1alpha1
2+
kind: Component
3+
4+
# Use explicit sorting options so we can guarantee order in which resources are
5+
# applied.
6+
sortOptions:
7+
order: fifo
8+
9+
resources:
10+
- dnszone-claim-policy.yaml
11+
- dnsrecordset-claim-policy.yaml
12+
13+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: kustomize.config.k8s.io/v1alpha1
2+
kind: Component
3+
4+
# Use explicit sorting options so we can guarantee order in which resources are
5+
# applied.
6+
sortOptions:
7+
order: fifo
8+
9+
resources:
10+
- personal-org-grant-policy.yaml
11+
12+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: quota.miloapis.com/v1alpha1
2+
kind: GrantCreationPolicy
3+
metadata:
4+
name: personal-organization-dns-quota-policy
5+
labels:
6+
app.kubernetes.io/name: datum
7+
app.kubernetes.io/component: quota-system
8+
spec:
9+
trigger:
10+
resource:
11+
apiVersion: resourcemanager.miloapis.com/v1alpha1
12+
kind: Project
13+
target:
14+
parentContext:
15+
apiGroup: "resourcemanager.miloapis.com"
16+
kind: "Project"
17+
nameExpression: "trigger.metadata.name"
18+
resourceGrantTemplate:
19+
metadata:
20+
name: "default-dns-quota-{{ trigger.metadata.name }}"
21+
namespace: milo-system
22+
annotations:
23+
kubernetes.io/description: "DNS quota allocation for Personal org project"
24+
spec:
25+
consumerRef:
26+
apiGroup: resourcemanager.miloapis.com
27+
kind: Project
28+
name: "{{ trigger.metadata.name }}"
29+
allowances:
30+
- resourceType: dns.networking.miloapis.com/dnszones
31+
buckets:
32+
- amount: 25
33+
- resourceType: dns.networking.miloapis.com/dnsrecordsets
34+
buckets:
35+
- amount: 500
36+
37+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: kustomize.config.k8s.io/v1alpha1
2+
kind: Component
3+
4+
# Use explicit sorting options so we can guarantee that resource registrations
5+
# are applied before grant / claim creation policies that reference the
6+
# resources being created.
7+
sortOptions:
8+
order: fifo
9+
10+
components:
11+
- registrations/
12+
- grant-policies/
13+
- claim-policies/
14+
15+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: quota.miloapis.com/v1alpha1
2+
kind: ResourceRegistration
3+
metadata:
4+
name: dnsrecordsets-per-project
5+
labels:
6+
app.kubernetes.io/name: datum
7+
app.kubernetes.io/component: quota-system
8+
spec:
9+
# Project is the consumer of DNS record set quota
10+
consumerType:
11+
apiGroup: resourcemanager.miloapis.com
12+
kind: Project
13+
14+
# Count-based quota for DNS record sets
15+
type: Entity
16+
17+
# The resource type being managed
18+
resourceType: dns.networking.miloapis.com/dnsrecordsets
19+
20+
description: "Maximum number of DNS record sets that can be created within a project"
21+
22+
# Simple counting units
23+
baseUnit: recordset
24+
displayUnit: recordsets
25+
unitConversionFactor: 1
26+
27+
# DNSRecordSet resources can claim quota against this registration
28+
claimingResources:
29+
- apiGroup: dns.networking.miloapis.com
30+
kind: DNSRecordSet
31+
32+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: quota.miloapis.com/v1alpha1
2+
kind: ResourceRegistration
3+
metadata:
4+
name: dnszones-per-project
5+
labels:
6+
app.kubernetes.io/name: datum
7+
app.kubernetes.io/component: quota-system
8+
spec:
9+
# Project is the consumer of DNS zone quota
10+
consumerType:
11+
apiGroup: resourcemanager.miloapis.com
12+
kind: Project
13+
14+
# Count-based quota for DNS zones
15+
type: Entity
16+
17+
# The resource type being managed
18+
resourceType: dns.networking.miloapis.com/dnszones
19+
20+
description: "Maximum number of DNS zones that can be created within a project"
21+
22+
# Simple counting units
23+
baseUnit: zone
24+
displayUnit: zones
25+
unitConversionFactor: 1
26+
27+
# DNSZone resources can claim quota against this registration
28+
claimingResources:
29+
- apiGroup: dns.networking.miloapis.com
30+
kind: DNSZone
31+
32+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: kustomize.config.k8s.io/v1alpha1
2+
kind: Component
3+
4+
# Use explicit sorting options so we can guarantee order in which resources are
5+
# applied.
6+
sortOptions:
7+
order: fifo
8+
9+
resources:
10+
- dnszone-registration.yaml
11+
- dnsrecordset-registration.yaml
12+
13+

0 commit comments

Comments
 (0)