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

Commit

Permalink
feat: allow volume expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
faiq committed Mar 29, 2024
1 parent 47f16f8 commit 05951a9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
18 changes: 15 additions & 3 deletions api/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ type StorageClassConfig struct {

// +optional
VolumeBindingMode string `json:"volumeBindingMode,omitempty"`

// +optional
AllowExpansion bool `json:"allowExpansion,omitempty"`
}

func (StorageClassConfig) VariableSchema() clusterv1.VariableSchema {
Expand All @@ -192,7 +195,8 @@ func (StorageClassConfig) VariableSchema() clusterv1.VariableSchema {
}
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Type: "object",
Required: []string{"name"},
Properties: map[string]clusterv1.JSONSchemaProps{
"name": {
Type: "string",
Expand All @@ -215,6 +219,11 @@ func (StorageClassConfig) VariableSchema() clusterv1.VariableSchema {
Enum: variables.MustMarshalValuesToEnumJSON(supportedBindingModes...),
Default: variables.MustMarshal(VolumeBindingWaitForFirstConsumer),
},
"allowExpansion": {
Type: "boolean",
Default: variables.MustMarshal(false),
Description: "If the storage class should allow volume expanding",
},
},
},
}
Expand All @@ -224,7 +233,8 @@ func (CSIProvider) VariableSchema() clusterv1.VariableSchema {
supportedCSIProviders := []string{CSIProviderAWSEBS, CSIProviderNutanix}
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Type: "object",
Required: []string{"name", "strategy"},
Properties: map[string]clusterv1.JSONSchemaProps{
"name": {
Description: "Name of the CSI Provider",
Expand Down Expand Up @@ -267,12 +277,14 @@ func (DefaultStorage) VariableSchema() clusterv1.VariableSchema {
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Description: "A tuple of provider name and storage class ",
Required: []string{"providerName", "storageClassConfigName"},
Properties: map[string]clusterv1.JSONSchemaProps{
"providerName": {
Type: "string",
Description: "Name of the CSI Provider for the default storage class",
Enum: variables.MustMarshalValuesToEnumJSON(
supportedCSIProviders...),
supportedCSIProviders...,
),
},
"storageClassConfigName": {
Type: "string",
Expand Down
9 changes: 5 additions & 4 deletions pkg/handlers/generic/lifecycle/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ func CreateStorageClass(
Name: storageConfig.Name,
Namespace: defaultsNamespace,
},
Provisioner: string(provisionerName),
Parameters: params,
VolumeBindingMode: volumeBindingMode,
ReclaimPolicy: reclaimPolicy,
Provisioner: string(provisionerName),
Parameters: params,
VolumeBindingMode: volumeBindingMode,
ReclaimPolicy: reclaimPolicy,
AllowVolumeExpansion: ptr.To(storageConfig.AllowExpansion),
}
if isDefault {
sc.ObjectMeta.Annotations = defaultStorageClassMap
Expand Down
24 changes: 14 additions & 10 deletions pkg/handlers/generic/lifecycle/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestCreateStorageClass(t *testing.T) {
ReclaimPolicy: v1alpha1.VolumeReclaimDelete,
VolumeBindingMode: v1alpha1.VolumeBindingWaitForFirstConsumer,
Parameters: nil,
AllowExpansion: true,
},
expectedStorageClass: &storagev1.StorageClass{
TypeMeta: metav1.TypeMeta{
Expand All @@ -42,10 +43,11 @@ func TestCreateStorageClass(t *testing.T) {
Name: "aws-ebs",
Namespace: "default",
},
Parameters: defaultAWSStorageClassParams,
ReclaimPolicy: ptr.To(corev1.PersistentVolumeReclaimDelete),
VolumeBindingMode: ptr.To(storagev1.VolumeBindingWaitForFirstConsumer),
Provisioner: string(v1alpha1.AWSEBSProvisioner),
Parameters: defaultAWSStorageClassParams,
ReclaimPolicy: ptr.To(corev1.PersistentVolumeReclaimDelete),
VolumeBindingMode: ptr.To(storagev1.VolumeBindingWaitForFirstConsumer),
Provisioner: string(v1alpha1.AWSEBSProvisioner),
AllowVolumeExpansion: ptr.To(true),
},
provisioner: v1alpha1.AWSEBSProvisioner,
defaultsNamespace: "default",
Expand Down Expand Up @@ -84,9 +86,10 @@ func TestCreateStorageClass(t *testing.T) {
"whitelistIPMode": "ENABLED",
"whitelistIPAddr": "1.1.1.1",
},
ReclaimPolicy: ptr.To(corev1.PersistentVolumeReclaimDelete),
VolumeBindingMode: ptr.To(storagev1.VolumeBindingWaitForFirstConsumer),
Provisioner: string(v1alpha1.NutanixProvisioner),
ReclaimPolicy: ptr.To(corev1.PersistentVolumeReclaimDelete),
VolumeBindingMode: ptr.To(storagev1.VolumeBindingWaitForFirstConsumer),
Provisioner: string(v1alpha1.NutanixProvisioner),
AllowVolumeExpansion: ptr.To(false),
},
provisioner: v1alpha1.NutanixProvisioner,
defaultsNamespace: "default",
Expand All @@ -107,9 +110,10 @@ func TestCreateStorageClass(t *testing.T) {
Name: "nutanix-volumes",
Namespace: "default",
},
ReclaimPolicy: ptr.To(corev1.PersistentVolumeReclaimDelete),
VolumeBindingMode: ptr.To(storagev1.VolumeBindingWaitForFirstConsumer),
Provisioner: string(v1alpha1.NutanixProvisioner),
ReclaimPolicy: ptr.To(corev1.PersistentVolumeReclaimDelete),
VolumeBindingMode: ptr.To(storagev1.VolumeBindingWaitForFirstConsumer),
Provisioner: string(v1alpha1.NutanixProvisioner),
AllowVolumeExpansion: ptr.To(false),
},
provisioner: v1alpha1.NutanixProvisioner,
defaultsNamespace: "default",
Expand Down

0 comments on commit 05951a9

Please sign in to comment.