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 479b4f6 commit 27afec8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

IMPROVEMENTS:
* cli: Cross-namespace `nomad job` commands will now select exact matches if the selection is unambiguous. [[GH-10648](https://github.com/hashicorp/nomad/issues/10648)]
* csi: Validate that `volume` blocks for CSI volumes include the required `attachment_mode` and `access_mode` fields. [[GH-10651](https://github.com/hashicorp/nomad/issues/10651)]

BUG FIXES:
* api: Fixed event stream connection initialization when there are no events to send [[GH-10637](https://github.com/hashicorp/nomad/issues/10637)]
Expand Down
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 27afec8

Please sign in to comment.