mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
Correctly canonicalize lifecycle block when missing hook value (#26285)
This commit is contained in:
3
.changelog/26285.txt
Normal file
3
.changelog/26285.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
jobspec: Validate required hook field in lifecycle block
|
||||||
|
```
|
||||||
@@ -747,13 +747,13 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TaskLifecycle struct {
|
type TaskLifecycle struct {
|
||||||
Hook string `mapstructure:"hook" hcl:"hook,optional"`
|
Hook string `mapstructure:"hook" hcl:"hook"`
|
||||||
Sidecar bool `mapstructure:"sidecar" hcl:"sidecar,optional"`
|
Sidecar bool `mapstructure:"sidecar" hcl:"sidecar,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if lifecycle has user-input values
|
// Determine if lifecycle has user-input values
|
||||||
func (l *TaskLifecycle) Empty() bool {
|
func (l *TaskLifecycle) Empty() bool {
|
||||||
return l == nil || (l.Hook == "")
|
return l == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task is a single process in a task group.
|
// Task is a single process in a task group.
|
||||||
|
|||||||
@@ -344,10 +344,36 @@ func TestTask_Canonicalize_TaskLifecycle(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "empty",
|
name: "empty",
|
||||||
task: &Task{
|
task: &Task{
|
||||||
Lifecycle: &TaskLifecycle{},
|
Lifecycle: nil,
|
||||||
},
|
},
|
||||||
expected: nil,
|
expected: nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "missing hook",
|
||||||
|
task: &Task{
|
||||||
|
Lifecycle: &TaskLifecycle{},
|
||||||
|
},
|
||||||
|
expected: &TaskLifecycle{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with sidecar",
|
||||||
|
task: &Task{
|
||||||
|
Lifecycle: &TaskLifecycle{
|
||||||
|
Sidecar: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &TaskLifecycle{Sidecar: true},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "valid",
|
||||||
|
task: &Task{
|
||||||
|
Lifecycle: &TaskLifecycle{
|
||||||
|
Hook: "prestart",
|
||||||
|
Sidecar: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &TaskLifecycle{Hook: "prestart", Sidecar: true},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|||||||
Reference in New Issue
Block a user