From 6ea52e4534d45d6910b235d352d7ff93d502a398 Mon Sep 17 00:00:00 2001 From: Piotr Kazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:20:09 +0100 Subject: [PATCH] stateful deployments: validate there are no sticky per_alloc volume requests (#24714) This changeset adds an additional validation that prevents users from setting per_alloc and sticky flags on volume requests. Ref: #24479 --- nomad/structs/volumes.go | 3 +++ nomad/structs/volumes_test.go | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/nomad/structs/volumes.go b/nomad/structs/volumes.go index 58c4eefacd3..f474fe1d28e 100644 --- a/nomad/structs/volumes.go +++ b/nomad/structs/volumes.go @@ -165,6 +165,9 @@ func (v *VolumeRequest) Validate(jobType string, taskGroupCount, canaries int) e if canaries > 0 { addErr("volume cannot be per_alloc when canaries are in use") } + if v.Sticky { + addErr("volume cannot be per_alloc and sticky at the same time") + } } switch v.Type { diff --git a/nomad/structs/volumes_test.go b/nomad/structs/volumes_test.go index 9b697faf18c..fb5a1a04d64 100644 --- a/nomad/structs/volumes_test.go +++ b/nomad/structs/volumes_test.go @@ -85,6 +85,17 @@ func TestVolumeRequest_Validate(t *testing.T) { PerAlloc: true, }, }, + { + name: "per_alloc sticky", + expected: []string{ + "volume cannot be per_alloc and sticky at the same time", + }, + req: &VolumeRequest{ + Type: VolumeTypeCSI, + PerAlloc: true, + Sticky: true, + }, + }, } for _, tc := range testCases {