Skip to content

Commit daa818e

Browse files
committed
refactor: Use maps for CSI providers and storage classes
This commit switches from arrays to maps for the CSI providers and storage class configurations. This ensures unique naming and therefore prevents name collisions. The infra provider specific cluster configuration now includes specific CSI configuration to ensure only compatible and supported CSI providers are configurable for each infra provider. Finally, this commit changes the final storage class that is created on the workload cluster to be derived from the CSI provider name and storage class config name, e.g. `<provider>-<storageClassConfig>`, once again to avoid name collisions. Using the API in this way reduces the chances of conflicting configurations when a user and provides early feedback when creating the cluster that the configurations incorrect via OpenAPI validation. As an example, this commit updates the cluster configuration from: ``` defaultStorage: providerName: local-path storageClassConfigName: local-path providers: - name: local-path storageClassConfig: - name: local-path strategy: HelmAddon ``` To: ``` defaultStorage: provider: local-path storageClassConfig: default providers: local-path: storageClassConfigs: default: {} strategy: HelmAddon ``` While this may seem like only a small change, a single line removed, it is always good to keep APIs as terse as possible while still retaining strict behaviour. I think this commit achieves that.
1 parent 511785f commit daa818e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1221
-1049
lines changed

api/v1alpha1/addon_types.go

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,28 @@ const (
5858
CCMProviderNutanix = "nutanix"
5959
)
6060

61-
type Addons struct {
61+
type AWSAddons struct {
62+
GenericAddons `json:",inline"`
63+
64+
// +kubebuilder:validation:Optional
65+
CSI *AWSCSI `json:"csi,omitempty"`
66+
}
67+
68+
type DockerAddons struct {
69+
GenericAddons `json:",inline"`
70+
71+
// +kubebuilder:validation:Optional
72+
CSI *DockerCSI `json:"csi,omitempty"`
73+
}
74+
75+
type NutanixAddons struct {
76+
GenericAddons `json:",inline"`
77+
78+
// +kubebuilder:validation:Optional
79+
CSI *NutanixCSI `json:"csi,omitempty"`
80+
}
81+
82+
type GenericAddons struct {
6283
// +kubebuilder:validation:Optional
6384
CNI *CNI `json:"cni,omitempty"`
6485

@@ -71,9 +92,6 @@ type Addons struct {
7192
// +kubebuilder:validation:Optional
7293
CCM *CCM `json:"ccm,omitempty"`
7394

74-
// +kubebuilder:validation:Optional
75-
CSIProviders *CSI `json:"csi,omitempty"`
76-
7795
// +kubebuilder:validation:Optional
7896
ServiceLoadBalancer *ServiceLoadBalancer `json:"serviceLoadBalancer,omitempty"`
7997
}
@@ -109,36 +127,63 @@ type ClusterAutoscaler struct {
109127
Strategy AddonStrategy `json:"strategy"`
110128
}
111129

130+
type GenericCSI struct {
131+
// +kubebuilder:validation:Required
132+
DefaultStorage DefaultStorage `json:"defaultStorage"`
133+
}
134+
112135
type DefaultStorage struct {
113136
// Name of the CSI Provider for the default storage class.
114137
// +kubebuilder:validation:Required
115138
// +kubebuilder:validation:Enum=aws-ebs;nutanix;local-path
116-
ProviderName string `json:"providerName"`
139+
Provider string `json:"provider"`
117140

118-
// Name of storage class config in any of the provider objects.
141+
// Name of the default storage class config the specified default provider.
119142
// +kubebuilder:validation:Required
120143
// +kubebuilder:validation:MinLength=1
121-
StorageClassConfigName string `json:"storageClassConfigName"`
144+
StorageClassConfig string `json:"storageClassConfig"`
145+
}
146+
147+
type AWSCSI struct {
148+
GenericCSI `json:",inline"`
149+
150+
// +kubebuilder:validation:Required
151+
Providers AWSCSIProviders `json:"providers"`
122152
}
123153

124-
type CSI struct {
125-
// +kubebuilder:validation:MinItems=1
154+
type AWSCSIProviders struct {
126155
// +kubebuilder:validation:Required
127-
Providers []CSIProvider `json:"providers"`
156+
AWSEBSCSI CSIProvider `json:"aws-ebs"`
157+
}
158+
159+
type DockerCSI struct {
160+
GenericCSI `json:",inline"`
128161

129162
// +kubebuilder:validation:Required
130-
DefaultStorage DefaultStorage `json:"defaultStorage"`
163+
Providers DockerCSIProviders `json:"providers"`
131164
}
132165

133-
type CSIProvider struct {
134-
// Name of the CSI Provider.
166+
type DockerCSIProviders struct {
135167
// +kubebuilder:validation:Required
136-
// +kubebuilder:validation:Enum=aws-ebs;nutanix;local-path
137-
Name string `json:"name"`
168+
LocalPathCSI CSIProvider `json:"local-path"`
169+
}
138170

139-
// StorageClassConfig is a list of storage class configurations for this CSI provider.
140-
// +kubebuilder:validation:Optional
141-
StorageClassConfig []StorageClassConfig `json:"storageClassConfig"`
171+
type NutanixCSI struct {
172+
GenericCSI `json:",inline"`
173+
174+
// +kubebuilder:validation:Required
175+
Providers NutanixCSIProviders `json:"providers"`
176+
}
177+
178+
type NutanixCSIProviders struct {
179+
// +kubebuilder:validation:Required
180+
NutanixCSI CSIProvider `json:"nutanix"`
181+
}
182+
183+
type CSIProvider struct {
184+
// StorageClassConfigs is a map of storage class configurations for this CSI provider.
185+
// +kubebuilder:validation:Required
186+
StorageClassConfigs map[string]StorageClassConfig `json:"storageClassConfigs"`
142187

143188
// Addon strategy used to deploy the CSI provider to the workload cluster.
144189
// +kubebuilder:validation:Required
@@ -151,11 +196,6 @@ type CSIProvider struct {
151196
}
152197

153198
type StorageClassConfig struct {
154-
// Name of storage class config.
155-
// +kubebuilder:validation:Required
156-
// +kubebuilder:validation:MinLength=1
157-
Name string `json:"name"`
158-
159199
// Parameters passed into the storage class object.
160200
// +kubebuilder:validation:Optional
161201
Parameters map[string]string `json:"parameters,omitempty"`

api/v1alpha1/clusterconfig_types.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ type AWSClusterConfigSpec struct {
7272

7373
GenericClusterConfigSpec `json:",inline"`
7474

75+
// +kubebuilder:validation:Optional
76+
Addons *AWSAddons `json:"addons,omitempty"`
77+
7578
// +kubebuilder:validation:Optional
7679
ControlPlane *AWSControlPlaneNodeConfigSpec `json:"controlPlane,omitempty"`
7780

@@ -104,6 +107,9 @@ type DockerClusterConfigSpec struct {
104107

105108
GenericClusterConfigSpec `json:",inline"`
106109

110+
// +kubebuilder:validation:Optional
111+
Addons *DockerAddons `json:"addons,omitempty"`
112+
107113
// +kubebuilder:validation:Optional
108114
ControlPlane *DockerNodeConfigSpec `json:"controlPlane,omitempty"`
109115

@@ -141,6 +147,9 @@ type NutanixClusterConfigSpec struct {
141147

142148
GenericClusterConfigSpec `json:",inline"`
143149

150+
// +kubebuilder:validation:Optional
151+
Addons *NutanixAddons `json:"addons,omitempty"`
152+
144153
// +kubebuilder:validation:Optional
145154
ControlPlane *NutanixNodeConfigSpec `json:"controlPlane,omitempty"`
146155

@@ -195,9 +204,6 @@ type GenericClusterConfigSpec struct {
195204
// +kubebuilder:validation:Optional
196205
GlobalImageRegistryMirror *GlobalImageRegistryMirror `json:"globalImageRegistryMirror,omitempty"`
197206

198-
// +kubebuilder:validation:Optional
199-
Addons *Addons `json:"addons,omitempty"`
200-
201207
// +kubebuilder:validation:Optional
202208
Users []User `json:"users,omitempty"`
203209

api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml

Lines changed: 65 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -102,93 +102,84 @@ spec:
102102
properties:
103103
defaultStorage:
104104
properties:
105-
providerName:
105+
provider:
106106
description: Name of the CSI Provider for the default storage class.
107107
enum:
108108
- aws-ebs
109109
type: string
110-
storageClassConfigName:
111-
description: Name of storage class config in any of the provider objects.
110+
storageClassConfig:
111+
description: Name of the default storage class config the specified default provider.
112112
minLength: 1
113113
type: string
114114
required:
115-
- providerName
116-
- storageClassConfigName
115+
- provider
116+
- storageClassConfig
117117
type: object
118118
providers:
119-
items:
120-
properties:
121-
credentials:
122-
description: The reference to any secret used by the CSI Provider.
123-
properties:
124-
secretRef:
125-
description: A reference to the Secret containing the credentials used by the CSI provider.
126-
properties:
127-
name:
128-
description: |-
129-
Name of the referent.
130-
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
131-
minLength: 1
132-
type: string
133-
required:
134-
- name
135-
type: object
136-
required:
137-
- secretRef
138-
type: object
139-
name:
140-
description: Name of the CSI Provider.
141-
enum:
142-
- aws-ebs
143-
type: string
144-
storageClassConfig:
145-
description: StorageClassConfig is a list of storage class configurations for this CSI provider.
146-
items:
119+
properties:
120+
aws-ebs:
121+
properties:
122+
credentials:
123+
description: The reference to any secret used by the CSI Provider.
147124
properties:
148-
allowExpansion:
149-
default: false
150-
description: If the storage class should allow volume expanding
151-
type: boolean
152-
name:
153-
description: Name of storage class config.
154-
minLength: 1
155-
type: string
156-
parameters:
157-
additionalProperties:
158-
type: string
159-
description: Parameters passed into the storage class object.
125+
secretRef:
126+
description: A reference to the Secret containing the credentials used by the CSI provider.
127+
properties:
128+
name:
129+
description: |-
130+
Name of the referent.
131+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
132+
minLength: 1
133+
type: string
134+
required:
135+
- name
160136
type: object
161-
reclaimPolicy:
162-
default: Delete
163-
description: PersistentVolumeReclaimPolicy describes a policy for end-of-life maintenance of persistent volumes.
164-
enum:
165-
- Delete
166-
- Retain
167-
- Recycle
168-
type: string
169-
volumeBindingMode:
170-
default: WaitForFirstConsumer
171-
description: VolumeBindingMode indicates how PersistentVolumeClaims should be bound.
172-
enum:
173-
- Immediate
174-
- WaitForFirstConsumer
175-
type: string
176137
required:
177-
- name
138+
- secretRef
178139
type: object
179-
type: array
180-
strategy:
181-
description: Addon strategy used to deploy the CSI provider to the workload cluster.
182-
enum:
183-
- ClusterResourceSet
184-
- HelmAddon
185-
type: string
186-
required:
187-
- name
188-
- strategy
189-
type: object
190-
minItems: 1
191-
type: array
140+
storageClassConfigs:
141+
additionalProperties:
142+
properties:
143+
allowExpansion:
144+
default: false
145+
description: If the storage class should allow volume expanding
146+
type: boolean
147+
parameters:
148+
additionalProperties:
149+
type: string
150+
description: Parameters passed into the storage class object.
151+
type: object
152+
reclaimPolicy:
153+
default: Delete
154+
description: PersistentVolumeReclaimPolicy describes a policy for end-of-life maintenance of persistent volumes.
155+
enum:
156+
- Delete
157+
- Retain
158+
- Recycle
159+
type: string
160+
volumeBindingMode:
161+
default: WaitForFirstConsumer
162+
description: VolumeBindingMode indicates how PersistentVolumeClaims should be bound.
163+
enum:
164+
- Immediate
165+
- WaitForFirstConsumer
166+
type: string
167+
type: object
168+
description: StorageClassConfigs is a map of storage class configurations for this CSI provider.
169+
type: object
170+
strategy:
171+
description: Addon strategy used to deploy the CSI provider to the workload cluster.
172+
enum:
173+
- ClusterResourceSet
174+
- HelmAddon
175+
type: string
176+
required:
177+
- storageClassConfigs
178+
- strategy
179+
type: object
180+
required:
181+
- aws-ebs
182+
type: object
192183
required:
193184
- defaultStorage
194185
- providers

0 commit comments

Comments
 (0)