2015-09-15 00:43:42 +00:00
|
|
|
package jobspec
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
2015-09-23 20:44:08 +00:00
|
|
|
"strings"
|
2015-09-15 00:43:42 +00:00
|
|
|
"testing"
|
2015-09-20 21:18:10 +00:00
|
|
|
"time"
|
2015-09-15 00:43:42 +00:00
|
|
|
|
2018-12-06 23:09:26 +00:00
|
|
|
capi "github.com/hashicorp/consul/api"
|
2017-02-22 20:30:05 +00:00
|
|
|
"github.com/hashicorp/nomad/api"
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2021-05-07 16:10:26 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2015-09-15 00:43:42 +00:00
|
|
|
)
|
|
|
|
|
2020-09-03 11:34:04 +00:00
|
|
|
// consts copied from nomad/structs package to keep jobspec isolated from rest of nomad
|
|
|
|
const (
|
|
|
|
// vaultChangeModeRestart restarts the task when a new token is retrieved.
|
|
|
|
vaultChangeModeRestart = "restart"
|
|
|
|
|
|
|
|
// vaultChangeModeSignal signals the task when a new token is retrieved.
|
|
|
|
vaultChangeModeSignal = "signal"
|
|
|
|
|
|
|
|
// templateChangeModeRestart marks that the task should be restarted if the
|
|
|
|
templateChangeModeRestart = "restart"
|
2022-08-24 15:43:01 +00:00
|
|
|
|
|
|
|
// templateChangeModeScript marks that ac script should be executed on
|
|
|
|
// template re-render
|
|
|
|
templateChangeModeScript = "script"
|
2020-09-03 11:34:04 +00:00
|
|
|
)
|
|
|
|
|
2022-08-02 20:15:38 +00:00
|
|
|
// Helper functions below are only used by this test suite
|
|
|
|
func int8ToPtr(i int8) *int8 {
|
|
|
|
return &i
|
|
|
|
}
|
|
|
|
func uint64ToPtr(u uint64) *uint64 {
|
|
|
|
return &u
|
|
|
|
}
|
|
|
|
func int64ToPtr(i int64) *int64 {
|
|
|
|
return &i
|
|
|
|
}
|
|
|
|
|
2015-09-15 00:43:42 +00:00
|
|
|
func TestParse(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2015-09-15 00:43:42 +00:00
|
|
|
cases := []struct {
|
|
|
|
File string
|
2017-02-22 20:30:05 +00:00
|
|
|
Result *api.Job
|
2015-09-15 00:43:42 +00:00
|
|
|
Err bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"basic.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("binstore-storagelocker"),
|
|
|
|
Name: stringToPtr("binstore-storagelocker"),
|
|
|
|
Type: stringToPtr("batch"),
|
|
|
|
Priority: intToPtr(52),
|
|
|
|
AllAtOnce: boolToPtr(true),
|
2015-09-15 00:43:42 +00:00
|
|
|
Datacenters: []string{"us2", "eu1"},
|
2020-09-03 11:34:04 +00:00
|
|
|
Region: stringToPtr("fooregion"),
|
|
|
|
Namespace: stringToPtr("foonamespace"),
|
|
|
|
ConsulToken: stringToPtr("abc"),
|
|
|
|
VaultToken: stringToPtr("foo"),
|
2015-09-15 00:43:42 +00:00
|
|
|
|
2015-09-15 00:46:52 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
|
2017-02-22 20:30:05 +00:00
|
|
|
Constraints: []*api.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-09-15 00:48:11 +00:00
|
|
|
LTarget: "kernel.os",
|
|
|
|
RTarget: "windows",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
2019-11-13 23:36:15 +00:00
|
|
|
{
|
|
|
|
LTarget: "${attr.vault.version}",
|
|
|
|
RTarget: ">= 0.6.1",
|
|
|
|
Operand: "semver",
|
|
|
|
},
|
2015-09-15 00:48:11 +00:00
|
|
|
},
|
|
|
|
|
2018-07-16 13:30:58 +00:00
|
|
|
Affinities: []*api.Affinity{
|
|
|
|
{
|
|
|
|
LTarget: "${meta.team}",
|
|
|
|
RTarget: "mobile",
|
|
|
|
Operand: "=",
|
2020-09-03 11:34:04 +00:00
|
|
|
Weight: int8ToPtr(50),
|
2018-07-16 13:30:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2018-07-18 17:28:26 +00:00
|
|
|
Spreads: []*api.Spread{
|
|
|
|
{
|
|
|
|
Attribute: "${meta.rack}",
|
2020-09-03 11:34:04 +00:00
|
|
|
Weight: int8ToPtr(100),
|
2018-07-18 17:28:26 +00:00
|
|
|
SpreadTarget: []*api.SpreadTarget{
|
|
|
|
{
|
|
|
|
Value: "r1",
|
|
|
|
Percent: 40,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: "r2",
|
|
|
|
Percent: 60,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-02-22 20:30:05 +00:00
|
|
|
Update: &api.UpdateStrategy{
|
2020-09-03 11:34:04 +00:00
|
|
|
Stagger: timeToPtr(60 * time.Second),
|
|
|
|
MaxParallel: intToPtr(2),
|
|
|
|
HealthCheck: stringToPtr("manual"),
|
|
|
|
MinHealthyTime: timeToPtr(10 * time.Second),
|
|
|
|
HealthyDeadline: timeToPtr(10 * time.Minute),
|
|
|
|
ProgressDeadline: timeToPtr(10 * time.Minute),
|
|
|
|
AutoRevert: boolToPtr(true),
|
|
|
|
AutoPromote: boolToPtr(true),
|
|
|
|
Canary: intToPtr(1),
|
2015-09-20 21:18:10 +00:00
|
|
|
},
|
|
|
|
|
2017-02-22 20:30:05 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("outside"),
|
2019-07-25 14:42:11 +00:00
|
|
|
|
2017-02-22 20:30:05 +00:00
|
|
|
Tasks: []*api.Task{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-09-15 00:43:42 +00:00
|
|
|
Name: "outside",
|
|
|
|
Driver: "java",
|
2015-11-15 08:10:48 +00:00
|
|
|
Config: map[string]interface{}{
|
2016-04-09 22:38:42 +00:00
|
|
|
"jar_path": "s3://my-cool-store/foo.jar",
|
2015-09-15 00:43:42 +00:00
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"my-cool-key": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("binsl"),
|
|
|
|
Count: intToPtr(5),
|
2017-02-22 20:30:05 +00:00
|
|
|
Constraints: []*api.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-09-15 00:43:42 +00:00
|
|
|
LTarget: "kernel.os",
|
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
2019-08-12 14:22:27 +00:00
|
|
|
Volumes: map[string]*api.VolumeRequest{
|
2019-07-25 14:42:11 +00:00
|
|
|
"foo": {
|
2020-03-23 17:55:26 +00:00
|
|
|
Name: "foo",
|
|
|
|
Type: "host",
|
|
|
|
Source: "/path",
|
|
|
|
ExtraKeysHCL: nil,
|
|
|
|
},
|
|
|
|
"bar": {
|
2021-07-22 19:15:25 +00:00
|
|
|
Name: "bar",
|
|
|
|
Type: "csi",
|
|
|
|
Source: "bar-vol",
|
|
|
|
ReadOnly: true,
|
|
|
|
AccessMode: "single-mode-writer",
|
|
|
|
AttachmentMode: "file-system",
|
2020-03-23 17:55:26 +00:00
|
|
|
MountOptions: &api.CSIMountOptions{
|
|
|
|
FSType: "ext4",
|
|
|
|
},
|
|
|
|
ExtraKeysHCL: nil,
|
|
|
|
},
|
|
|
|
"baz": {
|
|
|
|
Name: "baz",
|
|
|
|
Type: "csi",
|
|
|
|
Source: "bar-vol",
|
|
|
|
MountOptions: &api.CSIMountOptions{
|
|
|
|
MountFlags: []string{
|
|
|
|
"ro",
|
|
|
|
},
|
|
|
|
},
|
2021-07-22 19:15:25 +00:00
|
|
|
PerAlloc: true,
|
2020-03-23 17:55:26 +00:00
|
|
|
ExtraKeysHCL: nil,
|
2019-07-25 14:42:11 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-16 13:30:58 +00:00
|
|
|
Affinities: []*api.Affinity{
|
|
|
|
{
|
|
|
|
LTarget: "${node.datacenter}",
|
|
|
|
RTarget: "dc2",
|
|
|
|
Operand: "=",
|
2020-09-03 11:34:04 +00:00
|
|
|
Weight: int8ToPtr(100),
|
2018-07-16 13:30:58 +00:00
|
|
|
},
|
|
|
|
},
|
2015-09-15 00:43:42 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"elb_mode": "tcp",
|
|
|
|
"elb_interval": "10",
|
|
|
|
"elb_checks": "3",
|
|
|
|
},
|
2017-02-22 20:30:05 +00:00
|
|
|
RestartPolicy: &api.RestartPolicy{
|
2020-09-03 11:34:04 +00:00
|
|
|
Interval: timeToPtr(10 * time.Minute),
|
|
|
|
Attempts: intToPtr(5),
|
|
|
|
Delay: timeToPtr(15 * time.Second),
|
|
|
|
Mode: stringToPtr("delay"),
|
2015-10-30 23:32:05 +00:00
|
|
|
},
|
2018-07-18 17:28:26 +00:00
|
|
|
Spreads: []*api.Spread{
|
|
|
|
{
|
|
|
|
Attribute: "${node.datacenter}",
|
2020-09-03 11:34:04 +00:00
|
|
|
Weight: int8ToPtr(50),
|
2018-07-18 17:28:26 +00:00
|
|
|
SpreadTarget: []*api.SpreadTarget{
|
|
|
|
{
|
|
|
|
Value: "dc1",
|
|
|
|
Percent: 50,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: "dc2",
|
|
|
|
Percent: 25,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: "dc3",
|
|
|
|
Percent: 25,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-03 11:34:04 +00:00
|
|
|
StopAfterClientDisconnect: timeToPtr(120 * time.Second),
|
2022-04-14 12:56:58 +00:00
|
|
|
MaxClientDisconnect: timeToPtr(120 * time.Hour),
|
2018-01-18 20:49:01 +00:00
|
|
|
ReschedulePolicy: &api.ReschedulePolicy{
|
2020-09-03 11:34:04 +00:00
|
|
|
Interval: timeToPtr(12 * time.Hour),
|
|
|
|
Attempts: intToPtr(5),
|
2018-01-18 20:49:01 +00:00
|
|
|
},
|
2017-02-22 20:30:05 +00:00
|
|
|
EphemeralDisk: &api.EphemeralDisk{
|
2020-09-03 11:34:04 +00:00
|
|
|
Sticky: boolToPtr(true),
|
|
|
|
SizeMB: intToPtr(150),
|
2016-08-24 18:51:15 +00:00
|
|
|
},
|
2017-05-09 00:44:26 +00:00
|
|
|
Update: &api.UpdateStrategy{
|
2020-09-03 11:34:04 +00:00
|
|
|
MaxParallel: intToPtr(3),
|
|
|
|
HealthCheck: stringToPtr("checks"),
|
|
|
|
MinHealthyTime: timeToPtr(1 * time.Second),
|
|
|
|
HealthyDeadline: timeToPtr(1 * time.Minute),
|
|
|
|
ProgressDeadline: timeToPtr(1 * time.Minute),
|
|
|
|
AutoRevert: boolToPtr(false),
|
|
|
|
AutoPromote: boolToPtr(false),
|
|
|
|
Canary: intToPtr(2),
|
2017-05-09 00:44:26 +00:00
|
|
|
},
|
2018-01-24 00:47:00 +00:00
|
|
|
Migrate: &api.MigrateStrategy{
|
2020-09-03 11:34:04 +00:00
|
|
|
MaxParallel: intToPtr(2),
|
|
|
|
HealthCheck: stringToPtr("task_states"),
|
|
|
|
MinHealthyTime: timeToPtr(11 * time.Second),
|
|
|
|
HealthyDeadline: timeToPtr(11 * time.Minute),
|
2018-01-24 00:47:00 +00:00
|
|
|
},
|
2017-02-22 20:30:05 +00:00
|
|
|
Tasks: []*api.Task{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-09-15 00:43:42 +00:00
|
|
|
Name: "binstore",
|
|
|
|
Driver: "docker",
|
2016-03-23 11:57:31 +00:00
|
|
|
User: "bob",
|
2019-08-07 23:43:36 +00:00
|
|
|
Kind: "connect-proxy:test",
|
2015-11-15 08:10:48 +00:00
|
|
|
Config: map[string]interface{}{
|
2015-09-15 00:43:42 +00:00
|
|
|
"image": "hashicorp/binstore",
|
2016-04-25 21:58:31 +00:00
|
|
|
"labels": []map[string]interface{}{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2016-04-25 21:58:31 +00:00
|
|
|
"FOO": "bar",
|
|
|
|
},
|
|
|
|
},
|
2015-09-15 00:43:42 +00:00
|
|
|
},
|
2019-07-25 14:42:11 +00:00
|
|
|
VolumeMounts: []*api.VolumeMount{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Volume: stringToPtr("foo"),
|
|
|
|
Destination: stringToPtr("/mnt/foo"),
|
2019-07-25 14:42:11 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-18 19:16:02 +00:00
|
|
|
Affinities: []*api.Affinity{
|
|
|
|
{
|
|
|
|
LTarget: "${meta.foo}",
|
2018-07-18 19:36:02 +00:00
|
|
|
RTarget: "a,b,c",
|
|
|
|
Operand: "set_contains",
|
2020-09-03 11:34:04 +00:00
|
|
|
Weight: int8ToPtr(25),
|
2018-07-18 19:16:02 +00:00
|
|
|
},
|
|
|
|
},
|
2020-03-07 02:52:58 +00:00
|
|
|
RestartPolicy: &api.RestartPolicy{
|
2020-09-03 11:34:04 +00:00
|
|
|
Attempts: intToPtr(10),
|
2020-03-07 02:52:58 +00:00
|
|
|
},
|
2017-03-01 23:30:01 +00:00
|
|
|
Services: []*api.Service{
|
2015-11-17 06:51:08 +00:00
|
|
|
{
|
2018-04-19 22:12:23 +00:00
|
|
|
Tags: []string{"foo", "bar"},
|
|
|
|
CanaryTags: []string{"canary", "bam"},
|
2019-11-13 03:27:54 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"abc": "123",
|
|
|
|
},
|
|
|
|
CanaryMeta: map[string]string{
|
|
|
|
"canary": "boom",
|
|
|
|
},
|
|
|
|
PortLabel: "http",
|
2017-02-22 20:30:05 +00:00
|
|
|
Checks: []api.ServiceCheck{
|
2015-11-17 06:51:08 +00:00
|
|
|
{
|
2018-05-03 22:18:12 +00:00
|
|
|
Name: "check-name",
|
|
|
|
Type: "tcp",
|
|
|
|
PortLabel: "admin",
|
|
|
|
Interval: 10 * time.Second,
|
|
|
|
Timeout: 2 * time.Second,
|
|
|
|
GRPCService: "foo.Bar",
|
|
|
|
GRPCUseTLS: true,
|
2017-09-14 22:55:37 +00:00
|
|
|
CheckRestart: &api.CheckRestart{
|
|
|
|
Limit: 3,
|
2020-09-03 11:34:04 +00:00
|
|
|
Grace: timeToPtr(10 * time.Second),
|
2017-09-14 22:55:37 +00:00
|
|
|
IgnoreWarnings: true,
|
|
|
|
},
|
2015-11-17 06:51:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-09-30 16:18:43 +00:00
|
|
|
Env: map[string]string{
|
|
|
|
"HELLO": "world",
|
|
|
|
"LOREM": "ipsum",
|
|
|
|
},
|
2017-02-22 20:30:05 +00:00
|
|
|
Resources: &api.Resources{
|
2021-03-26 20:11:26 +00:00
|
|
|
CPU: intToPtr(500),
|
|
|
|
MemoryMB: intToPtr(128),
|
|
|
|
MemoryMaxMB: intToPtr(256),
|
2017-02-22 20:30:05 +00:00
|
|
|
Networks: []*api.NetworkResource{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
MBits: intToPtr(100),
|
2017-02-28 00:00:19 +00:00
|
|
|
ReservedPorts: []api.Port{{Label: "one", Value: 1}, {Label: "two", Value: 2}, {Label: "three", Value: 3}},
|
|
|
|
DynamicPorts: []api.Port{{Label: "http", Value: 0}, {Label: "https", Value: 0}, {Label: "admin", Value: 0}},
|
2015-09-15 01:27:37 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-08 23:09:41 +00:00
|
|
|
Devices: []*api.RequestedDevice{
|
|
|
|
{
|
|
|
|
Name: "nvidia/gpu",
|
2020-09-03 11:34:04 +00:00
|
|
|
Count: uint64ToPtr(10),
|
2018-10-11 21:05:19 +00:00
|
|
|
Constraints: []*api.Constraint{
|
|
|
|
{
|
2019-01-23 00:48:09 +00:00
|
|
|
LTarget: "${device.attr.memory}",
|
2018-10-11 21:05:19 +00:00
|
|
|
RTarget: "2GB",
|
|
|
|
Operand: ">",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Affinities: []*api.Affinity{
|
|
|
|
{
|
2019-01-23 00:48:09 +00:00
|
|
|
LTarget: "${device.model}",
|
2018-10-11 21:05:19 +00:00
|
|
|
RTarget: "1080ti",
|
|
|
|
Operand: "=",
|
2020-09-03 11:34:04 +00:00
|
|
|
Weight: int8ToPtr(50),
|
2018-10-11 21:05:19 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-08 23:09:41 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "intel/gpu",
|
|
|
|
Count: nil,
|
|
|
|
},
|
|
|
|
},
|
2015-09-15 00:43:42 +00:00
|
|
|
},
|
2020-09-03 11:34:04 +00:00
|
|
|
KillTimeout: timeToPtr(22 * time.Second),
|
2017-08-17 00:54:11 +00:00
|
|
|
ShutdownDelay: 11 * time.Second,
|
2017-02-22 20:30:05 +00:00
|
|
|
LogConfig: &api.LogConfig{
|
2020-09-03 11:34:04 +00:00
|
|
|
MaxFiles: intToPtr(14),
|
|
|
|
MaxFileSizeMB: intToPtr(101),
|
2016-02-05 07:28:01 +00:00
|
|
|
},
|
2017-02-22 20:30:05 +00:00
|
|
|
Artifacts: []*api.TaskArtifact{
|
2016-03-14 18:13:43 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
GetterSource: stringToPtr("http://foo.com/artifact"),
|
2016-03-14 22:46:06 +00:00
|
|
|
GetterOptions: map[string]string{
|
|
|
|
"checksum": "md5:b8a4f3f72ecab0510a6a31e997461c5f",
|
2016-03-14 18:13:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
GetterSource: stringToPtr("http://bar.com/artifact"),
|
|
|
|
RelativeDest: stringToPtr("test/foo/"),
|
2016-03-14 22:46:06 +00:00
|
|
|
GetterOptions: map[string]string{
|
|
|
|
"checksum": "md5:ff1cc0d3432dad54d607c1505fb7245c",
|
2016-03-14 18:13:43 +00:00
|
|
|
},
|
2020-09-03 11:34:04 +00:00
|
|
|
GetterMode: stringToPtr("file"),
|
2016-03-14 18:13:43 +00:00
|
|
|
},
|
|
|
|
},
|
2017-02-22 20:30:05 +00:00
|
|
|
Vault: &api.Vault{
|
2022-04-22 14:46:34 +00:00
|
|
|
Namespace: stringToPtr("ns1"),
|
|
|
|
Policies: []string{"foo", "bar"},
|
|
|
|
Env: boolToPtr(true),
|
|
|
|
ChangeMode: stringToPtr(vaultChangeModeRestart),
|
2016-08-09 23:07:45 +00:00
|
|
|
},
|
2017-02-22 20:30:05 +00:00
|
|
|
Templates: []*api.Template{
|
2016-09-26 22:23:26 +00:00
|
|
|
{
|
2022-11-04 17:23:01 +00:00
|
|
|
SourcePath: stringToPtr("foo"),
|
|
|
|
DestPath: stringToPtr("foo"),
|
|
|
|
ChangeMode: stringToPtr("foo"),
|
|
|
|
ChangeSignal: stringToPtr("foo"),
|
|
|
|
Splay: timeToPtr(10 * time.Second),
|
|
|
|
Perms: stringToPtr("0644"),
|
|
|
|
Envvars: boolToPtr(true),
|
|
|
|
Uid: intToPtr(-1),
|
|
|
|
Gid: intToPtr(-1),
|
|
|
|
VaultGrace: timeToPtr(33 * time.Second),
|
|
|
|
ErrMissingKey: boolToPtr(true),
|
2016-09-26 22:23:26 +00:00
|
|
|
},
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
SourcePath: stringToPtr("bar"),
|
|
|
|
DestPath: stringToPtr("bar"),
|
2022-08-24 15:43:01 +00:00
|
|
|
ChangeMode: stringToPtr(templateChangeModeScript),
|
|
|
|
ChangeScript: &api.ChangeScript{
|
|
|
|
Args: []string{"-debug", "-verbose"},
|
|
|
|
Command: stringToPtr("/bin/foo"),
|
|
|
|
Timeout: timeToPtr(5 * time.Second),
|
|
|
|
FailOnError: boolToPtr(false),
|
|
|
|
},
|
2022-11-04 17:23:01 +00:00
|
|
|
Splay: timeToPtr(5 * time.Second),
|
|
|
|
Perms: stringToPtr("777"),
|
|
|
|
Uid: intToPtr(1001),
|
|
|
|
Gid: intToPtr(20),
|
|
|
|
LeftDelim: stringToPtr("--"),
|
|
|
|
RightDelim: stringToPtr("__"),
|
|
|
|
ErrMissingKey: boolToPtr(false),
|
2016-09-26 22:23:26 +00:00
|
|
|
},
|
|
|
|
},
|
2017-12-06 18:50:22 +00:00
|
|
|
Leader: true,
|
|
|
|
KillSignal: "",
|
2015-09-15 00:43:42 +00:00
|
|
|
},
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-09-15 00:43:42 +00:00
|
|
|
Name: "storagelocker",
|
2016-04-09 22:38:42 +00:00
|
|
|
Driver: "docker",
|
2016-03-23 11:57:31 +00:00
|
|
|
User: "",
|
2019-10-11 17:10:45 +00:00
|
|
|
Lifecycle: &api.TaskLifecycle{
|
2020-03-21 22:25:13 +00:00
|
|
|
Hook: "prestart",
|
|
|
|
Sidecar: true,
|
2019-10-11 17:10:45 +00:00
|
|
|
},
|
2015-11-15 08:10:48 +00:00
|
|
|
Config: map[string]interface{}{
|
2015-09-15 00:43:42 +00:00
|
|
|
"image": "hashicorp/storagelocker",
|
|
|
|
},
|
2017-02-22 20:30:05 +00:00
|
|
|
Resources: &api.Resources{
|
2020-09-03 11:34:04 +00:00
|
|
|
CPU: intToPtr(500),
|
|
|
|
MemoryMB: intToPtr(128),
|
2015-09-15 00:43:42 +00:00
|
|
|
},
|
2017-02-22 20:30:05 +00:00
|
|
|
Constraints: []*api.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-09-15 00:50:34 +00:00
|
|
|
LTarget: "kernel.arch",
|
|
|
|
RTarget: "amd64",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
2017-02-22 20:30:05 +00:00
|
|
|
Vault: &api.Vault{
|
2016-10-11 22:25:49 +00:00
|
|
|
Policies: []string{"foo", "bar"},
|
2020-09-03 11:34:04 +00:00
|
|
|
Env: boolToPtr(false),
|
|
|
|
ChangeMode: stringToPtr(vaultChangeModeSignal),
|
|
|
|
ChangeSignal: stringToPtr("SIGUSR1"),
|
2016-10-11 22:25:49 +00:00
|
|
|
},
|
2015-09-15 00:43:42 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2015-09-15 01:30:26 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
"multi-network.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"multi-resource.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
2015-09-15 01:34:26 +00:00
|
|
|
|
2016-08-09 23:07:45 +00:00
|
|
|
{
|
|
|
|
"multi-vault.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
2015-09-15 01:34:26 +00:00
|
|
|
{
|
|
|
|
"default-job.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
2015-09-15 01:34:26 +00:00
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2015-09-17 05:06:55 +00:00
|
|
|
|
2015-10-11 19:20:58 +00:00
|
|
|
{
|
|
|
|
"version-constraint.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
2017-02-22 20:30:05 +00:00
|
|
|
Constraints: []*api.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-10-11 19:20:58 +00:00
|
|
|
LTarget: "$attr.kernel.version",
|
|
|
|
RTarget: "~> 3.2",
|
2020-09-03 11:34:04 +00:00
|
|
|
Operand: api.ConstraintVersion,
|
2015-10-11 19:20:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
2015-10-11 19:37:50 +00:00
|
|
|
{
|
|
|
|
"regexp-constraint.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
2017-02-22 20:30:05 +00:00
|
|
|
Constraints: []*api.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-10-11 19:37:50 +00:00
|
|
|
LTarget: "$attr.kernel.version",
|
|
|
|
RTarget: "[0-9.]+",
|
2020-09-03 11:34:04 +00:00
|
|
|
Operand: api.ConstraintRegex,
|
2015-10-11 19:37:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
2016-10-19 20:06:28 +00:00
|
|
|
{
|
|
|
|
"set-contains-constraint.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
2017-02-22 20:30:05 +00:00
|
|
|
Constraints: []*api.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2016-10-19 20:06:28 +00:00
|
|
|
LTarget: "$meta.data",
|
|
|
|
RTarget: "foo,bar,baz",
|
2020-09-03 11:34:04 +00:00
|
|
|
Operand: api.ConstraintSetContains,
|
2016-10-19 20:06:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
2015-10-22 23:37:20 +00:00
|
|
|
{
|
2015-10-23 00:40:41 +00:00
|
|
|
"distinctHosts-constraint.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
2017-02-22 20:30:05 +00:00
|
|
|
Constraints: []*api.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Operand: api.ConstraintDistinctHosts,
|
2015-10-22 23:37:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
2017-03-07 22:20:02 +00:00
|
|
|
{
|
|
|
|
"distinctProperty-constraint.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
2017-03-07 22:20:02 +00:00
|
|
|
Constraints: []*api.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Operand: api.ConstraintDistinctProperty,
|
2017-03-07 22:20:02 +00:00
|
|
|
LTarget: "${meta.rack}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
2015-12-01 00:51:56 +00:00
|
|
|
{
|
|
|
|
"periodic-cron.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
2017-02-22 20:30:05 +00:00
|
|
|
Periodic: &api.PeriodicConfig{
|
2020-09-03 11:34:04 +00:00
|
|
|
SpecType: stringToPtr(api.PeriodicSpecCron),
|
|
|
|
Spec: stringToPtr("*/5 * * *"),
|
|
|
|
ProhibitOverlap: boolToPtr(true),
|
|
|
|
TimeZone: stringToPtr("Europe/Minsk"),
|
2015-12-01 00:51:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
|
2015-09-17 05:06:55 +00:00
|
|
|
{
|
|
|
|
"specify-job.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("job1"),
|
|
|
|
Name: stringToPtr("My Job"),
|
2015-09-17 05:06:55 +00:00
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2015-11-16 18:00:06 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
"task-nested-config.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
2017-02-22 20:30:05 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("bar"),
|
2017-02-22 20:30:05 +00:00
|
|
|
Tasks: []*api.Task{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-11-16 18:00:06 +00:00
|
|
|
Name: "bar",
|
|
|
|
Driver: "docker",
|
|
|
|
Config: map[string]interface{}{
|
2016-04-09 22:38:42 +00:00
|
|
|
"image": "hashicorp/image",
|
2015-11-16 18:00:06 +00:00
|
|
|
"port_map": []map[string]interface{}{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-11-16 18:00:06 +00:00
|
|
|
"db": 1234,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2016-04-09 22:38:42 +00:00
|
|
|
|
2016-03-16 03:21:52 +00:00
|
|
|
{
|
|
|
|
"bad-artifact.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
2016-03-18 19:01:46 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
"artifacts.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("binstore-storagelocker"),
|
|
|
|
Name: stringToPtr("binstore-storagelocker"),
|
2017-02-22 20:30:05 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("binsl"),
|
2017-02-22 20:30:05 +00:00
|
|
|
Tasks: []*api.Task{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2016-03-18 19:01:46 +00:00
|
|
|
Name: "binstore",
|
|
|
|
Driver: "docker",
|
2017-02-22 20:30:05 +00:00
|
|
|
Artifacts: []*api.TaskArtifact{
|
2016-03-18 19:01:46 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
GetterSource: stringToPtr("http://foo.com/bar"),
|
2016-06-10 19:28:27 +00:00
|
|
|
GetterOptions: map[string]string{"foo": "bar"},
|
2020-09-03 11:34:04 +00:00
|
|
|
RelativeDest: stringToPtr(""),
|
2016-03-18 19:01:46 +00:00
|
|
|
},
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
GetterSource: stringToPtr("http://foo.com/baz"),
|
2016-06-10 19:28:27 +00:00
|
|
|
GetterOptions: nil,
|
2017-02-22 20:30:05 +00:00
|
|
|
RelativeDest: nil,
|
2016-03-18 19:01:46 +00:00
|
|
|
},
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
GetterSource: stringToPtr("http://foo.com/bam"),
|
2016-06-10 19:28:27 +00:00
|
|
|
GetterOptions: nil,
|
2020-09-03 11:34:04 +00:00
|
|
|
RelativeDest: stringToPtr("var/foo"),
|
2016-03-18 19:01:46 +00:00
|
|
|
},
|
2022-09-27 16:18:49 +00:00
|
|
|
{
|
|
|
|
GetterSource: stringToPtr("https://example.com/file.txt"),
|
|
|
|
GetterHeaders: map[string]string{
|
|
|
|
"User-Agent": "nomad",
|
|
|
|
"X-Nomad-Alloc": "alloc",
|
|
|
|
},
|
|
|
|
},
|
2016-03-18 19:01:46 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2019-10-22 13:20:26 +00:00
|
|
|
{
|
|
|
|
"csi-plugin.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("binstore-storagelocker"),
|
|
|
|
Name: stringToPtr("binstore-storagelocker"),
|
2019-10-22 13:20:26 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("binsl"),
|
2019-10-22 13:20:26 +00:00
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "binstore",
|
|
|
|
Driver: "docker",
|
|
|
|
CSIPluginConfig: &api.TaskCSIPluginConfig{
|
2022-06-14 14:04:16 +00:00
|
|
|
ID: "org.hashicorp.csi",
|
|
|
|
Type: api.CSIPluginTypeMonolith,
|
|
|
|
MountDir: "/csi/test",
|
|
|
|
HealthTimeout: 1 * time.Minute,
|
2019-10-22 13:20:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2016-08-16 21:34:36 +00:00
|
|
|
{
|
|
|
|
"service-check-initial-status.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("check_initial_status"),
|
|
|
|
Name: stringToPtr("check_initial_status"),
|
|
|
|
Type: stringToPtr("service"),
|
2017-02-22 20:30:05 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Count: intToPtr(1),
|
2017-02-22 20:30:05 +00:00
|
|
|
Tasks: []*api.Task{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2016-08-16 21:34:36 +00:00
|
|
|
Name: "task",
|
2017-03-01 23:30:01 +00:00
|
|
|
Services: []*api.Service{
|
2016-08-16 21:34:36 +00:00
|
|
|
{
|
|
|
|
Tags: []string{"foo", "bar"},
|
|
|
|
PortLabel: "http",
|
2017-02-22 20:30:05 +00:00
|
|
|
Checks: []api.ServiceCheck{
|
2016-08-16 21:34:36 +00:00
|
|
|
{
|
|
|
|
Name: "check-name",
|
|
|
|
Type: "http",
|
2017-08-16 00:17:11 +00:00
|
|
|
Path: "/",
|
2016-08-16 21:34:36 +00:00
|
|
|
Interval: 10 * time.Second,
|
|
|
|
Timeout: 2 * time.Second,
|
2017-02-22 20:30:05 +00:00
|
|
|
InitialStatus: capi.HealthPassing,
|
2017-08-16 00:17:11 +00:00
|
|
|
Method: "POST",
|
|
|
|
Header: map[string][]string{
|
|
|
|
"Authorization": {"Basic ZWxhc3RpYzpjaGFuZ2VtZQ=="},
|
|
|
|
},
|
2016-08-16 21:34:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-08-08 01:22:06 +00:00
|
|
|
{
|
|
|
|
"service-check-pass-fail.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("check_pass_fail"),
|
|
|
|
Name: stringToPtr("check_pass_fail"),
|
|
|
|
Type: stringToPtr("service"),
|
2020-08-08 01:22:06 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Count: intToPtr(1),
|
2020-08-08 01:22:06 +00:00
|
|
|
Tasks: []*api.Task{{
|
|
|
|
Name: "task",
|
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "service",
|
|
|
|
PortLabel: "http",
|
|
|
|
Checks: []api.ServiceCheck{{
|
|
|
|
Name: "check-name",
|
|
|
|
Type: "http",
|
|
|
|
Path: "/",
|
|
|
|
Interval: 10 * time.Second,
|
|
|
|
Timeout: 2 * time.Second,
|
|
|
|
InitialStatus: capi.HealthPassing,
|
|
|
|
Method: "POST",
|
|
|
|
SuccessBeforePassing: 3,
|
|
|
|
FailuresBeforeCritical: 4,
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-07-28 20:12:08 +00:00
|
|
|
{
|
|
|
|
"service-check-pass-fail.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("check_pass_fail"),
|
|
|
|
Name: stringToPtr("check_pass_fail"),
|
|
|
|
Type: stringToPtr("service"),
|
2020-07-28 20:12:08 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Count: intToPtr(1),
|
2020-07-28 20:12:08 +00:00
|
|
|
Tasks: []*api.Task{{
|
|
|
|
Name: "task",
|
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "service",
|
|
|
|
PortLabel: "http",
|
|
|
|
Checks: []api.ServiceCheck{{
|
|
|
|
Name: "check-name",
|
|
|
|
Type: "http",
|
|
|
|
Path: "/",
|
|
|
|
Interval: 10 * time.Second,
|
|
|
|
Timeout: 2 * time.Second,
|
|
|
|
InitialStatus: capi.HealthPassing,
|
|
|
|
Method: "POST",
|
|
|
|
SuccessBeforePassing: 3,
|
|
|
|
FailuresBeforeCritical: 4,
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2017-08-17 22:25:51 +00:00
|
|
|
{
|
|
|
|
"service-check-bad-header.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"service-check-bad-header-2.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
2016-09-21 18:18:44 +00:00
|
|
|
{
|
2017-02-22 20:30:05 +00:00
|
|
|
// TODO This should be pushed into the API
|
2016-09-21 18:18:44 +00:00
|
|
|
"vault_inheritance.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("example"),
|
|
|
|
Name: stringToPtr("example"),
|
2017-02-22 20:30:05 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("cache"),
|
2017-02-22 20:30:05 +00:00
|
|
|
Tasks: []*api.Task{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2017-02-22 20:30:05 +00:00
|
|
|
Name: "redis",
|
|
|
|
Vault: &api.Vault{
|
2016-10-11 22:25:49 +00:00
|
|
|
Policies: []string{"group"},
|
2020-09-03 11:34:04 +00:00
|
|
|
Env: boolToPtr(true),
|
|
|
|
ChangeMode: stringToPtr(vaultChangeModeRestart),
|
2016-09-21 18:18:44 +00:00
|
|
|
},
|
|
|
|
},
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2017-02-22 20:30:05 +00:00
|
|
|
Name: "redis2",
|
|
|
|
Vault: &api.Vault{
|
2016-10-11 22:25:49 +00:00
|
|
|
Policies: []string{"task"},
|
2020-09-03 11:34:04 +00:00
|
|
|
Env: boolToPtr(false),
|
|
|
|
ChangeMode: stringToPtr(vaultChangeModeRestart),
|
2016-09-21 18:18:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("cache2"),
|
2017-02-22 20:30:05 +00:00
|
|
|
Tasks: []*api.Task{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2017-02-22 20:30:05 +00:00
|
|
|
Name: "redis",
|
|
|
|
Vault: &api.Vault{
|
2016-10-11 22:25:49 +00:00
|
|
|
Policies: []string{"job"},
|
2020-09-03 11:34:04 +00:00
|
|
|
Env: boolToPtr(true),
|
|
|
|
ChangeMode: stringToPtr(vaultChangeModeRestart),
|
2016-09-21 18:18:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2016-11-23 23:48:36 +00:00
|
|
|
{
|
2017-01-20 18:33:52 +00:00
|
|
|
"parameterized_job.hcl",
|
2017-02-22 20:30:05 +00:00
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("parameterized_job"),
|
|
|
|
Name: stringToPtr("parameterized_job"),
|
2017-02-22 20:30:05 +00:00
|
|
|
|
|
|
|
ParameterizedJob: &api.ParameterizedJobConfig{
|
2016-12-14 20:50:08 +00:00
|
|
|
Payload: "required",
|
2016-11-23 23:48:36 +00:00
|
|
|
MetaRequired: []string{"foo", "bar"},
|
|
|
|
MetaOptional: []string{"baz", "bam"},
|
|
|
|
},
|
|
|
|
|
2017-02-22 20:30:05 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("foo"),
|
2017-02-22 20:30:05 +00:00
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
2016-11-23 23:48:36 +00:00
|
|
|
Name: "bar",
|
|
|
|
Driver: "docker",
|
2017-02-22 20:30:05 +00:00
|
|
|
DispatchPayload: &api.DispatchPayloadConfig{
|
2016-12-14 20:50:08 +00:00
|
|
|
File: "foo/bar",
|
2016-11-23 23:48:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2017-11-30 21:53:35 +00:00
|
|
|
{
|
|
|
|
"job-with-kill-signal.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
2017-11-30 21:53:35 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("bar"),
|
2017-11-30 21:53:35 +00:00
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
2017-12-06 21:23:24 +00:00
|
|
|
Name: "bar",
|
2017-11-30 21:53:35 +00:00
|
|
|
Driver: "docker",
|
2017-12-06 21:23:24 +00:00
|
|
|
KillSignal: "SIGQUIT",
|
2017-11-30 21:53:35 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"image": "hashicorp/image",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2022-05-31 15:06:39 +00:00
|
|
|
{
|
|
|
|
"service-tagged-address.hcl",
|
|
|
|
&api.Job{
|
|
|
|
ID: stringToPtr("service_tagged_address"),
|
|
|
|
Name: stringToPtr("service_tagged_address"),
|
|
|
|
Type: stringToPtr("service"),
|
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Services: []*api.Service{
|
|
|
|
{
|
|
|
|
Name: "service1",
|
|
|
|
TaggedAddresses: map[string]string{
|
|
|
|
"public_wan": "1.2.3.4",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2017-12-05 19:39:42 +00:00
|
|
|
{
|
|
|
|
"service-check-driver-address.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("address_mode_driver"),
|
|
|
|
Name: stringToPtr("address_mode_driver"),
|
|
|
|
Type: stringToPtr("service"),
|
2017-12-05 19:39:42 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2017-12-05 19:39:42 +00:00
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "task",
|
|
|
|
Services: []*api.Service{
|
|
|
|
{
|
|
|
|
Name: "http-service",
|
|
|
|
PortLabel: "http",
|
|
|
|
AddressMode: "auto",
|
|
|
|
Checks: []api.ServiceCheck{
|
|
|
|
{
|
|
|
|
Name: "http-check",
|
|
|
|
Type: "http",
|
|
|
|
Path: "/",
|
|
|
|
PortLabel: "http",
|
|
|
|
AddressMode: "driver",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "random-service",
|
|
|
|
PortLabel: "9000",
|
|
|
|
AddressMode: "driver",
|
|
|
|
Checks: []api.ServiceCheck{
|
|
|
|
{
|
|
|
|
Name: "random-check",
|
|
|
|
Type: "tcp",
|
|
|
|
PortLabel: "9001",
|
|
|
|
AddressMode: "driver",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2018-01-04 23:04:45 +00:00
|
|
|
{
|
|
|
|
"service-check-restart.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("service_check_restart"),
|
|
|
|
Name: stringToPtr("service_check_restart"),
|
|
|
|
Type: stringToPtr("service"),
|
2018-01-04 23:04:45 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2018-01-04 23:04:45 +00:00
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "task",
|
|
|
|
Services: []*api.Service{
|
|
|
|
{
|
|
|
|
Name: "http-service",
|
|
|
|
CheckRestart: &api.CheckRestart{
|
|
|
|
Limit: 3,
|
2020-09-03 11:34:04 +00:00
|
|
|
Grace: timeToPtr(10 * time.Second),
|
2018-01-04 23:04:45 +00:00
|
|
|
IgnoreWarnings: true,
|
|
|
|
},
|
|
|
|
Checks: []api.ServiceCheck{
|
|
|
|
{
|
|
|
|
Name: "random-check",
|
|
|
|
Type: "tcp",
|
|
|
|
PortLabel: "9001",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2019-08-23 16:49:02 +00:00
|
|
|
{
|
|
|
|
"service-meta.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("service_meta"),
|
|
|
|
Name: stringToPtr("service_meta"),
|
|
|
|
Type: stringToPtr("service"),
|
2019-08-23 16:49:02 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2019-08-23 16:49:02 +00:00
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "task",
|
|
|
|
Services: []*api.Service{
|
|
|
|
{
|
|
|
|
Name: "http-service",
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
client: enable configuring enable_tag_override for services
Consul provides a feature of Service Definitions where the tags
associated with a service can be modified through the Catalog API,
overriding the value(s) configured in the agent's service configuration.
To enable this feature, the flag enable_tag_override must be configured
in the service definition.
Previously, Nomad did not allow configuring this flag, and thus the default
value of false was used. Now, it is configurable.
Because Nomad itself acts as a state machine around the the service definitions
of the tasks it manages, it's worth describing what happens when this feature
is enabled and why.
Consider the basic case where there is no Nomad, and your service is provided
to consul as a boring JSON file. The ultimate source of truth for the definition
of that service is the file, and is stored in the agent. Later, Consul performs
"anti-entropy" which synchronizes the Catalog (stored only the leaders). Then
with enable_tag_override=true, the tags field is available for "external"
modification through the Catalog API (rather than directly configuring the
service definition file, or using the Agent API). The important observation
is that if the service definition ever changes (i.e. the file is changed &
config reloaded OR the Agent API is used to modify the service), those
"external" tag values are thrown away, and the new service definition is
once again the source of truth.
In the Nomad case, Nomad itself is the source of truth over the Agent in
the same way the JSON file was the source of truth in the example above.
That means any time Nomad sets a new service definition, any externally
configured tags are going to be replaced. When does this happen? Only on
major lifecycle events, for example when a task is modified because of an
updated job spec from the 'nomad job run <existing>' command. Otherwise,
Nomad's periodic re-sync's with Consul will now no longer try to restore
the externally modified tag values (as long as enable_tag_override=true).
Fixes #2057
2020-02-07 21:22:19 +00:00
|
|
|
{
|
|
|
|
"service-enable-tag-override.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("service_eto"),
|
|
|
|
Name: stringToPtr("service_eto"),
|
|
|
|
Type: stringToPtr("service"),
|
client: enable configuring enable_tag_override for services
Consul provides a feature of Service Definitions where the tags
associated with a service can be modified through the Catalog API,
overriding the value(s) configured in the agent's service configuration.
To enable this feature, the flag enable_tag_override must be configured
in the service definition.
Previously, Nomad did not allow configuring this flag, and thus the default
value of false was used. Now, it is configurable.
Because Nomad itself acts as a state machine around the the service definitions
of the tasks it manages, it's worth describing what happens when this feature
is enabled and why.
Consider the basic case where there is no Nomad, and your service is provided
to consul as a boring JSON file. The ultimate source of truth for the definition
of that service is the file, and is stored in the agent. Later, Consul performs
"anti-entropy" which synchronizes the Catalog (stored only the leaders). Then
with enable_tag_override=true, the tags field is available for "external"
modification through the Catalog API (rather than directly configuring the
service definition file, or using the Agent API). The important observation
is that if the service definition ever changes (i.e. the file is changed &
config reloaded OR the Agent API is used to modify the service), those
"external" tag values are thrown away, and the new service definition is
once again the source of truth.
In the Nomad case, Nomad itself is the source of truth over the Agent in
the same way the JSON file was the source of truth in the example above.
That means any time Nomad sets a new service definition, any externally
configured tags are going to be replaced. When does this happen? Only on
major lifecycle events, for example when a task is modified because of an
updated job spec from the 'nomad job run <existing>' command. Otherwise,
Nomad's periodic re-sync's with Consul will now no longer try to restore
the externally modified tag values (as long as enable_tag_override=true).
Fixes #2057
2020-02-07 21:22:19 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
client: enable configuring enable_tag_override for services
Consul provides a feature of Service Definitions where the tags
associated with a service can be modified through the Catalog API,
overriding the value(s) configured in the agent's service configuration.
To enable this feature, the flag enable_tag_override must be configured
in the service definition.
Previously, Nomad did not allow configuring this flag, and thus the default
value of false was used. Now, it is configurable.
Because Nomad itself acts as a state machine around the the service definitions
of the tasks it manages, it's worth describing what happens when this feature
is enabled and why.
Consider the basic case where there is no Nomad, and your service is provided
to consul as a boring JSON file. The ultimate source of truth for the definition
of that service is the file, and is stored in the agent. Later, Consul performs
"anti-entropy" which synchronizes the Catalog (stored only the leaders). Then
with enable_tag_override=true, the tags field is available for "external"
modification through the Catalog API (rather than directly configuring the
service definition file, or using the Agent API). The important observation
is that if the service definition ever changes (i.e. the file is changed &
config reloaded OR the Agent API is used to modify the service), those
"external" tag values are thrown away, and the new service definition is
once again the source of truth.
In the Nomad case, Nomad itself is the source of truth over the Agent in
the same way the JSON file was the source of truth in the example above.
That means any time Nomad sets a new service definition, any externally
configured tags are going to be replaced. When does this happen? Only on
major lifecycle events, for example when a task is modified because of an
updated job spec from the 'nomad job run <existing>' command. Otherwise,
Nomad's periodic re-sync's with Consul will now no longer try to restore
the externally modified tag values (as long as enable_tag_override=true).
Fixes #2057
2020-02-07 21:22:19 +00:00
|
|
|
Tasks: []*api.Task{{
|
|
|
|
Name: "task",
|
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "example",
|
|
|
|
EnableTagOverride: true,
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2018-01-18 20:49:01 +00:00
|
|
|
{
|
|
|
|
"reschedule-job.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
|
|
|
Type: stringToPtr("batch"),
|
2018-01-18 20:49:01 +00:00
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Reschedule: &api.ReschedulePolicy{
|
2020-09-03 11:34:04 +00:00
|
|
|
Attempts: intToPtr(15),
|
|
|
|
Interval: timeToPtr(30 * time.Minute),
|
|
|
|
DelayFunction: stringToPtr("constant"),
|
|
|
|
Delay: timeToPtr(10 * time.Second),
|
2018-03-07 21:26:45 +00:00
|
|
|
},
|
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("bar"),
|
|
|
|
Count: intToPtr(3),
|
2018-03-07 21:26:45 +00:00
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Driver: "raw_exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "bash",
|
|
|
|
"args": []interface{}{"-c", "echo hi"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"reschedule-job-unlimited.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
|
|
|
Type: stringToPtr("batch"),
|
2018-03-07 21:26:45 +00:00
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Reschedule: &api.ReschedulePolicy{
|
2020-09-03 11:34:04 +00:00
|
|
|
DelayFunction: stringToPtr("exponential"),
|
|
|
|
Delay: timeToPtr(10 * time.Second),
|
|
|
|
MaxDelay: timeToPtr(120 * time.Second),
|
|
|
|
Unlimited: boolToPtr(true),
|
2018-01-18 20:49:01 +00:00
|
|
|
},
|
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("bar"),
|
|
|
|
Count: intToPtr(3),
|
2018-01-18 20:49:01 +00:00
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Driver: "raw_exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "bash",
|
|
|
|
"args": []interface{}{"-c", "echo hi"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2018-03-01 19:21:32 +00:00
|
|
|
{
|
|
|
|
"migrate-job.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
|
|
|
Type: stringToPtr("batch"),
|
2018-03-01 19:21:32 +00:00
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Migrate: &api.MigrateStrategy{
|
2020-09-03 11:34:04 +00:00
|
|
|
MaxParallel: intToPtr(2),
|
|
|
|
HealthCheck: stringToPtr("task_states"),
|
|
|
|
MinHealthyTime: timeToPtr(11 * time.Second),
|
|
|
|
HealthyDeadline: timeToPtr(11 * time.Minute),
|
2018-03-01 19:21:32 +00:00
|
|
|
},
|
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("bar"),
|
|
|
|
Count: intToPtr(3),
|
2018-03-01 19:21:32 +00:00
|
|
|
Migrate: &api.MigrateStrategy{
|
2020-09-03 11:34:04 +00:00
|
|
|
MaxParallel: intToPtr(3),
|
|
|
|
HealthCheck: stringToPtr("checks"),
|
|
|
|
MinHealthyTime: timeToPtr(1 * time.Second),
|
|
|
|
HealthyDeadline: timeToPtr(1 * time.Minute),
|
2018-03-01 19:21:32 +00:00
|
|
|
},
|
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Driver: "raw_exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "bash",
|
|
|
|
"args": []interface{}{"-c", "echo hi"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2019-04-29 17:15:12 +00:00
|
|
|
{
|
|
|
|
"tg-network.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
2019-04-29 17:15:12 +00:00
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("bar"),
|
|
|
|
ShutdownDelay: timeToPtr(14 * time.Second),
|
|
|
|
Count: intToPtr(3),
|
2019-04-29 17:15:12 +00:00
|
|
|
Networks: []*api.NetworkResource{
|
|
|
|
{
|
|
|
|
Mode: "bridge",
|
|
|
|
ReservedPorts: []api.Port{
|
|
|
|
{
|
2020-06-16 15:53:10 +00:00
|
|
|
Label: "http",
|
|
|
|
Value: 80,
|
|
|
|
To: 8080,
|
|
|
|
HostNetwork: "public",
|
2019-04-29 17:15:12 +00:00
|
|
|
},
|
|
|
|
},
|
2020-04-28 03:11:06 +00:00
|
|
|
DNS: &api.DNSConfig{
|
|
|
|
Servers: []string{"8.8.8.8"},
|
|
|
|
Options: []string{"ndots:2", "edns0"},
|
|
|
|
},
|
2019-04-29 17:15:12 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-30 22:40:45 +00:00
|
|
|
Services: []*api.Service{
|
|
|
|
{
|
|
|
|
Name: "connect-service",
|
|
|
|
Tags: []string{"foo", "bar"},
|
|
|
|
CanaryTags: []string{"canary", "bam"},
|
|
|
|
PortLabel: "1234",
|
|
|
|
Connect: &api.ConsulConnect{
|
|
|
|
SidecarService: &api.ConsulSidecarService{
|
2019-10-08 19:19:09 +00:00
|
|
|
Tags: []string{"side1", "side2"},
|
2019-07-30 22:40:45 +00:00
|
|
|
Proxy: &api.ConsulProxy{
|
2020-04-10 23:42:32 +00:00
|
|
|
LocalServicePort: 8080,
|
2019-07-30 22:40:45 +00:00
|
|
|
Upstreams: []*api.ConsulUpstream{
|
|
|
|
{
|
2021-07-22 19:15:50 +00:00
|
|
|
DestinationName: "other-service",
|
|
|
|
LocalBindPort: 4567,
|
|
|
|
LocalBindAddress: "0.0.0.0",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
|
|
|
|
MeshGateway: &api.ConsulMeshGateway{
|
|
|
|
Mode: "local",
|
|
|
|
},
|
2019-07-30 22:40:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-08-20 05:22:46 +00:00
|
|
|
SidecarTask: &api.SidecarTask{
|
2019-08-09 19:18:53 +00:00
|
|
|
Resources: &api.Resources{
|
2020-09-03 11:34:04 +00:00
|
|
|
CPU: intToPtr(500),
|
|
|
|
MemoryMB: intToPtr(1024),
|
2019-08-09 19:18:53 +00:00
|
|
|
},
|
|
|
|
Env: map[string]string{
|
|
|
|
"FOO": "abc",
|
|
|
|
},
|
2020-09-03 11:34:04 +00:00
|
|
|
ShutdownDelay: timeToPtr(5 * time.Second),
|
2019-08-09 19:18:53 +00:00
|
|
|
},
|
2019-07-30 22:40:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-04-29 17:15:12 +00:00
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Driver: "raw_exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "bash",
|
|
|
|
"args": []interface{}{"-c", "echo hi"},
|
|
|
|
},
|
|
|
|
Resources: &api.Resources{
|
|
|
|
Networks: []*api.NetworkResource{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
MBits: intToPtr(10),
|
2019-04-29 17:15:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2019-08-19 13:17:38 +00:00
|
|
|
{
|
|
|
|
"tg-service-check.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("group_service_check_script"),
|
|
|
|
Name: stringToPtr("group_service_check_script"),
|
2019-08-19 13:17:38 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Count: intToPtr(1),
|
2019-08-19 13:17:38 +00:00
|
|
|
Networks: []*api.NetworkResource{
|
|
|
|
{
|
|
|
|
Mode: "bridge",
|
|
|
|
ReservedPorts: []api.Port{
|
|
|
|
{
|
|
|
|
Label: "http",
|
|
|
|
Value: 80,
|
|
|
|
To: 8080,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: []*api.Service{
|
|
|
|
{
|
|
|
|
Name: "foo-service",
|
|
|
|
PortLabel: "http",
|
2021-07-22 19:25:36 +00:00
|
|
|
OnUpdate: "ignore",
|
2019-08-19 13:17:38 +00:00
|
|
|
Checks: []api.ServiceCheck{
|
|
|
|
{
|
|
|
|
Name: "check-name",
|
|
|
|
Type: "script",
|
|
|
|
Command: "/bin/true",
|
|
|
|
Interval: time.Duration(10 * time.Second),
|
|
|
|
Timeout: time.Duration(2 * time.Second),
|
|
|
|
InitialStatus: "passing",
|
|
|
|
TaskName: "foo",
|
2021-07-22 19:25:36 +00:00
|
|
|
OnUpdate: "ignore",
|
2021-07-22 19:34:23 +00:00
|
|
|
Body: "post body",
|
2019-08-19 13:17:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Tasks: []*api.Task{{Name: "foo"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-03-07 03:15:22 +00:00
|
|
|
{
|
|
|
|
"tg-service-proxy-expose.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("group_service_proxy_expose"),
|
|
|
|
Name: stringToPtr("group_service_proxy_expose"),
|
2020-03-07 03:15:22 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2020-03-07 03:15:22 +00:00
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "example",
|
|
|
|
Connect: &api.ConsulConnect{
|
|
|
|
SidecarService: &api.ConsulSidecarService{
|
|
|
|
Proxy: &api.ConsulProxy{
|
2023-01-30 15:31:16 +00:00
|
|
|
Expose: &api.ConsulExposeConfig{
|
|
|
|
Paths: []*api.ConsulExposePath{{
|
2020-03-07 03:15:22 +00:00
|
|
|
Path: "/health",
|
|
|
|
Protocol: "http",
|
|
|
|
LocalPathPort: 2222,
|
|
|
|
ListenerPort: "healthcheck",
|
2020-03-12 14:37:31 +00:00
|
|
|
}, {
|
|
|
|
Path: "/metrics",
|
|
|
|
Protocol: "grpc",
|
|
|
|
LocalPathPort: 3000,
|
|
|
|
ListenerPort: "metrics",
|
2020-03-07 03:15:22 +00:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-04-10 23:42:32 +00:00
|
|
|
{
|
|
|
|
"tg-service-connect-sidecar_task-name.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("sidecar_task_name"),
|
|
|
|
Name: stringToPtr("sidecar_task_name"),
|
|
|
|
Type: stringToPtr("service"),
|
2020-04-10 23:42:32 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2020-04-10 23:42:32 +00:00
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "example",
|
|
|
|
Connect: &api.ConsulConnect{
|
2020-06-22 17:55:59 +00:00
|
|
|
Native: false,
|
2020-04-10 23:42:32 +00:00
|
|
|
SidecarService: &api.ConsulSidecarService{},
|
|
|
|
SidecarTask: &api.SidecarTask{
|
|
|
|
Name: "my-sidecar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2021-05-07 16:10:26 +00:00
|
|
|
{
|
|
|
|
"tg-service-connect-sidecar_disablecheck.hcl",
|
|
|
|
&api.Job{
|
|
|
|
ID: stringToPtr("sidecar_disablecheck"),
|
|
|
|
Name: stringToPtr("sidecar_disablecheck"),
|
|
|
|
Type: stringToPtr("service"),
|
|
|
|
TaskGroups: []*api.TaskGroup{{
|
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "example",
|
|
|
|
Connect: &api.ConsulConnect{
|
|
|
|
Native: false,
|
|
|
|
SidecarService: &api.ConsulSidecarService{
|
|
|
|
DisableDefaultTCPCheck: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2022-01-25 15:29:16 +00:00
|
|
|
{
|
|
|
|
"tg-service-connect-resources.hcl",
|
|
|
|
&api.Job{
|
|
|
|
ID: stringToPtr("sidecar_task_resources"),
|
|
|
|
Name: stringToPtr("sidecar_task_resources"),
|
|
|
|
Type: stringToPtr("service"),
|
|
|
|
TaskGroups: []*api.TaskGroup{{
|
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "example",
|
|
|
|
Connect: &api.ConsulConnect{
|
|
|
|
SidecarTask: &api.SidecarTask{
|
|
|
|
Resources: &api.Resources{
|
|
|
|
CPU: intToPtr(111),
|
|
|
|
MemoryMB: intToPtr(222),
|
|
|
|
MemoryMaxMB: intToPtr(333),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-04-10 23:42:32 +00:00
|
|
|
{
|
|
|
|
"tg-service-connect-proxy.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("service-connect-proxy"),
|
|
|
|
Name: stringToPtr("service-connect-proxy"),
|
|
|
|
Type: stringToPtr("service"),
|
2020-04-10 23:42:32 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2020-04-10 23:42:32 +00:00
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "example",
|
|
|
|
Connect: &api.ConsulConnect{
|
2020-06-22 17:55:59 +00:00
|
|
|
Native: false,
|
2020-04-10 23:42:32 +00:00
|
|
|
SidecarService: &api.ConsulSidecarService{
|
|
|
|
Proxy: &api.ConsulProxy{
|
|
|
|
LocalServiceAddress: "10.0.1.2",
|
|
|
|
LocalServicePort: 8080,
|
2023-01-30 15:31:16 +00:00
|
|
|
Expose: &api.ConsulExposeConfig{
|
|
|
|
Paths: []*api.ConsulExposePath{{
|
2020-04-10 23:42:32 +00:00
|
|
|
Path: "/metrics",
|
|
|
|
Protocol: "http",
|
|
|
|
LocalPathPort: 9001,
|
|
|
|
ListenerPort: "metrics",
|
|
|
|
}, {
|
|
|
|
Path: "/health",
|
|
|
|
Protocol: "http",
|
|
|
|
LocalPathPort: 9002,
|
|
|
|
ListenerPort: "health",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
Upstreams: []*api.ConsulUpstream{{
|
|
|
|
DestinationName: "upstream1",
|
|
|
|
LocalBindPort: 2001,
|
|
|
|
}, {
|
|
|
|
DestinationName: "upstream2",
|
|
|
|
LocalBindPort: 2002,
|
|
|
|
}},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"tg-service-connect-local-service.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("connect-proxy-local-service"),
|
|
|
|
Name: stringToPtr("connect-proxy-local-service"),
|
|
|
|
Type: stringToPtr("service"),
|
2020-04-10 23:42:32 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2020-04-10 23:42:32 +00:00
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "example",
|
|
|
|
Connect: &api.ConsulConnect{
|
2020-06-22 17:55:59 +00:00
|
|
|
Native: false,
|
2020-04-10 23:42:32 +00:00
|
|
|
SidecarService: &api.ConsulSidecarService{
|
|
|
|
Proxy: &api.ConsulProxy{
|
|
|
|
LocalServiceAddress: "10.0.1.2",
|
|
|
|
LocalServicePort: 9876,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
connect: enable automatic expose paths for individual group service checks
Part of #6120
Building on the support for enabling connect proxy paths in #7323, this change
adds the ability to configure the 'service.check.expose' flag on group-level
service check definitions for services that are connect-enabled. This is a slight
deviation from the "magic" that Consul provides. With Consul, the 'expose' flag
exists on the connect.proxy stanza, which will then auto-generate expose paths
for every HTTP and gRPC service check associated with that connect-enabled
service.
A first attempt at providing similar magic for Nomad's Consul Connect integration
followed that pattern exactly, as seen in #7396. However, on reviewing the PR
we realized having the `expose` flag on the proxy stanza inseperably ties together
the automatic path generation with every HTTP/gRPC defined on the service. This
makes sense in Consul's context, because a service definition is reasonably
associated with a single "task". With Nomad's group level service definitions
however, there is a reasonable expectation that a service definition is more
abstractly representative of multiple services within the task group. In this
case, one would want to define checks of that service which concretely make HTTP
or gRPC requests to different underlying tasks. Such a model is not possible
with the course `proxy.expose` flag.
Instead, we now have the flag made available within the check definitions themselves.
By making the expose feature resolute to each check, it is possible to have
some HTTP/gRPC checks which make use of the envoy exposed paths, as well as
some HTTP/gRPC checks which make use of some orthongonal port-mapping to do
checks on some other task (or even some other bound port of the same task)
within the task group.
Given this example,
group "server-group" {
network {
mode = "bridge"
port "forchecks" {
to = -1
}
}
service {
name = "myserver"
port = 2000
connect {
sidecar_service {
}
}
check {
name = "mycheck-myserver"
type = "http"
port = "forchecks"
interval = "3s"
timeout = "2s"
method = "GET"
path = "/classic/responder/health"
expose = true
}
}
}
Nomad will automatically inject (via job endpoint mutator) the
extrapolated expose path configuration, i.e.
expose {
path {
path = "/classic/responder/health"
protocol = "http"
local_path_port = 2000
listener_port = "forchecks"
}
}
Documentation is coming in #7440 (needs updating, doing next)
Modifications to the `countdash` examples in https://github.com/hashicorp/demo-consul-101/pull/6
which will make the examples in the documentation actually runnable.
Will add some e2e tests based on the above when it becomes available.
2020-03-25 01:49:55 +00:00
|
|
|
{
|
|
|
|
"tg-service-check-expose.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("group_service_proxy_expose"),
|
|
|
|
Name: stringToPtr("group_service_proxy_expose"),
|
connect: enable automatic expose paths for individual group service checks
Part of #6120
Building on the support for enabling connect proxy paths in #7323, this change
adds the ability to configure the 'service.check.expose' flag on group-level
service check definitions for services that are connect-enabled. This is a slight
deviation from the "magic" that Consul provides. With Consul, the 'expose' flag
exists on the connect.proxy stanza, which will then auto-generate expose paths
for every HTTP and gRPC service check associated with that connect-enabled
service.
A first attempt at providing similar magic for Nomad's Consul Connect integration
followed that pattern exactly, as seen in #7396. However, on reviewing the PR
we realized having the `expose` flag on the proxy stanza inseperably ties together
the automatic path generation with every HTTP/gRPC defined on the service. This
makes sense in Consul's context, because a service definition is reasonably
associated with a single "task". With Nomad's group level service definitions
however, there is a reasonable expectation that a service definition is more
abstractly representative of multiple services within the task group. In this
case, one would want to define checks of that service which concretely make HTTP
or gRPC requests to different underlying tasks. Such a model is not possible
with the course `proxy.expose` flag.
Instead, we now have the flag made available within the check definitions themselves.
By making the expose feature resolute to each check, it is possible to have
some HTTP/gRPC checks which make use of the envoy exposed paths, as well as
some HTTP/gRPC checks which make use of some orthongonal port-mapping to do
checks on some other task (or even some other bound port of the same task)
within the task group.
Given this example,
group "server-group" {
network {
mode = "bridge"
port "forchecks" {
to = -1
}
}
service {
name = "myserver"
port = 2000
connect {
sidecar_service {
}
}
check {
name = "mycheck-myserver"
type = "http"
port = "forchecks"
interval = "3s"
timeout = "2s"
method = "GET"
path = "/classic/responder/health"
expose = true
}
}
}
Nomad will automatically inject (via job endpoint mutator) the
extrapolated expose path configuration, i.e.
expose {
path {
path = "/classic/responder/health"
protocol = "http"
local_path_port = 2000
listener_port = "forchecks"
}
}
Documentation is coming in #7440 (needs updating, doing next)
Modifications to the `countdash` examples in https://github.com/hashicorp/demo-consul-101/pull/6
which will make the examples in the documentation actually runnable.
Will add some e2e tests based on the above when it becomes available.
2020-03-25 01:49:55 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
connect: enable automatic expose paths for individual group service checks
Part of #6120
Building on the support for enabling connect proxy paths in #7323, this change
adds the ability to configure the 'service.check.expose' flag on group-level
service check definitions for services that are connect-enabled. This is a slight
deviation from the "magic" that Consul provides. With Consul, the 'expose' flag
exists on the connect.proxy stanza, which will then auto-generate expose paths
for every HTTP and gRPC service check associated with that connect-enabled
service.
A first attempt at providing similar magic for Nomad's Consul Connect integration
followed that pattern exactly, as seen in #7396. However, on reviewing the PR
we realized having the `expose` flag on the proxy stanza inseperably ties together
the automatic path generation with every HTTP/gRPC defined on the service. This
makes sense in Consul's context, because a service definition is reasonably
associated with a single "task". With Nomad's group level service definitions
however, there is a reasonable expectation that a service definition is more
abstractly representative of multiple services within the task group. In this
case, one would want to define checks of that service which concretely make HTTP
or gRPC requests to different underlying tasks. Such a model is not possible
with the course `proxy.expose` flag.
Instead, we now have the flag made available within the check definitions themselves.
By making the expose feature resolute to each check, it is possible to have
some HTTP/gRPC checks which make use of the envoy exposed paths, as well as
some HTTP/gRPC checks which make use of some orthongonal port-mapping to do
checks on some other task (or even some other bound port of the same task)
within the task group.
Given this example,
group "server-group" {
network {
mode = "bridge"
port "forchecks" {
to = -1
}
}
service {
name = "myserver"
port = 2000
connect {
sidecar_service {
}
}
check {
name = "mycheck-myserver"
type = "http"
port = "forchecks"
interval = "3s"
timeout = "2s"
method = "GET"
path = "/classic/responder/health"
expose = true
}
}
}
Nomad will automatically inject (via job endpoint mutator) the
extrapolated expose path configuration, i.e.
expose {
path {
path = "/classic/responder/health"
protocol = "http"
local_path_port = 2000
listener_port = "forchecks"
}
}
Documentation is coming in #7440 (needs updating, doing next)
Modifications to the `countdash` examples in https://github.com/hashicorp/demo-consul-101/pull/6
which will make the examples in the documentation actually runnable.
Will add some e2e tests based on the above when it becomes available.
2020-03-25 01:49:55 +00:00
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "example",
|
|
|
|
Connect: &api.ConsulConnect{
|
|
|
|
SidecarService: &api.ConsulSidecarService{
|
|
|
|
Proxy: &api.ConsulProxy{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Checks: []api.ServiceCheck{{
|
|
|
|
Name: "example-check1",
|
|
|
|
Expose: true,
|
|
|
|
}, {
|
|
|
|
Name: "example-check2",
|
|
|
|
Expose: false,
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-05-13 20:15:55 +00:00
|
|
|
{
|
|
|
|
"tg-service-connect-native.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("connect_native_service"),
|
|
|
|
Name: stringToPtr("connect_native_service"),
|
2020-05-13 20:15:55 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2020-05-13 20:15:55 +00:00
|
|
|
Services: []*api.Service{{
|
2020-06-22 17:55:59 +00:00
|
|
|
Name: "example",
|
|
|
|
TaskName: "task1",
|
2020-05-13 20:15:55 +00:00
|
|
|
Connect: &api.ConsulConnect{
|
2020-06-22 17:55:59 +00:00
|
|
|
Native: true,
|
2020-05-13 20:15:55 +00:00
|
|
|
},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
client: enable configuring enable_tag_override for services
Consul provides a feature of Service Definitions where the tags
associated with a service can be modified through the Catalog API,
overriding the value(s) configured in the agent's service configuration.
To enable this feature, the flag enable_tag_override must be configured
in the service definition.
Previously, Nomad did not allow configuring this flag, and thus the default
value of false was used. Now, it is configurable.
Because Nomad itself acts as a state machine around the the service definitions
of the tasks it manages, it's worth describing what happens when this feature
is enabled and why.
Consider the basic case where there is no Nomad, and your service is provided
to consul as a boring JSON file. The ultimate source of truth for the definition
of that service is the file, and is stored in the agent. Later, Consul performs
"anti-entropy" which synchronizes the Catalog (stored only the leaders). Then
with enable_tag_override=true, the tags field is available for "external"
modification through the Catalog API (rather than directly configuring the
service definition file, or using the Agent API). The important observation
is that if the service definition ever changes (i.e. the file is changed &
config reloaded OR the Agent API is used to modify the service), those
"external" tag values are thrown away, and the new service definition is
once again the source of truth.
In the Nomad case, Nomad itself is the source of truth over the Agent in
the same way the JSON file was the source of truth in the example above.
That means any time Nomad sets a new service definition, any externally
configured tags are going to be replaced. When does this happen? Only on
major lifecycle events, for example when a task is modified because of an
updated job spec from the 'nomad job run <existing>' command. Otherwise,
Nomad's periodic re-sync's with Consul will now no longer try to restore
the externally modified tag values (as long as enable_tag_override=true).
Fixes #2057
2020-02-07 21:22:19 +00:00
|
|
|
{
|
|
|
|
"tg-service-enable-tag-override.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("group_service_eto"),
|
|
|
|
Name: stringToPtr("group_service_eto"),
|
client: enable configuring enable_tag_override for services
Consul provides a feature of Service Definitions where the tags
associated with a service can be modified through the Catalog API,
overriding the value(s) configured in the agent's service configuration.
To enable this feature, the flag enable_tag_override must be configured
in the service definition.
Previously, Nomad did not allow configuring this flag, and thus the default
value of false was used. Now, it is configurable.
Because Nomad itself acts as a state machine around the the service definitions
of the tasks it manages, it's worth describing what happens when this feature
is enabled and why.
Consider the basic case where there is no Nomad, and your service is provided
to consul as a boring JSON file. The ultimate source of truth for the definition
of that service is the file, and is stored in the agent. Later, Consul performs
"anti-entropy" which synchronizes the Catalog (stored only the leaders). Then
with enable_tag_override=true, the tags field is available for "external"
modification through the Catalog API (rather than directly configuring the
service definition file, or using the Agent API). The important observation
is that if the service definition ever changes (i.e. the file is changed &
config reloaded OR the Agent API is used to modify the service), those
"external" tag values are thrown away, and the new service definition is
once again the source of truth.
In the Nomad case, Nomad itself is the source of truth over the Agent in
the same way the JSON file was the source of truth in the example above.
That means any time Nomad sets a new service definition, any externally
configured tags are going to be replaced. When does this happen? Only on
major lifecycle events, for example when a task is modified because of an
updated job spec from the 'nomad job run <existing>' command. Otherwise,
Nomad's periodic re-sync's with Consul will now no longer try to restore
the externally modified tag values (as long as enable_tag_override=true).
Fixes #2057
2020-02-07 21:22:19 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
client: enable configuring enable_tag_override for services
Consul provides a feature of Service Definitions where the tags
associated with a service can be modified through the Catalog API,
overriding the value(s) configured in the agent's service configuration.
To enable this feature, the flag enable_tag_override must be configured
in the service definition.
Previously, Nomad did not allow configuring this flag, and thus the default
value of false was used. Now, it is configurable.
Because Nomad itself acts as a state machine around the the service definitions
of the tasks it manages, it's worth describing what happens when this feature
is enabled and why.
Consider the basic case where there is no Nomad, and your service is provided
to consul as a boring JSON file. The ultimate source of truth for the definition
of that service is the file, and is stored in the agent. Later, Consul performs
"anti-entropy" which synchronizes the Catalog (stored only the leaders). Then
with enable_tag_override=true, the tags field is available for "external"
modification through the Catalog API (rather than directly configuring the
service definition file, or using the Agent API). The important observation
is that if the service definition ever changes (i.e. the file is changed &
config reloaded OR the Agent API is used to modify the service), those
"external" tag values are thrown away, and the new service definition is
once again the source of truth.
In the Nomad case, Nomad itself is the source of truth over the Agent in
the same way the JSON file was the source of truth in the example above.
That means any time Nomad sets a new service definition, any externally
configured tags are going to be replaced. When does this happen? Only on
major lifecycle events, for example when a task is modified because of an
updated job spec from the 'nomad job run <existing>' command. Otherwise,
Nomad's periodic re-sync's with Consul will now no longer try to restore
the externally modified tag values (as long as enable_tag_override=true).
Fixes #2057
2020-02-07 21:22:19 +00:00
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "example",
|
|
|
|
EnableTagOverride: true,
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-01-16 15:44:40 +00:00
|
|
|
{
|
|
|
|
"tg-scaling-policy.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("elastic"),
|
|
|
|
Name: stringToPtr("elastic"),
|
2020-01-16 15:44:40 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2020-01-16 15:44:40 +00:00
|
|
|
Scaling: &api.ScalingPolicy{
|
2020-09-09 22:30:40 +00:00
|
|
|
Type: "horizontal",
|
|
|
|
Min: int64ToPtr(5),
|
|
|
|
Max: int64ToPtr(100),
|
2020-01-16 15:44:40 +00:00
|
|
|
Policy: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
"b": true,
|
|
|
|
"val": 5,
|
|
|
|
"f": .1,
|
2020-10-26 15:24:30 +00:00
|
|
|
|
|
|
|
"check": []map[string]interface{}{
|
|
|
|
{"foo": []map[string]interface{}{
|
|
|
|
{"query": "some_query"},
|
|
|
|
}},
|
|
|
|
},
|
2020-01-16 15:44:40 +00:00
|
|
|
},
|
2020-09-03 11:34:04 +00:00
|
|
|
Enabled: boolToPtr(false),
|
2020-01-16 15:44:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-09-09 22:30:40 +00:00
|
|
|
{
|
|
|
|
"task-scaling-policy.hcl",
|
|
|
|
&api.Job{
|
|
|
|
ID: stringToPtr("foo"),
|
|
|
|
Name: stringToPtr("foo"),
|
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
|
|
|
Name: stringToPtr("bar"),
|
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Driver: "docker",
|
|
|
|
ScalingPolicies: []*api.ScalingPolicy{
|
|
|
|
{
|
|
|
|
Type: "vertical_cpu",
|
|
|
|
Target: nil,
|
|
|
|
Min: int64ToPtr(50),
|
|
|
|
Max: int64ToPtr(1000),
|
|
|
|
Policy: map[string]interface{}{
|
|
|
|
"test": "cpu",
|
|
|
|
},
|
|
|
|
Enabled: boolToPtr(true),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "vertical_mem",
|
|
|
|
Target: nil,
|
|
|
|
Min: int64ToPtr(128),
|
|
|
|
Max: int64ToPtr(1024),
|
|
|
|
Policy: map[string]interface{}{
|
|
|
|
"test": "mem",
|
|
|
|
},
|
|
|
|
Enabled: boolToPtr(false),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-07-28 20:12:08 +00:00
|
|
|
{
|
|
|
|
"tg-service-connect-gateway-ingress.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("connect_gateway_ingress"),
|
|
|
|
Name: stringToPtr("connect_gateway_ingress"),
|
2020-07-28 20:12:08 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2020-07-28 20:12:08 +00:00
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "ingress-gateway-service",
|
|
|
|
Connect: &api.ConsulConnect{
|
|
|
|
Gateway: &api.ConsulGateway{
|
|
|
|
Proxy: &api.ConsulGatewayProxy{
|
2020-09-03 11:34:04 +00:00
|
|
|
ConnectTimeout: timeToPtr(3 * time.Second),
|
2020-07-28 20:12:08 +00:00
|
|
|
EnvoyGatewayBindTaggedAddresses: true,
|
|
|
|
EnvoyGatewayBindAddresses: map[string]*api.ConsulGatewayBindAddress{
|
2020-10-21 14:07:31 +00:00
|
|
|
"listener1": {Name: "listener1", Address: "10.0.0.1", Port: 8888},
|
|
|
|
"listener2": {Name: "listener2", Address: "10.0.0.2", Port: 8889},
|
2020-07-28 20:12:08 +00:00
|
|
|
},
|
|
|
|
EnvoyGatewayNoDefaultBind: true,
|
|
|
|
Config: map[string]interface{}{"foo": "bar"},
|
|
|
|
},
|
|
|
|
Ingress: &api.ConsulIngressConfigEntry{
|
|
|
|
TLS: &api.ConsulGatewayTLSConfig{
|
2022-06-02 22:43:58 +00:00
|
|
|
Enabled: true,
|
|
|
|
TLSMinVersion: "TLSv1_2",
|
|
|
|
CipherSuites: []string{"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"},
|
2020-07-28 20:12:08 +00:00
|
|
|
},
|
|
|
|
Listeners: []*api.ConsulIngressListener{{
|
|
|
|
Port: 8001,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []*api.ConsulIngressService{{
|
|
|
|
Name: "service1",
|
|
|
|
Hosts: []string{
|
|
|
|
"127.0.0.1:8001",
|
|
|
|
"[::1]:8001",
|
|
|
|
}}, {
|
|
|
|
Name: "service2",
|
|
|
|
Hosts: []string{
|
|
|
|
"10.0.0.1:8001",
|
|
|
|
}},
|
|
|
|
}}, {
|
|
|
|
Port: 8080,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []*api.ConsulIngressService{{
|
|
|
|
Name: "nginx",
|
|
|
|
Hosts: []string{
|
|
|
|
"2.2.2.2:8080",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2021-06-22 22:47:00 +00:00
|
|
|
{
|
|
|
|
"tg-service-connect-gateway-terminating.hcl",
|
|
|
|
&api.Job{
|
|
|
|
ID: stringToPtr("connect_gateway_terminating"),
|
|
|
|
Name: stringToPtr("connect_gateway_terminating"),
|
|
|
|
TaskGroups: []*api.TaskGroup{{
|
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "terminating-gateway-service",
|
|
|
|
Connect: &api.ConsulConnect{
|
|
|
|
Gateway: &api.ConsulGateway{
|
|
|
|
Proxy: &api.ConsulGatewayProxy{
|
|
|
|
ConnectTimeout: timeToPtr(3 * time.Second),
|
|
|
|
EnvoyGatewayBindTaggedAddresses: true,
|
|
|
|
EnvoyGatewayBindAddresses: map[string]*api.ConsulGatewayBindAddress{
|
|
|
|
"listener1": {Name: "listener1", Address: "10.0.0.1", Port: 8888},
|
|
|
|
"listener2": {Name: "listener2", Address: "10.0.0.2", Port: 8889},
|
|
|
|
},
|
|
|
|
EnvoyGatewayNoDefaultBind: true,
|
2021-07-22 19:40:03 +00:00
|
|
|
EnvoyDNSDiscoveryType: "LOGICAL_DNS",
|
2021-06-22 22:47:00 +00:00
|
|
|
Config: map[string]interface{}{"foo": "bar"},
|
|
|
|
},
|
|
|
|
Terminating: &api.ConsulTerminatingConfigEntry{
|
|
|
|
Services: []*api.ConsulLinkedService{{
|
|
|
|
Name: "service1",
|
|
|
|
CAFile: "ca.pem",
|
|
|
|
CertFile: "cert.pem",
|
|
|
|
KeyFile: "key.pem",
|
|
|
|
}, {
|
|
|
|
Name: "service2",
|
|
|
|
SNI: "myhost",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2021-07-22 19:57:02 +00:00
|
|
|
{
|
|
|
|
"tg-service-connect-gateway-mesh.hcl",
|
|
|
|
&api.Job{
|
|
|
|
ID: stringToPtr("connect_gateway_mesh"),
|
|
|
|
Name: stringToPtr("connect_gateway_mesh"),
|
|
|
|
TaskGroups: []*api.TaskGroup{{
|
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Services: []*api.Service{{
|
|
|
|
Name: "mesh-gateway-service",
|
|
|
|
Connect: &api.ConsulConnect{
|
|
|
|
Gateway: &api.ConsulGateway{
|
|
|
|
Proxy: &api.ConsulGatewayProxy{
|
|
|
|
Config: map[string]interface{}{"foo": "bar"},
|
|
|
|
},
|
|
|
|
Mesh: &api.ConsulMeshConfigEntry{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-04-23 12:37:45 +00:00
|
|
|
{
|
|
|
|
"tg-scaling-policy-minimal.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("elastic"),
|
|
|
|
Name: stringToPtr("elastic"),
|
2020-04-23 12:37:45 +00:00
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
2020-09-03 11:34:04 +00:00
|
|
|
Name: stringToPtr("group"),
|
2020-04-23 12:37:45 +00:00
|
|
|
Scaling: &api.ScalingPolicy{
|
2020-09-09 22:30:40 +00:00
|
|
|
Type: "horizontal",
|
2020-04-23 12:37:45 +00:00
|
|
|
Min: nil,
|
2020-09-03 11:34:04 +00:00
|
|
|
Max: int64ToPtr(10),
|
2020-04-23 12:37:45 +00:00
|
|
|
Policy: nil,
|
|
|
|
Enabled: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-07-04 19:32:37 +00:00
|
|
|
{
|
|
|
|
"tg-scaling-policy-missing-max.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
2020-04-23 12:37:45 +00:00
|
|
|
{
|
|
|
|
"tg-scaling-policy-multi-policy.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
2020-09-09 22:30:40 +00:00
|
|
|
{
|
|
|
|
"tg-scaling-policy-with-label.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"tg-scaling-policy-invalid-type.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"task-scaling-policy-missing-name.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"task-scaling-policy-multi-name.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"task-scaling-policy-multi-cpu.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"task-scaling-policy-invalid-type.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"task-scaling-policy-invalid-resource.hcl",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
2021-11-03 17:49:32 +00:00
|
|
|
{
|
|
|
|
"consul-namespace.hcl",
|
|
|
|
&api.Job{
|
|
|
|
ID: stringToPtr("consul-namespace"),
|
|
|
|
Name: stringToPtr("consul-namespace"),
|
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Consul: &api.Consul{
|
|
|
|
Namespace: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2020-06-09 17:56:58 +00:00
|
|
|
{
|
|
|
|
"multiregion.hcl",
|
|
|
|
&api.Job{
|
2020-09-03 11:34:04 +00:00
|
|
|
ID: stringToPtr("multiregion_job"),
|
|
|
|
Name: stringToPtr("multiregion_job"),
|
2020-06-09 17:56:58 +00:00
|
|
|
Multiregion: &api.Multiregion{
|
|
|
|
Strategy: &api.MultiregionStrategy{
|
2020-09-03 11:34:04 +00:00
|
|
|
MaxParallel: intToPtr(1),
|
|
|
|
OnFailure: stringToPtr("fail_all"),
|
2020-06-09 17:56:58 +00:00
|
|
|
},
|
|
|
|
Regions: []*api.MultiregionRegion{
|
|
|
|
{
|
2020-06-15 14:05:31 +00:00
|
|
|
Name: "west",
|
2020-09-03 11:34:04 +00:00
|
|
|
Count: intToPtr(2),
|
2020-06-09 17:56:58 +00:00
|
|
|
Datacenters: []string{"west-1"},
|
|
|
|
Meta: map[string]string{"region_code": "W"},
|
|
|
|
},
|
|
|
|
{
|
2020-06-15 14:05:31 +00:00
|
|
|
Name: "east",
|
2020-09-03 11:34:04 +00:00
|
|
|
Count: intToPtr(1),
|
2020-06-09 17:56:58 +00:00
|
|
|
Datacenters: []string{"east-1", "east-2"},
|
|
|
|
Meta: map[string]string{"region_code": "E"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2021-07-26 15:25:28 +00:00
|
|
|
{
|
|
|
|
"resources-cores.hcl",
|
|
|
|
&api.Job{
|
|
|
|
ID: stringToPtr("cores-test"),
|
|
|
|
Name: stringToPtr("cores-test"),
|
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
|
|
|
Count: intToPtr(5),
|
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "task",
|
|
|
|
Driver: "docker",
|
|
|
|
Resources: &api.Resources{
|
|
|
|
Cores: intToPtr(4),
|
|
|
|
MemoryMB: intToPtr(128),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2022-03-14 09:00:53 +00:00
|
|
|
{
|
|
|
|
"service-provider.hcl",
|
|
|
|
&api.Job{
|
|
|
|
ID: stringToPtr("service-provider"),
|
|
|
|
Name: stringToPtr("service-provider"),
|
|
|
|
TaskGroups: []*api.TaskGroup{
|
|
|
|
{
|
|
|
|
Count: intToPtr(5),
|
|
|
|
Name: stringToPtr("group"),
|
|
|
|
Tasks: []*api.Task{
|
|
|
|
{
|
|
|
|
Name: "task",
|
|
|
|
Driver: "docker",
|
|
|
|
Services: []*api.Service{
|
|
|
|
{
|
|
|
|
Name: "service-provider",
|
|
|
|
Provider: "nomad",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2015-09-15 00:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2021-05-07 16:10:26 +00:00
|
|
|
t.Run(tc.File, func(t *testing.T) {
|
|
|
|
t.Logf("Testing parse: %s", tc.File)
|
2015-09-15 00:43:42 +00:00
|
|
|
|
2021-05-07 16:10:26 +00:00
|
|
|
path, err := filepath.Abs(filepath.Join("./test-fixtures", tc.File))
|
|
|
|
require.NoError(t, err)
|
2017-02-22 20:30:05 +00:00
|
|
|
|
2021-05-07 16:10:26 +00:00
|
|
|
actual, err := ParseFile(path)
|
|
|
|
if tc.Err {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, tc.Result, actual)
|
2017-02-22 20:30:05 +00:00
|
|
|
}
|
2021-05-07 16:10:26 +00:00
|
|
|
})
|
2015-09-15 00:43:42 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-23 20:44:08 +00:00
|
|
|
|
|
|
|
func TestBadPorts(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2015-09-23 20:44:08 +00:00
|
|
|
path, err := filepath.Abs(filepath.Join("./test-fixtures", "bad-ports.hcl"))
|
|
|
|
if err != nil {
|
2016-04-09 22:38:42 +00:00
|
|
|
t.Fatalf("Can't get absolute path for file: %s", err)
|
2015-09-23 20:44:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = ParseFile(path)
|
|
|
|
|
2015-11-15 08:10:48 +00:00
|
|
|
if !strings.Contains(err.Error(), errPortLabel.Error()) {
|
|
|
|
t.Fatalf("\nExpected error\n %s\ngot\n %v", errPortLabel, err)
|
2015-09-23 20:44:08 +00:00
|
|
|
}
|
2015-09-26 01:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOverlappingPorts(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2015-09-26 01:59:17 +00:00
|
|
|
path, err := filepath.Abs(filepath.Join("./test-fixtures", "overlapping-ports.hcl"))
|
|
|
|
if err != nil {
|
2015-11-18 01:12:21 +00:00
|
|
|
t.Fatalf("Can't get absolute path for file: %s", err)
|
2015-09-26 01:59:17 +00:00
|
|
|
}
|
2015-09-23 20:44:08 +00:00
|
|
|
|
2015-09-26 01:59:17 +00:00
|
|
|
_, err = ParseFile(path)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expected an error")
|
|
|
|
}
|
|
|
|
|
2015-12-18 20:33:38 +00:00
|
|
|
if !strings.Contains(err.Error(), "found a port label collision") {
|
2015-09-26 01:59:17 +00:00
|
|
|
t.Fatalf("Expected collision error; got %v", err)
|
|
|
|
}
|
2015-09-23 20:44:08 +00:00
|
|
|
}
|
2015-11-18 01:06:29 +00:00
|
|
|
|
2016-03-10 18:16:35 +00:00
|
|
|
func TestIncorrectKey(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2016-03-10 18:16:35 +00:00
|
|
|
path, err := filepath.Abs(filepath.Join("./test-fixtures", "basic_wrong_key.hcl"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't get absolute path for file: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = ParseFile(path)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expected an error")
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:18:53 +00:00
|
|
|
if !strings.Contains(err.Error(), "* group: 'binsl', task: 'binstore', service (0): 'foo', check -> invalid key: nterval") {
|
2017-02-22 20:30:05 +00:00
|
|
|
t.Fatalf("Expected key error; got %v", err)
|
2016-03-10 18:16:35 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-08 10:26:28 +00:00
|
|
|
|
|
|
|
// TestPortParsing validates that the removal of the mapstructure tags on the
|
|
|
|
// Port struct don't cause issues with HCL 1 parsing.
|
|
|
|
//
|
|
|
|
// TODO: in the future, see if we need `mapstructure` tags on any of the API
|
|
|
|
func TestPortParsing(t *testing.T) {
|
|
|
|
ci.Parallel(t)
|
|
|
|
|
|
|
|
var err error
|
|
|
|
var path string
|
|
|
|
var job *api.Job
|
|
|
|
|
|
|
|
path, err = filepath.Abs(filepath.Join("./test-fixtures", "parse-ports.hcl"))
|
|
|
|
require.NoError(t, err, "Can't get absolute path for file: parse-ports.hcl")
|
|
|
|
|
|
|
|
job, err = ParseFile(path)
|
|
|
|
require.NoError(t, err, "cannot parse job")
|
|
|
|
require.NotNil(t, job)
|
|
|
|
require.Len(t, job.TaskGroups, 1)
|
|
|
|
require.Len(t, job.TaskGroups[0].Networks, 1)
|
|
|
|
require.Len(t, job.TaskGroups[0].Networks[0].ReservedPorts, 1)
|
|
|
|
require.Len(t, job.TaskGroups[0].Networks[0].DynamicPorts, 1)
|
|
|
|
require.Equal(t, 9000, job.TaskGroups[0].Networks[0].ReservedPorts[0].Value)
|
|
|
|
require.Equal(t, 0, job.TaskGroups[0].Networks[0].DynamicPorts[0].Value)
|
|
|
|
}
|