Skip to content

refactor: Use maps for CSI providers and storage classes #696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 63 additions & 23 deletions api/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,28 @@ const (
CCMProviderNutanix = "nutanix"
)

type Addons struct {
type AWSAddons struct {
GenericAddons `json:",inline"`

// +kubebuilder:validation:Optional
CSI *AWSCSI `json:"csi,omitempty"`
}

type DockerAddons struct {
GenericAddons `json:",inline"`

// +kubebuilder:validation:Optional
CSI *DockerCSI `json:"csi,omitempty"`
}

type NutanixAddons struct {
GenericAddons `json:",inline"`

// +kubebuilder:validation:Optional
CSI *NutanixCSI `json:"csi,omitempty"`
}

type GenericAddons struct {
// +kubebuilder:validation:Optional
CNI *CNI `json:"cni,omitempty"`

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

// +kubebuilder:validation:Optional
CSIProviders *CSI `json:"csi,omitempty"`

// +kubebuilder:validation:Optional
ServiceLoadBalancer *ServiceLoadBalancer `json:"serviceLoadBalancer,omitempty"`
}
Expand Down Expand Up @@ -109,36 +127,63 @@ type ClusterAutoscaler struct {
Strategy AddonStrategy `json:"strategy"`
}

type GenericCSI struct {
// +kubebuilder:validation:Required
DefaultStorage DefaultStorage `json:"defaultStorage"`
}

type DefaultStorage struct {
// Name of the CSI Provider for the default storage class.
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=aws-ebs;nutanix;local-path
ProviderName string `json:"providerName"`
Provider string `json:"provider"`

// Name of storage class config in any of the provider objects.
// Name of the default storage class config the specified default provider.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
StorageClassConfigName string `json:"storageClassConfigName"`
StorageClassConfig string `json:"storageClassConfig"`
}

type AWSCSI struct {
GenericCSI `json:",inline"`

// +kubebuilder:validation:Required
Providers AWSCSIProviders `json:"providers"`
}

type CSI struct {
// +kubebuilder:validation:MinItems=1
type AWSCSIProviders struct {
// +kubebuilder:validation:Required
Providers []CSIProvider `json:"providers"`
AWSEBSCSI CSIProvider `json:"aws-ebs"`
}

type DockerCSI struct {
GenericCSI `json:",inline"`

// +kubebuilder:validation:Required
DefaultStorage DefaultStorage `json:"defaultStorage"`
Providers DockerCSIProviders `json:"providers"`
}

type CSIProvider struct {
// Name of the CSI Provider.
type DockerCSIProviders struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=aws-ebs;nutanix;local-path
Name string `json:"name"`
LocalPathCSI CSIProvider `json:"local-path"`
}

// StorageClassConfig is a list of storage class configurations for this CSI provider.
// +kubebuilder:validation:Optional
StorageClassConfig []StorageClassConfig `json:"storageClassConfig"`
type NutanixCSI struct {
GenericCSI `json:",inline"`

// +kubebuilder:validation:Required
Providers NutanixCSIProviders `json:"providers"`
}

type NutanixCSIProviders struct {
// +kubebuilder:validation:Required
NutanixCSI CSIProvider `json:"nutanix"`
}

type CSIProvider struct {
// StorageClassConfigs is a map of storage class configurations for this CSI provider.
// +kubebuilder:validation:Required
StorageClassConfigs map[string]StorageClassConfig `json:"storageClassConfigs"`

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

type StorageClassConfig struct {
// Name of storage class config.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`

// Parameters passed into the storage class object.
// +kubebuilder:validation:Optional
Parameters map[string]string `json:"parameters,omitempty"`
Expand Down
12 changes: 9 additions & 3 deletions api/v1alpha1/clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ type AWSClusterConfigSpec struct {

GenericClusterConfigSpec `json:",inline"`

// +kubebuilder:validation:Optional
Addons *AWSAddons `json:"addons,omitempty"`

// +kubebuilder:validation:Optional
ControlPlane *AWSControlPlaneNodeConfigSpec `json:"controlPlane,omitempty"`

Expand Down Expand Up @@ -104,6 +107,9 @@ type DockerClusterConfigSpec struct {

GenericClusterConfigSpec `json:",inline"`

// +kubebuilder:validation:Optional
Addons *DockerAddons `json:"addons,omitempty"`

// +kubebuilder:validation:Optional
ControlPlane *DockerNodeConfigSpec `json:"controlPlane,omitempty"`

Expand Down Expand Up @@ -141,6 +147,9 @@ type NutanixClusterConfigSpec struct {

GenericClusterConfigSpec `json:",inline"`

// +kubebuilder:validation:Optional
Addons *NutanixAddons `json:"addons,omitempty"`

// +kubebuilder:validation:Optional
ControlPlane *NutanixNodeConfigSpec `json:"controlPlane,omitempty"`

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

// +kubebuilder:validation:Optional
Addons *Addons `json:"addons,omitempty"`

// +kubebuilder:validation:Optional
Users []User `json:"users,omitempty"`

Expand Down
139 changes: 65 additions & 74 deletions api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,93 +102,84 @@ spec:
properties:
defaultStorage:
properties:
providerName:
provider:
description: Name of the CSI Provider for the default storage class.
enum:
- aws-ebs
type: string
storageClassConfigName:
description: Name of storage class config in any of the provider objects.
storageClassConfig:
description: Name of the default storage class config the specified default provider.
minLength: 1
type: string
required:
- providerName
- storageClassConfigName
- provider
- storageClassConfig
type: object
providers:
items:
properties:
credentials:
description: The reference to any secret used by the CSI Provider.
properties:
secretRef:
description: A reference to the Secret containing the credentials used by the CSI provider.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
minLength: 1
type: string
required:
- name
type: object
required:
- secretRef
type: object
name:
description: Name of the CSI Provider.
enum:
- aws-ebs
type: string
storageClassConfig:
description: StorageClassConfig is a list of storage class configurations for this CSI provider.
items:
properties:
aws-ebs:
properties:
credentials:
description: The reference to any secret used by the CSI Provider.
properties:
allowExpansion:
default: false
description: If the storage class should allow volume expanding
type: boolean
name:
description: Name of storage class config.
minLength: 1
type: string
parameters:
additionalProperties:
type: string
description: Parameters passed into the storage class object.
secretRef:
description: A reference to the Secret containing the credentials used by the CSI provider.
properties:
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
minLength: 1
type: string
required:
- name
type: object
reclaimPolicy:
default: Delete
description: PersistentVolumeReclaimPolicy describes a policy for end-of-life maintenance of persistent volumes.
enum:
- Delete
- Retain
- Recycle
type: string
volumeBindingMode:
default: WaitForFirstConsumer
description: VolumeBindingMode indicates how PersistentVolumeClaims should be bound.
enum:
- Immediate
- WaitForFirstConsumer
type: string
required:
- name
- secretRef
type: object
type: array
strategy:
description: Addon strategy used to deploy the CSI provider to the workload cluster.
enum:
- ClusterResourceSet
- HelmAddon
type: string
required:
- name
- strategy
type: object
minItems: 1
type: array
storageClassConfigs:
additionalProperties:
properties:
allowExpansion:
default: false
description: If the storage class should allow volume expanding
type: boolean
parameters:
additionalProperties:
type: string
description: Parameters passed into the storage class object.
type: object
reclaimPolicy:
default: Delete
description: PersistentVolumeReclaimPolicy describes a policy for end-of-life maintenance of persistent volumes.
enum:
- Delete
- Retain
- Recycle
type: string
volumeBindingMode:
default: WaitForFirstConsumer
description: VolumeBindingMode indicates how PersistentVolumeClaims should be bound.
enum:
- Immediate
- WaitForFirstConsumer
type: string
type: object
description: StorageClassConfigs is a map of storage class configurations for this CSI provider.
type: object
strategy:
description: Addon strategy used to deploy the CSI provider to the workload cluster.
enum:
- ClusterResourceSet
- HelmAddon
type: string
required:
- storageClassConfigs
- strategy
type: object
required:
- aws-ebs
type: object
required:
- defaultStorage
- providers
Expand Down
Loading
Loading