Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion levant/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (l *levantDeployment) deploy() (success bool) {

// If the service job doesn't have an update stanza, the job will not use
// Nomad deployments.
if l.config.Template.Job.Update == nil {
if !l.hasUpdateStanza() {
log.Info().Msg("levant/deploy: job is not configured with update stanza, consider adding to use deployments")
return l.jobStatusChecker(&eval.EvalID)
}
Expand Down Expand Up @@ -519,3 +519,23 @@ func (l *levantDeployment) isJobZeroCount() bool {
}
return true
}

// hasUpdateStanza checks if the job has an update stanza at the job level or for all task groups
func (l *levantDeployment) hasUpdateStanza() (hasUpdate bool) {
if l.config.Template.Job.Update != nil {
hasUpdate = true
return
}

// Check if all task groups have an update stanza
if l.config.Template.Job.TaskGroups != nil {
hasUpdate = true
for _, taskGroup := range l.config.Template.Job.TaskGroups {
if taskGroup.Update == nil {
hasUpdate = false
return
}
}
}
return
}
38 changes: 38 additions & 0 deletions levant/deploy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package levant

import (
"testing"

"github.com/hashicorp/levant/levant/structs"
nomad "github.com/hashicorp/nomad/api"
)

func TestHasUpdateStanza(t *testing.T) {
ld1 := levantDeployment{config: &DeployConfig{Template: &structs.TemplateConfig{Job: &nomad.Job{
Update: nil}}}}
ld2 := levantDeployment{config: &DeployConfig{Template: &structs.TemplateConfig{Job: &nomad.Job{
Update: &nomad.UpdateStrategy{}}}}}
ld3 := levantDeployment{config: &DeployConfig{Template: &structs.TemplateConfig{Job: &nomad.Job{
Update: nil, TaskGroups: []*nomad.TaskGroup{{Update: nil}}}}}}
ld4 := levantDeployment{config: &DeployConfig{Template: &structs.TemplateConfig{Job: &nomad.Job{
Update: nil, TaskGroups: []*nomad.TaskGroup{{Update: &nomad.UpdateStrategy{}}}}}}}
ld5 := levantDeployment{config: &DeployConfig{Template: &structs.TemplateConfig{Job: &nomad.Job{
Update: nil, TaskGroups: []*nomad.TaskGroup{{Update: nil}, {Update: &nomad.UpdateStrategy{}}}}}}}

cases := []struct {
ld levantDeployment
expectedTrue bool
}{
{ld1, false},
{ld2, true},
{ld3, false},
{ld4, true},
{ld5, false},
}

for _, c := range cases {
if c.ld.hasUpdateStanza() != c.expectedTrue {
t.Fatalf("expected hasUpdate to be %t, but got %t", c.ld.hasUpdateStanza(), c.expectedTrue)
}
}
}