Skip to content

Commit

Permalink
VolumeRequest and VolumeMount update
Browse files Browse the repository at this point in the history
  • Loading branch information
pkazmierczak committed Dec 3, 2024
1 parent 49428c3 commit b821b3e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
8 changes: 0 additions & 8 deletions api/host_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ type HostVolume struct {
// created. We record this to make debugging easier.
HostPath string `mapstructure:"host_path" hcl:"host_path"`

// Sticky property specifies whether the scheduler should treat this volume
// as assigned to a particular allocation. If marked sticky, the ID of this
// volume will be added to an allocation that uses it during scheduling,
// and every time that allocation gets rescheduled it will only be on a
// node that has this Volume ID present, thus allowing stateful
// deployments.
Sticky bool

// State represents the overall state of the volume. One of pending, ready,
// deleted.
State HostVolumeState
Expand Down
8 changes: 0 additions & 8 deletions nomad/structs/host_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ type HostVolume struct {
// created. We record this to make debugging easier.
HostPath string

// Sticky property specifies whether the scheduler should treat this volume
// as assigned to a particular allocation. If marked sticky, the ID of this
// volume will be added to an allocation that uses it during scheduling,
// and every time that allocation gets rescheduled it will only be on a
// node that has this Volume ID present, thus allowing stateful
// deployments.
Sticky bool

// State represents the overall state of the volume. One of pending, ready,
// deleted.
State HostVolumeState
Expand Down
15 changes: 12 additions & 3 deletions nomad/structs/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ func HostVolumeSliceMerge(a, b []*ClientHostVolumeConfig) []*ClientHostVolumeCon
return n
}

// VolumeRequest is a representation of a storage volume that a TaskGroup wishes to use.
// VolumeRequest is a representation of a storage volume that a TaskGroup wishes
// to use.
type VolumeRequest struct {
Name string
Type string
Source string
ReadOnly bool
Sticky bool
AccessMode CSIVolumeAccessMode
AttachmentMode CSIVolumeAttachmentMode
MountOptions *CSIMountOptions
Expand All @@ -116,6 +118,8 @@ func (v *VolumeRequest) Equal(o *VolumeRequest) bool {
return false
case v.ReadOnly != o.ReadOnly:
return false
case v.Sticky != o.Sticky:
return false
case v.AccessMode != o.AccessMode:
return false
case v.AttachmentMode != o.AttachmentMode:
Expand All @@ -129,8 +133,7 @@ func (v *VolumeRequest) Equal(o *VolumeRequest) bool {
}

func (v *VolumeRequest) Validate(jobType string, taskGroupCount, canaries int) error {
if !(v.Type == VolumeTypeHost ||
v.Type == VolumeTypeCSI) {
if !(v.Type == VolumeTypeHost || v.Type == VolumeTypeCSI) {
return fmt.Errorf("volume has unrecognized type %s", v.Type)
}

Expand Down Expand Up @@ -165,6 +168,9 @@ func (v *VolumeRequest) Validate(jobType string, taskGroupCount, canaries int) e
}

case VolumeTypeCSI:
if v.Sticky {
addErr("CSI volumes cannot be set to sticky")
}

switch v.AttachmentMode {
case CSIVolumeAttachmentModeUnknown:
Expand Down Expand Up @@ -247,6 +253,7 @@ type VolumeMount struct {
Volume string
Destination string
ReadOnly bool
Sticky bool
PropagationMode string
SELinuxLabel string
}
Expand All @@ -267,6 +274,8 @@ func (v *VolumeMount) Equal(o *VolumeMount) bool {
return false
case v.ReadOnly != o.ReadOnly:
return false
case v.Sticky != o.Sticky:
return false
case v.PropagationMode != o.PropagationMode:
return false
case v.SELinuxLabel != o.SELinuxLabel:
Expand Down
16 changes: 14 additions & 2 deletions nomad/structs/volume_test.go → nomad/structs/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/hashicorp/nomad/ci"
"github.com/shoenig/test/must"
"github.com/stretchr/testify/require"
)

func TestVolumeRequest_Validate(t *testing.T) {
Expand Down Expand Up @@ -86,13 +85,26 @@ func TestVolumeRequest_Validate(t *testing.T) {
PerAlloc: true,
},
},
{
name: "Sticky CSI",
expected: []string{
"CSI volumes cannot be set to sticky",
},
req: &VolumeRequest{
Source: "source",
Type: VolumeTypeCSI,
Sticky: true,
AttachmentMode: CSIVolumeAttachmentModeBlockDevice,
AccessMode: CSIVolumeAccessModeMultiNodeMultiWriter,
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := tc.req.Validate(JobTypeSystem, tc.taskGroupCount, tc.canariesCount)
for _, expected := range tc.expected {
require.Contains(t, err.Error(), expected)
must.StrContains(t, err.Error(), expected)
}
})
}
Expand Down

0 comments on commit b821b3e

Please sign in to comment.