Skip to content

Commit

Permalink
csi: validate volume block has attachment_mode and access_mode
Browse files Browse the repository at this point in the history
The `attachment_mode` and `access_mode` fields are required for CSI
volumes. The `mount_options` block is only allowed for CSI volumes.
  • Loading branch information
tgross committed May 24, 2021
1 parent 9135b42 commit 0f90bb4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nomad/structs/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ func (v *VolumeRequest) Validate(canaries int) error {
mErr.Errors = append(mErr.Errors,
fmt.Errorf("host volumes cannot have an access mode"))
}
if v.Type == VolumeTypeHost && v.MountOptions != nil {
mErr.Errors = append(mErr.Errors,
fmt.Errorf("host volumes cannot have mount options"))
}
if v.Type == VolumeTypeCSI && v.AttachmentMode == CSIVolumeAttachmentModeUnknown {
mErr.Errors = append(mErr.Errors,
fmt.Errorf("CSI volumes must have an attachment mode"))
}
if v.Type == VolumeTypeCSI && v.AccessMode == CSIVolumeAccessModeUnknown {
mErr.Errors = append(mErr.Errors,
fmt.Errorf("CSI volumes must have an access mode"))
}

if v.AccessMode == CSIVolumeAccessModeSingleNodeReader || v.AccessMode == CSIVolumeAccessModeMultiNodeReader {
if !v.ReadOnly {
Expand Down

0 comments on commit 0f90bb4

Please sign in to comment.