Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 2ec54be

Browse files
authored
Merge pull request #7 from d2iq-labs/faiq/add-nutanix-csi
feat: add nutanix csi
2 parents 9cad889 + 7665a94 commit 2ec54be

33 files changed

+1641
-250
lines changed

api/v1alpha1/addon_types.go

Lines changed: 163 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@
44
package v1alpha1
55

66
import (
7+
corev1 "k8s.io/api/core/v1"
8+
storagev1 "k8s.io/api/storage/v1"
9+
"k8s.io/utils/ptr"
710
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
811

912
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/variables"
1013
)
1114

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+
1226
type Addons struct {
1327
// +optional
1428
CNI *CNI `json:"cni,omitempty"`
@@ -23,7 +37,7 @@ type Addons struct {
2337
CCM *CCM `json:"ccm,omitempty"`
2438

2539
// +optional
26-
CSIProviders *CSIProviders `json:"csi,omitempty"`
40+
CSIProviders *CSI `json:"csi,omitempty"`
2741
}
2842

2943
func (Addons) VariableSchema() clusterv1.VariableSchema {
@@ -35,7 +49,7 @@ func (Addons) VariableSchema() clusterv1.VariableSchema {
3549
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
3650
"nfd": NFD{}.VariableSchema().OpenAPIV3Schema,
3751
"clusterAutoscaler": ClusterAutoscaler{}.VariableSchema().OpenAPIV3Schema,
38-
"csi": CSIProviders{}.VariableSchema().OpenAPIV3Schema,
52+
"csi": CSI{}.VariableSchema().OpenAPIV3Schema,
3953
"ccm": CCM{}.VariableSchema().OpenAPIV3Schema,
4054
},
4155
},
@@ -44,11 +58,6 @@ func (Addons) VariableSchema() clusterv1.VariableSchema {
4458

4559
type AddonStrategy string
4660

47-
const (
48-
AddonStrategyClusterResourceSet AddonStrategy = "ClusterResourceSet"
49-
AddonStrategyHelmAddon AddonStrategy = "HelmAddon"
50-
)
51-
5261
// CNI required for providing CNI configuration.
5362
type CNI struct {
5463
// +optional
@@ -134,40 +143,168 @@ func (ClusterAutoscaler) VariableSchema() clusterv1.VariableSchema {
134143
}
135144
}
136145

137-
type CSIProviders struct {
146+
type DefaultStorage struct {
147+
ProviderName string `json:"providerName"`
148+
StorageClassConfigName string `json:"storageClassConfigName"`
149+
}
150+
151+
type CSI struct {
138152
// +optional
139153
Providers []CSIProvider `json:"providers,omitempty"`
140154
// +optional
141-
DefaultClassName string `json:"defaultClassName,omitempty"`
155+
DefaultStorage *DefaultStorage `json:"defaultStorage,omitempty"`
142156
}
143157

144158
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"`
146168
}
147169

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+
}
150196
return clusterv1.VariableSchema{
151197
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
152-
Type: "object",
198+
Type: "object",
199+
Required: []string{"name"},
153200
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",
164262
},
165263
},
166264
},
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),
170306
},
307+
"defaultStorage": DefaultStorage{}.VariableSchema().OpenAPIV3Schema,
171308
},
172309
},
173310
}

api/v1alpha1/clusterconfig_types.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ import (
1414
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/openapi/patterns"
1515
)
1616

17+
type StorageProvisioner string
18+
1719
const (
18-
CNIProviderCalico = "Calico"
19-
CNIProviderCilium = "Cilium"
20+
CNIProviderCalico = "Calico"
21+
CNIProviderCilium = "Cilium"
22+
AWSEBSProvisioner StorageProvisioner = "ebs.csi.aws.com"
23+
NutanixProvisioner StorageProvisioner = "csi.nutanix.com"
2024

21-
CSIProviderAWSEBS = "aws-ebs"
25+
CSIProviderAWSEBS = "aws-ebs"
26+
CSIProviderNutanix = "nutanix"
2227

2328
CCMProviderAWS = "aws"
2429
)

0 commit comments

Comments
 (0)