4
4
package v1alpha1
5
5
6
6
import (
7
+ corev1 "k8s.io/api/core/v1"
8
+ storagev1 "k8s.io/api/storage/v1"
9
+ "k8s.io/utils/ptr"
7
10
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
8
11
9
12
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/variables"
10
13
)
11
14
15
+ const (
16
+ AddonStrategyClusterResourceSet AddonStrategy = "ClusterResourceSet"
17
+ AddonStrategyHelmAddon AddonStrategy = "HelmAddon"
18
+ VolumeBindingImmediate = storagev1 .VolumeBindingImmediate
19
+ VolumeBindingWaitForFirstConsumer = storagev1 .VolumeBindingWaitForFirstConsumer
20
+
21
+ VolumeReclaimRecycle = corev1 .PersistentVolumeReclaimRecycle
22
+ VolumeReclaimDelete = corev1 .PersistentVolumeReclaimDelete
23
+ VolumeReclaimRetain = corev1 .PersistentVolumeReclaimRetain
24
+ )
25
+
12
26
type Addons struct {
13
27
// +optional
14
28
CNI * CNI `json:"cni,omitempty"`
@@ -23,7 +37,7 @@ type Addons struct {
23
37
CCM * CCM `json:"ccm,omitempty"`
24
38
25
39
// +optional
26
- CSIProviders * CSIProviders `json:"csi,omitempty"`
40
+ CSIProviders * CSI `json:"csi,omitempty"`
27
41
}
28
42
29
43
func (Addons ) VariableSchema () clusterv1.VariableSchema {
@@ -35,7 +49,7 @@ func (Addons) VariableSchema() clusterv1.VariableSchema {
35
49
"cni" : CNI {}.VariableSchema ().OpenAPIV3Schema ,
36
50
"nfd" : NFD {}.VariableSchema ().OpenAPIV3Schema ,
37
51
"clusterAutoscaler" : ClusterAutoscaler {}.VariableSchema ().OpenAPIV3Schema ,
38
- "csi" : CSIProviders {}.VariableSchema ().OpenAPIV3Schema ,
52
+ "csi" : CSI {}.VariableSchema ().OpenAPIV3Schema ,
39
53
"ccm" : CCM {}.VariableSchema ().OpenAPIV3Schema ,
40
54
},
41
55
},
@@ -44,11 +58,6 @@ func (Addons) VariableSchema() clusterv1.VariableSchema {
44
58
45
59
type AddonStrategy string
46
60
47
- const (
48
- AddonStrategyClusterResourceSet AddonStrategy = "ClusterResourceSet"
49
- AddonStrategyHelmAddon AddonStrategy = "HelmAddon"
50
- )
51
-
52
61
// CNI required for providing CNI configuration.
53
62
type CNI struct {
54
63
// +optional
@@ -134,40 +143,168 @@ func (ClusterAutoscaler) VariableSchema() clusterv1.VariableSchema {
134
143
}
135
144
}
136
145
137
- type CSIProviders struct {
146
+ type DefaultStorage struct {
147
+ ProviderName string `json:"providerName"`
148
+ StorageClassConfigName string `json:"storageClassConfigName"`
149
+ }
150
+
151
+ type CSI struct {
138
152
// +optional
139
153
Providers []CSIProvider `json:"providers,omitempty"`
140
154
// +optional
141
- DefaultClassName string `json:"defaultClassName ,omitempty"`
155
+ DefaultStorage * DefaultStorage `json:"defaultStorage ,omitempty"`
142
156
}
143
157
144
158
type CSIProvider struct {
145
- Name string `json:"name,omitempty"`
159
+ Name string `json:"name"`
160
+
161
+ // +optional
162
+ StorageClassConfig []StorageClassConfig `json:"storageClassConfig,omitempty"`
163
+
164
+ Strategy AddonStrategy `json:"strategy"`
165
+
166
+ // +optional
167
+ Credentials * corev1.SecretReference `json:"credentials,omitempty"`
146
168
}
147
169
148
- func (CSIProviders ) VariableSchema () clusterv1.VariableSchema {
149
- supportedCSIProviders := []string {CSIProviderAWSEBS }
170
+ type StorageClassConfig struct {
171
+ Name string `json:"name"`
172
+
173
+ // +optional
174
+ Parameters map [string ]string `json:"parameters,omitempty"`
175
+
176
+ // +optional
177
+ ReclaimPolicy corev1.PersistentVolumeReclaimPolicy `json:"reclaimPolicy,omitempty"`
178
+
179
+ // +optional
180
+ VolumeBindingMode storagev1.VolumeBindingMode `json:"volumeBindingMode,omitempty"`
181
+
182
+ // +optional
183
+ AllowExpansion bool `json:"allowExpansion,omitempty"`
184
+ }
185
+
186
+ func (StorageClassConfig ) VariableSchema () clusterv1.VariableSchema {
187
+ supportedReclaimPolicies := []string {
188
+ string (VolumeReclaimRecycle ),
189
+ string (VolumeReclaimDelete ),
190
+ string (VolumeReclaimRetain ),
191
+ }
192
+ supportedBindingModes := []string {
193
+ string (VolumeBindingImmediate ),
194
+ string (VolumeBindingWaitForFirstConsumer ),
195
+ }
150
196
return clusterv1.VariableSchema {
151
197
OpenAPIV3Schema : clusterv1.JSONSchemaProps {
152
- Type : "object" ,
198
+ Type : "object" ,
199
+ Required : []string {"name" },
153
200
Properties : map [string ]clusterv1.JSONSchemaProps {
154
- "providers" : {
155
- Type : "array" ,
156
- Items : & clusterv1.JSONSchemaProps {
157
- Type : "object" ,
158
- Properties : map [string ]clusterv1.JSONSchemaProps {
159
- "name" : {
160
- Type : "string" ,
161
- Enum : variables .MustMarshalValuesToEnumJSON (
162
- supportedCSIProviders ... ),
163
- },
201
+ "name" : {
202
+ Type : "string" ,
203
+ Description : "Name of storage class config." ,
204
+ },
205
+ "parameters" : {
206
+ Type : "object" ,
207
+ Description : "Parameters passed into the storage class object." ,
208
+ AdditionalProperties : & clusterv1.JSONSchemaProps {
209
+ Type : "string" ,
210
+ },
211
+ },
212
+ "reclaimPolicy" : {
213
+ Type : "string" ,
214
+ Enum : variables .MustMarshalValuesToEnumJSON (supportedReclaimPolicies ... ),
215
+ Default : variables .MustMarshal (VolumeReclaimDelete ),
216
+ },
217
+ "volumeBindingMode" : {
218
+ Type : "string" ,
219
+ Enum : variables .MustMarshalValuesToEnumJSON (supportedBindingModes ... ),
220
+ Default : variables .MustMarshal (VolumeBindingWaitForFirstConsumer ),
221
+ },
222
+ "allowExpansion" : {
223
+ Type : "boolean" ,
224
+ Default : variables .MustMarshal (false ),
225
+ Description : "If the storage class should allow volume expanding" ,
226
+ },
227
+ },
228
+ },
229
+ }
230
+ }
231
+
232
+ func (CSIProvider ) VariableSchema () clusterv1.VariableSchema {
233
+ supportedCSIProviders := []string {CSIProviderAWSEBS , CSIProviderNutanix }
234
+ return clusterv1.VariableSchema {
235
+ OpenAPIV3Schema : clusterv1.JSONSchemaProps {
236
+ Type : "object" ,
237
+ Required : []string {"name" , "strategy" },
238
+ Properties : map [string ]clusterv1.JSONSchemaProps {
239
+ "name" : {
240
+ Description : "Name of the CSI Provider" ,
241
+ Type : "string" ,
242
+ Enum : variables .MustMarshalValuesToEnumJSON (
243
+ supportedCSIProviders ... ),
244
+ },
245
+ "strategy" : {
246
+ Description : "Addon strategy used to deploy the CSI provider to the workload cluster" ,
247
+ Type : "string" ,
248
+ Enum : variables .MustMarshalValuesToEnumJSON (
249
+ AddonStrategyClusterResourceSet ,
250
+ AddonStrategyHelmAddon ,
251
+ ),
252
+ },
253
+ "credentials" : {
254
+ Type : "object" ,
255
+ Description : "The reference to any secret used by the CSI Provider." ,
256
+ Properties : map [string ]clusterv1.JSONSchemaProps {
257
+ "name" : {
258
+ Type : "string" ,
259
+ },
260
+ "namespace" : {
261
+ Type : "string" ,
164
262
},
165
263
},
166
264
},
167
- "defaultClassName" : {
168
- Type : "string" ,
169
- Enum : variables .MustMarshalValuesToEnumJSON (supportedCSIProviders ... ),
265
+ "storageClassConfig" : {
266
+ Type : "array" ,
267
+ Items : ptr .To (StorageClassConfig {}.VariableSchema ().OpenAPIV3Schema ),
268
+ },
269
+ },
270
+ },
271
+ }
272
+ }
273
+
274
+ func (DefaultStorage ) VariableSchema () clusterv1.VariableSchema {
275
+ supportedCSIProviders := []string {CSIProviderAWSEBS , CSIProviderNutanix }
276
+ return clusterv1.VariableSchema {
277
+ OpenAPIV3Schema : clusterv1.JSONSchemaProps {
278
+ Type : "object" ,
279
+ Description : "A tuple of provider name and storage class " ,
280
+ Required : []string {"providerName" , "storageClassConfigName" },
281
+ Properties : map [string ]clusterv1.JSONSchemaProps {
282
+ "providerName" : {
283
+ Type : "string" ,
284
+ Description : "Name of the CSI Provider for the default storage class" ,
285
+ Enum : variables .MustMarshalValuesToEnumJSON (
286
+ supportedCSIProviders ... ,
287
+ ),
288
+ },
289
+ "storageClassConfigName" : {
290
+ Type : "string" ,
291
+ Description : "Name of storage class config in any of the provider objects" ,
292
+ },
293
+ },
294
+ },
295
+ }
296
+ }
297
+
298
+ func (CSI ) VariableSchema () clusterv1.VariableSchema {
299
+ return clusterv1.VariableSchema {
300
+ OpenAPIV3Schema : clusterv1.JSONSchemaProps {
301
+ Type : "object" ,
302
+ Properties : map [string ]clusterv1.JSONSchemaProps {
303
+ "providers" : {
304
+ Type : "array" ,
305
+ Items : ptr .To (CSIProvider {}.VariableSchema ().OpenAPIV3Schema ),
170
306
},
307
+ "defaultStorage" : DefaultStorage {}.VariableSchema ().OpenAPIV3Schema ,
171
308
},
172
309
},
173
310
}
0 commit comments