Skip to content

Commit f02264c

Browse files
authored
Changes to consider StoragePolicyReservation CRs during periodic sync calculations of expected Reserved capacity (#3454)
1 parent fff2b83 commit f02264c

File tree

8 files changed

+508
-5
lines changed

8 files changed

+508
-5
lines changed

manifests/supervisorcluster/1.30/cns-csi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ rules:
9090
- apiGroups: ["cns.vmware.com"]
9191
resources: ["storagepolicyquotas"]
9292
verbs: ["get", "list", "watch"]
93+
- apiGroups: ["cns.vmware.com"]
94+
resources: ["storagepolicyreservations"]
95+
verbs: ["get", "list", "watch"]
9396
- apiGroups: ["apps"]
9497
resources: ["statefulsets"]
9598
verbs: ["list"]
@@ -572,6 +575,7 @@ data:
572575
"file-volume-with-vm-service": "false"
573576
"csi-transaction-support": "false"
574577
"linked-clone-support": "false"
578+
"storage-policy-reservation-support": "false"
575579
kind: ConfigMap
576580
metadata:
577581
name: csi-feature-states

manifests/supervisorcluster/1.31/cns-csi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ rules:
9090
- apiGroups: ["cns.vmware.com"]
9191
resources: ["storagepolicyquotas"]
9292
verbs: ["get", "list", "watch"]
93+
- apiGroups: ["cns.vmware.com"]
94+
resources: ["storagepolicyreservations"]
95+
verbs: ["get", "list", "watch"]
9396
- apiGroups: ["apps"]
9497
resources: ["statefulsets"]
9598
verbs: ["list"]
@@ -572,6 +575,7 @@ data:
572575
"file-volume-with-vm-service": "false"
573576
"csi-transaction-support": "false"
574577
"linked-clone-support": "false"
578+
"storage-policy-reservation-support": "false"
575579
kind: ConfigMap
576580
metadata:
577581
name: csi-feature-states

manifests/supervisorcluster/1.32/cns-csi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ rules:
9090
- apiGroups: ["cns.vmware.com"]
9191
resources: ["storagepolicyquotas"]
9292
verbs: ["get", "list", "watch"]
93+
- apiGroups: ["cns.vmware.com"]
94+
resources: ["storagepolicyreservations"]
95+
verbs: ["get", "list", "watch"]
9396
- apiGroups: ["apps"]
9497
resources: ["statefulsets"]
9598
verbs: ["list"]
@@ -570,6 +573,7 @@ data:
570573
"sv-pvc-snapshot-protection-finalizer": "false"
571574
"file-volume-with-vm-service": "false"
572575
"linked-clone-support": "false"
576+
"storage-policy-reservation-support": "false"
573577
kind: ConfigMap
574578
metadata:
575579
name: csi-feature-states

pkg/apis/cnsoperator/register.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ var (
7171
CnsStoragePolicyQuotaSingular = "storagepolicyquota"
7272
// CnsStoragePolicyQuotaPlural is plural of StoragePolicyQuota
7373
CnsStoragePolicyQuotaPlural = "storagepolicyquotas"
74+
// CnsStoragePolicyReservationSingular is Singular of StoragePolicyReservation
75+
CnsStoragePolicyReservationSingular = "storagepolicyreservation"
76+
// CnsStoragePolicyReservationPlural is plural of StoragePolicyReservation
77+
CnsStoragePolicyReservationPlural = "storagepolicyreservations"
7478
)
7579

7680
var (
@@ -159,6 +163,12 @@ func addKnownTypes(scheme *runtime.Scheme) error {
159163
&storagepolicyv1alpha2.StoragePolicyQuotaList{},
160164
)
161165

166+
scheme.AddKnownTypes(
167+
SchemeGroupVersionV2,
168+
&storagepolicyv1alpha2.StoragePolicyReservation{},
169+
&storagepolicyv1alpha2.StoragePolicyReservationList{},
170+
)
171+
162172
scheme.AddKnownTypes(
163173
SchemeGroupVersion,
164174
&metav1.Status{},
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha2
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/api/resource"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// StoragePolicyReservationSpec defines the desired state of StoragePolicyReservation
25+
type StoragePolicyReservationSpec struct {
26+
// +kubebuilder:validation:Required
27+
Requested []Requested `json:"requested"`
28+
}
29+
30+
// Requested defines a storage reservation request for a given object
31+
type Requested struct {
32+
// APIGroup is the group for the resource being referenced.
33+
// If APIGroup is not specified, the specified Kind must be in the core API group.
34+
// For any other third-party types, APIGroup is required.
35+
// +optional
36+
APIGroup *string `json:"apiGroup,omitempty"`
37+
// Kind of the requested storage object.
38+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
39+
Kind string `json:"kind"`
40+
// Name of the requested storage object such as a VM service VM API object.
41+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
42+
Name string `json:"name"`
43+
// +listType=map
44+
// +listMapKey=storageClassName
45+
// ReservationRequests define request for storage quota associated with a StorageClass
46+
ReservationRequests []ReservationRequest `json:"reservationRequests"`
47+
}
48+
49+
// ReservationRequest defines request for storage quota associated with a StorageClass
50+
type ReservationRequest struct {
51+
// Name of the Kubernetes StorageClass
52+
StorageClassName string `json:"storageClassName"`
53+
// Requested capacity for a storage resource to be provisioned at a later time
54+
Request *resource.Quantity `json:"request,omitempty"`
55+
}
56+
57+
// StoragePolicyReservationStatus defines the observed state of StoragePolicyReservation
58+
type StoragePolicyReservationStatus struct {
59+
Approved []StorageObject `json:"approved,omitempty"`
60+
Denied []StorageObject `json:"denied,omitempty"`
61+
}
62+
63+
// StorageObject defines a storage reservation for a given object
64+
type StorageObject struct {
65+
// APIGroup is the group for the resource being referenced.
66+
// If APIGroup is not specified, the specified Kind must be in the core API group.
67+
// For any other third-party types, APIGroup is required.
68+
// +optional
69+
APIGroup *string `json:"apiGroup,omitempty"`
70+
// Kind of the requested storage object.
71+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
72+
Kind string `json:"kind"`
73+
// Name of the requested storage object.
74+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
75+
Name string `json:"name"`
76+
// Name of the Kubernetes StorageClass
77+
StorageClassName string `json:"storageClassName"`
78+
// Requested capacity for a storage resource being provisioned
79+
Request *resource.Quantity `json:"request,omitempty"`
80+
// Indicates the reason why the reservation for an object is being denied
81+
// +optional
82+
Reason *string `json:"reason,omitempty"`
83+
}
84+
85+
//+kubebuilder:object:root=true
86+
//+kubebuilder:subresource:status
87+
//+kubebuilder:storageversion
88+
89+
// StoragePolicyReservation is the Schema for the storagepolicyreservations API
90+
type StoragePolicyReservation struct {
91+
metav1.TypeMeta `json:",inline"`
92+
metav1.ObjectMeta `json:"metadata,omitempty"`
93+
94+
Spec StoragePolicyReservationSpec `json:"spec"`
95+
Status StoragePolicyReservationStatus `json:"status,omitempty"`
96+
}
97+
98+
//+kubebuilder:object:root=true
99+
100+
// StoragePolicyReservationList contains a list of StoragePolicyReservation
101+
type StoragePolicyReservationList struct {
102+
metav1.TypeMeta `json:",inline"`
103+
metav1.ListMeta `json:"metadata,omitempty"`
104+
Items []StoragePolicyReservation `json:"items"`
105+
}

pkg/apis/cnsoperator/storagepolicy/v1alpha2/zz_generated.deepcopy.go

Lines changed: 187 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)