Skip to content

Commit

Permalink
Merge pull request #349 from jeff-roche/lvm-ext4
Browse files Browse the repository at this point in the history
OCPVE-300: fix: added validation around fstype
  • Loading branch information
jeff-roche authored May 25, 2023
2 parents 9376f90 + 58056ca commit 0c57987
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/lvmcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ type DeviceClass struct {
Default bool `json:"default,omitempty"`

// FilesystemType sets the filesystem the device should use
// +kubebuilder:validation:Enum=xfs;ext4;""
// +kubebuilder:default=xfs
// +optional
FilesystemType DeviceFilesystemType `json:"fstype,omitempty"`
}
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/lvmcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (l *LVMCluster) ValidateCreate() error {
return err
}

err = l.verifyFstype()
if err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -95,6 +100,11 @@ func (l *LVMCluster) ValidateUpdate(old runtime.Object) error {
return err
}

err = l.verifyFstype()
if err != nil {
return err
}

oldLVMCluster, ok := old.(*LVMCluster)
if !ok {
return fmt.Errorf("Failed to parse LVMCluster.")
Expand Down Expand Up @@ -294,3 +304,13 @@ func (l *LVMCluster) getThinPoolsConfigOfDeviceClass(deviceClassName string) (*T

return nil, ErrDeviceClassNotFound
}

func (l *LVMCluster) verifyFstype() error {
for _, deviceClass := range l.Spec.Storage.DeviceClasses {
if deviceClass.FilesystemType != FilesystemTypeExt4 && deviceClass.FilesystemType != FilesystemTypeXFS {
return fmt.Errorf("fstype '%s' is not a supported filesystem type", deviceClass.FilesystemType)
}
}

return nil
}
5 changes: 5 additions & 0 deletions bundle/manifests/lvm.topolvm.io_lvmclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ spec:
type: array
type: object
fstype:
default: xfs
description: FilesystemType sets the filesystem the device
should use
enum:
- xfs
- ext4
- ""
type: string
name:
description: 'Name of the class, the VG and possibly the
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/lvm.topolvm.io_lvmclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ spec:
type: array
type: object
fstype:
default: xfs
description: FilesystemType sets the filesystem the device
should use
enum:
- xfs
- ext4
- ""
type: string
name:
description: 'Name of the class, the VG and possibly the
Expand Down

0 comments on commit 0c57987

Please sign in to comment.