diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index e4a60fa37b3..8ad0bc9aa34 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1271,6 +1271,11 @@ func (j *Job) Validate() error { } if j.IsConstructor() { + if j.Type != JobTypeBatch { + mErr.Errors = append(mErr.Errors, + fmt.Errorf("Constructor job can only be used with %q scheduler", JobTypeBatch)) + } + if err := j.Constructor.Validate(); err != nil { mErr.Errors = append(mErr.Errors, err) } diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 7a9ea05ff7e..78638d69b07 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -1445,7 +1445,7 @@ func TestVault_Validate(t *testing.T) { } } -func TestDispatchConfig_Validate(t *testing.T) { +func TestConstructorConfig_Validate(t *testing.T) { d := &ConstructorConfig{ Payload: "foo", } @@ -1463,7 +1463,19 @@ func TestDispatchConfig_Validate(t *testing.T) { } } -func TestDispatchConfig_Canonicalize(t *testing.T) { +func TestConstructorConfig_Validate_NonBatch(t *testing.T) { + job := testJob() + job.Constructor = &ConstructorConfig{ + Payload: DispatchPayloadOptional, + } + job.Type = JobTypeSystem + + if err := job.Validate(); err == nil || !strings.Contains(err.Error(), "only be used with") { + t.Fatalf("Expected bad scheduler tpye: %v", err) + } +} + +func TestConstructorConfig_Canonicalize(t *testing.T) { d := &ConstructorConfig{} d.Canonicalize() if d.Payload != DispatchPayloadOptional {