Skip to content

Commit 708ff9a

Browse files
committed
Resource Quota Per VolumeAttributesClass
Signed-off-by: carlory <[email protected]>
1 parent cd79f1d commit 708ff9a

File tree

3 files changed

+234
-0
lines changed

3 files changed

+234
-0
lines changed

content/en/docs/concepts/policy/resource-quotas.md

+180
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ Resources specified on the quota outside of the allowed set results in a validat
228228
| `NotBestEffort` | Match pods that do not have best effort quality of service. |
229229
| `PriorityClass` | Match pods that references the specified [priority class](/docs/concepts/scheduling-eviction/pod-priority-preemption). |
230230
| `CrossNamespacePodAffinity` | Match pods that have cross-namespace pod [(anti)affinity terms](/docs/concepts/scheduling-eviction/assign-pod-node). |
231+
| `VolumeAttributesClass` | Match persistentvolumeclaims that references the specified [volume attributes class](/docs/concepts/storage/volume-attributes-classes). |
231232

232233
The `BestEffort` scope restricts a quota to tracking the following resource:
233234

@@ -459,6 +460,185 @@ With the above configuration, pods can use `namespaces` and `namespaceSelector`
459460
if the namespace where they are created have a resource quota object with
460461
`CrossNamespacePodAffinity` scope and a hard limit greater than or equal to the number of pods using those fields.
461462

463+
## Resource Quota Per VolumeAttributesClass
464+
465+
{{< feature-state feature_gate_name="VolumeAttributesClass" >}}
466+
467+
PersistentVolumeClaims can be created with a specific [volume attributes class](/docs/concepts/storage/volume-attributes-classes/), and might be modified after creation. You can control a PVC's consumption of storage resources based on the associated volume attributes classes, by using the `scopeSelector` field in the quota spec.
468+
469+
The PVC references the associated volume attributes class by the following fields:
470+
471+
* `spec.volumeAttributesClassName`
472+
* `status.currentVolumeAttributesClassName`
473+
* `status.modifyVolumeStatus.targetVolumeAttributesClassName`
474+
475+
A quota is matched and consumed only if `scopeSelector` in the quota spec selects the PVC.
476+
477+
When quota is scoped for volume attributes class using `scopeSelector` field, quota object is restricted to track only following resources:
478+
479+
* `persistentvolumeclaims`
480+
* `requests.storage`
481+
482+
This example creates a quota object and matches it with PVC at specific volume attributes classes. The example works as follows:
483+
484+
- PVCs in the cluster have at least one of the three volume attributes classes, "gold", "silver", "copper".
485+
- One quota object is created for each volume attributes class.
486+
487+
Save the following YAML to a file `quota-vac.yaml`.
488+
489+
{{% code_sample file="policy/quota-vac.yaml" %}}
490+
491+
Apply the YAML using `kubectl create`.
492+
493+
```shell
494+
kubectl create -f ./quota-vac.yaml
495+
```
496+
497+
```
498+
resourcequota/pvcs-gold created
499+
resourcequota/pvcs-silver created
500+
resourcequota/pvcs-copper created
501+
```
502+
503+
Verify that `Used` quota is `0` using `kubectl describe quota`.
504+
505+
```shell
506+
kubectl describe quota
507+
```
508+
509+
```
510+
Name: pvcs-gold
511+
Namespace: default
512+
Resource Used Hard
513+
-------- ---- ----
514+
persistentvolumeclaims 0 10
515+
requests.storage 0 10Gi
516+
517+
518+
Name: pvcs-silver
519+
Namespace: default
520+
Resource Used Hard
521+
-------- ---- ----
522+
persistentvolumeclaims 0 10
523+
requests.storage 0 20Gi
524+
525+
526+
Name: pvcs-copper
527+
Namespace: default
528+
Resource Used Hard
529+
-------- ---- ----
530+
persistentvolumeclaims 0 10
531+
requests.storage 0 30Gi
532+
```
533+
534+
Create a pvc with volume attributes class "gold". Save the following YAML to a file `gold-vac-pvc.yaml`.
535+
536+
{{% code_sample file="policy/gold-vac-pvc.yaml" %}}
537+
538+
Apply it with `kubectl create`.
539+
540+
```shell
541+
kubectl create -f ./gold-vac-pvc.yaml
542+
```
543+
544+
Verify that "Used" stats for "gold" volume attributes class quota, `pvcs-gold` has changed and that the other two quotas are unchanged.
545+
546+
```shell
547+
kubectl describe quota
548+
```
549+
550+
```
551+
Name: pvcs-gold
552+
Namespace: default
553+
Resource Used Hard
554+
-------- ---- ----
555+
persistentvolumeclaims 1 10
556+
requests.storage 2Gi 10Gi
557+
558+
559+
Name: pvcs-silver
560+
Namespace: default
561+
Resource Used Hard
562+
-------- ---- ----
563+
persistentvolumeclaims 0 10
564+
requests.storage 0 20Gi
565+
566+
567+
Name: pvcs-copper
568+
Namespace: default
569+
Resource Used Hard
570+
-------- ---- ----
571+
persistentvolumeclaims 0 10
572+
requests.storage 0 30Gi
573+
```
574+
575+
Once the PVC is bound, it is allowed to modify the desired volume attributes class. Let's change it to "silver" with `kubectl patch`.
576+
577+
```shell
578+
kubectl patch pvc gold-vac-pvc --type='merge' -p '{"spec":{"volumeAttributesClassName":"silver"}}'
579+
```
580+
581+
Verify that "Used" stats for "silver" volume attributes class quota, `pvcs-silver` has changed, `pvcs-copper` is unchanged, and `pvcs-gold` might be unchanged or released, which depends on the PVC's status.
582+
```shell
583+
kubectl describe quota
584+
```
585+
586+
```
587+
Name: pvcs-gold
588+
Namespace: default
589+
Resource Used Hard
590+
-------- ---- ----
591+
persistentvolumeclaims 1 10
592+
requests.storage 2Gi 10Gi
593+
594+
595+
Name: pvcs-silver
596+
Namespace: default
597+
Resource Used Hard
598+
-------- ---- ----
599+
persistentvolumeclaims 1 10
600+
requests.storage 2Gi 20Gi
601+
602+
603+
Name: pvcs-copper
604+
Namespace: default
605+
Resource Used Hard
606+
-------- ---- ----
607+
persistentvolumeclaims 0 10
608+
requests.storage 0 30Gi
609+
```
610+
611+
Wait a moment for the operation to complete, then verify the quota again.
612+
613+
```shell
614+
kubectl describe quota
615+
```
616+
617+
```
618+
Name: pvcs-gold
619+
Namespace: default
620+
Resource Used Hard
621+
-------- ---- ----
622+
persistentvolumeclaims 0 10
623+
requests.storage 0 10Gi
624+
625+
626+
Name: pvcs-silver
627+
Namespace: default
628+
Resource Used Hard
629+
-------- ---- ----
630+
persistentvolumeclaims 1 10
631+
requests.storage 2Gi 20Gi
632+
633+
634+
Name: pvcs-copper
635+
Namespace: default
636+
Resource Used Hard
637+
-------- ---- ----
638+
persistentvolumeclaims 0 10
639+
requests.storage 0 30Gi
640+
```
641+
462642
## Requests compared to Limits {#requests-vs-limits}
463643

464644
When allocating compute resources, each container may specify a request and a limit value for either CPU or memory.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: gold-vac-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
resources:
9+
requests:
10+
storage: 2Gi
11+
storageClassName: # change this to the name of the storage class you want to use
12+
volumeAttributesClassName: gold
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: v1
2+
kind: List
3+
items:
4+
- apiVersion: v1
5+
kind: ResourceQuota
6+
metadata:
7+
name: pvcs-gold
8+
spec:
9+
hard:
10+
requests.storage: "10Gi"
11+
persistentvolumeclaims: "10"
12+
scopeSelector:
13+
matchExpressions:
14+
- operator: In
15+
scopeName: VolumeAttributesClass
16+
values: ["gold"]
17+
- apiVersion: v1
18+
kind: ResourceQuota
19+
metadata:
20+
name: pvcs-silver
21+
spec:
22+
hard:
23+
requests.storage: "20Gi"
24+
persistentvolumeclaims: "10"
25+
scopeSelector:
26+
matchExpressions:
27+
- operator: In
28+
scopeName: VolumeAttributesClass
29+
values: ["silver"]
30+
- apiVersion: v1
31+
kind: ResourceQuota
32+
metadata:
33+
name: pvcs-copper
34+
spec:
35+
hard:
36+
requests.storage: "30Gi"
37+
persistentvolumeclaims: "10"
38+
scopeSelector:
39+
matchExpressions:
40+
- operator: In
41+
scopeName: VolumeAttributesClass
42+
values: ["copper"]

0 commit comments

Comments
 (0)