Skip to content

Commit

Permalink
stateful deployments: add Sticky property to task group volumes (#24641)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkazmierczak authored and tgross committed Dec 19, 2024
1 parent 3143019 commit 258b159
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
30 changes: 21 additions & 9 deletions nomad/structs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

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

func TestJobDiff(t *testing.T) {
Expand Down Expand Up @@ -4864,6 +4864,12 @@ func TestTaskGroupDiff(t *testing.T) {
Old: "",
New: "foo-src",
},
{
Type: DiffTypeAdded,
Name: "Sticky",
Old: "",
New: "false",
},
{
Type: DiffTypeAdded,
Name: "Type",
Expand Down Expand Up @@ -5475,17 +5481,17 @@ func TestTaskGroupDiff(t *testing.T) {
}

for i, c := range cases {
require.NotEmpty(t, c.TestCase, "case #%d needs a name", i+1)
must.NotEq(t, c.TestCase, "", must.Sprintf("case #%d needs a name", i+1))

t.Run(c.TestCase, func(t *testing.T) {

result, err := c.Old.Diff(c.New, c.Contextual)
switch c.ExpErr {
case true:
require.Error(t, err, "case %q expected error", c.TestCase)
must.Error(t, err, must.Sprintf("case %q expected error", c.TestCase))
case false:
require.NoError(t, err, "case %q expected no error", c.TestCase)
require.Equal(t, c.Expected, result)
must.NoError(t, err, must.Sprintf("case %q expected no error", c.TestCase))
must.Eq(t, c.Expected, result)
}
})
}
Expand Down Expand Up @@ -8370,6 +8376,12 @@ func TestTaskDiff(t *testing.T) {
Old: "",
New: "Z",
},
{
Type: DiffTypeAdded,
Name: "Sticky",
Old: "",
New: "false",
},
{
Type: DiffTypeAdded,
Name: "Volume",
Expand Down Expand Up @@ -9870,10 +9882,10 @@ func TestTaskDiff(t *testing.T) {
t.Run(c.Name, func(t *testing.T) {
actual, err := c.Old.Diff(c.New, c.Contextual)
if c.Error {
require.Error(t, err)
must.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, c.Expected, actual)
must.NoError(t, err)
must.Eq(t, c.Expected, actual)
}
})
}
Expand Down Expand Up @@ -10848,7 +10860,7 @@ func TestServicesDiff(t *testing.T) {
for _, c := range cases {
t.Run(c.Name, func(t *testing.T) {
actual := serviceDiffs(c.Old, c.New, c.Contextual)
require.Equal(t, c.Expected, actual)
must.Eq(t, c.Expected, actual)
})
}
}
9 changes: 8 additions & 1 deletion nomad/structs/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,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 @@ -128,6 +130,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 Down Expand Up @@ -259,6 +263,7 @@ type VolumeMount struct {
Volume string
Destination string
ReadOnly bool
Sticky bool
PropagationMode string
SELinuxLabel string
}
Expand All @@ -279,6 +284,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
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 @@ -92,7 +91,7 @@ func TestVolumeRequest_Validate(t *testing.T) {
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 258b159

Please sign in to comment.