2015-08-11 21:27:14 +00:00
|
|
|
package mock
|
|
|
|
|
2015-10-31 01:34:23 +00:00
|
|
|
import (
|
2017-08-07 21:21:00 +00:00
|
|
|
"fmt"
|
2022-01-15 01:09:14 +00:00
|
|
|
"math/rand"
|
2015-10-31 01:34:23 +00:00
|
|
|
"time"
|
2015-11-13 01:47:51 +00:00
|
|
|
|
2020-07-28 20:12:08 +00:00
|
|
|
"github.com/hashicorp/nomad/helper"
|
2020-12-11 15:57:13 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/envoy"
|
2017-09-29 16:58:48 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
2015-11-13 01:47:51 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2018-10-15 22:15:46 +00:00
|
|
|
psstructs "github.com/hashicorp/nomad/plugins/shared/structs"
|
2015-10-31 01:34:23 +00:00
|
|
|
)
|
2015-08-11 21:27:14 +00:00
|
|
|
|
|
|
|
func Node() *structs.Node {
|
|
|
|
node := &structs.Node{
|
2017-09-29 16:58:48 +00:00
|
|
|
ID: uuid.Generate(),
|
|
|
|
SecretID: uuid.Generate(),
|
2015-08-11 21:27:14 +00:00
|
|
|
Datacenter: "dc1",
|
|
|
|
Name: "foobar",
|
2019-08-29 12:41:32 +00:00
|
|
|
Drivers: map[string]*structs.DriverInfo{
|
|
|
|
"exec": {
|
|
|
|
Detected: true,
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
"mock_driver": {
|
|
|
|
Detected: true,
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
Attributes: map[string]string{
|
2018-03-28 18:57:47 +00:00
|
|
|
"kernel.name": "linux",
|
|
|
|
"arch": "x86",
|
|
|
|
"nomad.version": "0.5.0",
|
|
|
|
"driver.exec": "1",
|
|
|
|
"driver.mock_driver": "1",
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
2018-10-03 16:47:18 +00:00
|
|
|
|
|
|
|
// TODO Remove once clientv2 gets merged
|
2015-08-11 21:27:14 +00:00
|
|
|
Resources: &structs.Resources{
|
2015-09-23 18:14:32 +00:00
|
|
|
CPU: 4000,
|
2015-08-11 21:27:14 +00:00
|
|
|
MemoryMB: 8192,
|
|
|
|
DiskMB: 100 * 1024,
|
|
|
|
},
|
|
|
|
Reserved: &structs.Resources{
|
2015-09-23 18:14:32 +00:00
|
|
|
CPU: 100,
|
2015-08-11 21:27:14 +00:00
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
2015-09-13 02:34:46 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-09-13 02:34:46 +00:00
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
2017-12-08 22:50:06 +00:00
|
|
|
ReservedPorts: []structs.Port{{Label: "ssh", Value: 22}},
|
2015-09-13 02:34:46 +00:00
|
|
|
MBits: 1,
|
|
|
|
},
|
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
2018-10-03 16:47:18 +00:00
|
|
|
|
|
|
|
NodeResources: &structs.NodeResources{
|
|
|
|
Cpu: structs.NodeCpuResources{
|
2018-10-04 21:33:09 +00:00
|
|
|
CpuShares: 4000,
|
2018-10-03 16:47:18 +00:00
|
|
|
},
|
|
|
|
Memory: structs.NodeMemoryResources{
|
|
|
|
MemoryMB: 8192,
|
|
|
|
},
|
|
|
|
Disk: structs.NodeDiskResources{
|
|
|
|
DiskMB: 100 * 1024,
|
|
|
|
},
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
2020-05-15 15:09:01 +00:00
|
|
|
Mode: "host",
|
2018-10-03 16:47:18 +00:00
|
|
|
Device: "eth0",
|
|
|
|
CIDR: "192.168.0.100/32",
|
|
|
|
MBits: 1000,
|
|
|
|
},
|
|
|
|
},
|
2020-06-19 18:22:24 +00:00
|
|
|
NodeNetworks: []*structs.NodeNetworkResource{
|
|
|
|
{
|
|
|
|
Mode: "host",
|
|
|
|
Device: "eth0",
|
|
|
|
Speed: 1000,
|
2020-08-28 17:15:26 +00:00
|
|
|
Addresses: []structs.NodeNetworkAddress{
|
|
|
|
{
|
|
|
|
Alias: "default",
|
|
|
|
Address: "192.168.0.100",
|
|
|
|
Family: structs.NodeNetworkAF_IPv4,
|
|
|
|
},
|
|
|
|
},
|
2020-06-19 18:22:24 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-03 16:47:18 +00:00
|
|
|
},
|
|
|
|
ReservedResources: &structs.NodeReservedResources{
|
|
|
|
Cpu: structs.NodeReservedCpuResources{
|
2018-10-04 21:33:09 +00:00
|
|
|
CpuShares: 100,
|
2018-10-03 16:47:18 +00:00
|
|
|
},
|
|
|
|
Memory: structs.NodeReservedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
Disk: structs.NodeReservedDiskResources{
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
},
|
|
|
|
Networks: structs.NodeReservedNetworkResources{
|
|
|
|
ReservedHostPorts: "22",
|
|
|
|
},
|
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
Links: map[string]string{
|
|
|
|
"consul": "foobar.dc1",
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
2016-03-28 19:25:16 +00:00
|
|
|
"pci-dss": "true",
|
|
|
|
"database": "mysql",
|
|
|
|
"version": "5.6",
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
2018-02-21 18:58:04 +00:00
|
|
|
NodeClass: "linux-medium-pci",
|
|
|
|
Status: structs.NodeStatusReady,
|
|
|
|
SchedulingEligibility: structs.NodeSchedulingEligible,
|
2015-08-11 21:27:14 +00:00
|
|
|
}
|
2016-01-27 01:34:41 +00:00
|
|
|
node.ComputeClass()
|
2015-08-11 21:27:14 +00:00
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
2021-02-11 15:40:59 +00:00
|
|
|
func DrainNode() *structs.Node {
|
|
|
|
node := Node()
|
|
|
|
node.DrainStrategy = &structs.DrainStrategy{
|
|
|
|
DrainSpec: structs.DrainSpec{},
|
|
|
|
}
|
2021-03-26 18:57:59 +00:00
|
|
|
node.Canonicalize()
|
2021-02-11 15:40:59 +00:00
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
2018-10-17 18:04:54 +00:00
|
|
|
// NvidiaNode returns a node with two instances of an Nvidia GPU
|
2018-10-15 22:15:46 +00:00
|
|
|
func NvidiaNode() *structs.Node {
|
|
|
|
n := Node()
|
|
|
|
n.NodeResources.Devices = []*structs.NodeDeviceResource{
|
|
|
|
{
|
|
|
|
Type: "gpu",
|
|
|
|
Vendor: "nvidia",
|
|
|
|
Name: "1080ti",
|
|
|
|
Attributes: map[string]*psstructs.Attribute{
|
|
|
|
"memory": psstructs.NewIntAttribute(11, psstructs.UnitGiB),
|
|
|
|
"cuda_cores": psstructs.NewIntAttribute(3584, ""),
|
|
|
|
"graphics_clock": psstructs.NewIntAttribute(1480, psstructs.UnitMHz),
|
|
|
|
"memory_bandwidth": psstructs.NewIntAttribute(11, psstructs.UnitGBPerS),
|
|
|
|
},
|
|
|
|
Instances: []*structs.NodeDevice{
|
|
|
|
{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
Healthy: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
n.ComputeClass()
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
2018-04-12 18:45:38 +00:00
|
|
|
func HCL() string {
|
|
|
|
return `job "my-job" {
|
|
|
|
datacenters = ["dc1"]
|
|
|
|
type = "service"
|
|
|
|
constraint {
|
|
|
|
attribute = "${attr.kernel.name}"
|
|
|
|
value = "linux"
|
|
|
|
}
|
|
|
|
|
|
|
|
group "web" {
|
|
|
|
count = 10
|
|
|
|
restart {
|
|
|
|
attempts = 3
|
|
|
|
interval = "10m"
|
|
|
|
delay = "1m"
|
|
|
|
mode = "delay"
|
|
|
|
}
|
|
|
|
task "web" {
|
|
|
|
driver = "exec"
|
|
|
|
config {
|
|
|
|
command = "/bin/date"
|
|
|
|
}
|
|
|
|
resources {
|
|
|
|
cpu = 500
|
|
|
|
memory = 256
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2020-10-09 21:31:38 +00:00
|
|
|
func SystemBatchJob() *structs.Job {
|
|
|
|
job := &structs.Job{
|
|
|
|
Region: "global",
|
|
|
|
ID: fmt.Sprintf("mock-sysbatch-%s", uuid.Short()),
|
|
|
|
Name: "my-sysbatch",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
Type: structs.JobTypeSysBatch,
|
|
|
|
Priority: 10,
|
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Constraints: []*structs.Constraint{
|
|
|
|
{
|
|
|
|
LTarget: "${attr.kernel.name}",
|
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskGroups: []*structs.TaskGroup{{
|
|
|
|
Count: 1,
|
|
|
|
Name: "pinger",
|
|
|
|
Tasks: []*structs.Task{{
|
|
|
|
Name: "ping-example",
|
|
|
|
Driver: "exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "/usr/bin/ping",
|
|
|
|
"args": []string{"-c", "5", "example.com"},
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
|
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
Version: 0,
|
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
JobModifyIndex: 99,
|
|
|
|
}
|
|
|
|
job.Canonicalize()
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2015-08-11 21:27:14 +00:00
|
|
|
func Job() *structs.Job {
|
|
|
|
job := &structs.Job{
|
2015-09-15 18:12:46 +00:00
|
|
|
Region: "global",
|
2018-03-28 18:57:47 +00:00
|
|
|
ID: fmt.Sprintf("mock-service-%s", uuid.Generate()),
|
2015-08-14 05:07:01 +00:00
|
|
|
Name: "my-job",
|
2017-09-07 23:56:15 +00:00
|
|
|
Namespace: structs.DefaultNamespace,
|
2015-08-14 05:07:01 +00:00
|
|
|
Type: structs.JobTypeService,
|
|
|
|
Priority: 50,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
2015-08-11 21:27:14 +00:00
|
|
|
Constraints: []*structs.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2016-02-05 00:50:20 +00:00
|
|
|
LTarget: "${attr.kernel.name}",
|
2015-08-11 21:27:14 +00:00
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-08-11 21:27:14 +00:00
|
|
|
Name: "web",
|
|
|
|
Count: 10,
|
2016-09-14 22:43:42 +00:00
|
|
|
EphemeralDisk: &structs.EphemeralDisk{
|
|
|
|
SizeMB: 150,
|
2016-08-25 17:27:19 +00:00
|
|
|
},
|
2015-10-31 01:34:23 +00:00
|
|
|
RestartPolicy: &structs.RestartPolicy{
|
2016-02-02 23:08:07 +00:00
|
|
|
Attempts: 3,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 1 * time.Minute,
|
|
|
|
Mode: structs.RestartPolicyModeDelay,
|
2015-10-31 01:34:23 +00:00
|
|
|
},
|
2018-01-14 22:47:21 +00:00
|
|
|
ReschedulePolicy: &structs.ReschedulePolicy{
|
2018-02-22 23:43:07 +00:00
|
|
|
Attempts: 2,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 5 * time.Second,
|
2018-03-26 19:45:09 +00:00
|
|
|
DelayFunction: "constant",
|
2018-01-14 22:47:21 +00:00
|
|
|
},
|
2018-01-24 00:47:00 +00:00
|
|
|
Migrate: structs.DefaultMigrateStrategy(),
|
2020-08-28 16:38:30 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
2020-08-28 17:15:26 +00:00
|
|
|
Mode: "host",
|
2020-08-28 16:38:30 +00:00
|
|
|
DynamicPorts: []structs.Port{
|
|
|
|
{Label: "http"},
|
|
|
|
{Label: "admin"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
Tasks: []*structs.Task{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-08-11 21:27:14 +00:00
|
|
|
Name: "web",
|
2015-08-29 23:24:01 +00:00
|
|
|
Driver: "exec",
|
2015-11-14 02:09:42 +00:00
|
|
|
Config: map[string]interface{}{
|
2015-08-29 23:24:01 +00:00
|
|
|
"command": "/bin/date",
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
2015-10-23 21:52:06 +00:00
|
|
|
Env: map[string]string{
|
|
|
|
"FOO": "bar",
|
|
|
|
},
|
2016-06-12 23:36:49 +00:00
|
|
|
Services: []*structs.Service{
|
2015-11-27 03:26:00 +00:00
|
|
|
{
|
|
|
|
Name: "${TASK}-frontend",
|
|
|
|
PortLabel: "http",
|
2016-03-26 19:49:49 +00:00
|
|
|
Tags: []string{"pci:${meta.pci-dss}", "datacenter:${node.datacenter}"},
|
2016-03-28 19:25:16 +00:00
|
|
|
Checks: []*structs.ServiceCheck{
|
|
|
|
{
|
|
|
|
Name: "check-table",
|
|
|
|
Type: structs.ServiceCheckScript,
|
2016-03-28 21:36:51 +00:00
|
|
|
Command: "/usr/local/check-table-${meta.database}",
|
2016-03-28 19:25:16 +00:00
|
|
|
Args: []string{"${meta.version}"},
|
|
|
|
Interval: 30 * time.Second,
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
2015-11-27 03:26:00 +00:00
|
|
|
},
|
2015-12-15 18:43:56 +00:00
|
|
|
{
|
|
|
|
Name: "${TASK}-admin",
|
2017-12-08 22:50:06 +00:00
|
|
|
PortLabel: "admin",
|
2015-12-15 18:43:56 +00:00
|
|
|
},
|
2015-11-27 03:26:00 +00:00
|
|
|
},
|
2016-02-11 01:46:35 +00:00
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
2015-08-11 21:27:14 +00:00
|
|
|
Resources: &structs.Resources{
|
2015-09-23 18:14:32 +00:00
|
|
|
CPU: 500,
|
2019-09-02 17:30:09 +00:00
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"elb_check_type": "http",
|
|
|
|
"elb_check_interval": "30s",
|
|
|
|
"elb_check_min": "3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
2020-01-07 19:50:57 +00:00
|
|
|
},
|
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
Version: 0,
|
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
JobModifyIndex: 99,
|
|
|
|
}
|
|
|
|
job.Canonicalize()
|
|
|
|
return job
|
|
|
|
}
|
2020-01-09 19:34:46 +00:00
|
|
|
|
2022-01-19 00:40:44 +00:00
|
|
|
func MultiTaskGroupJob() *structs.Job {
|
|
|
|
job := Job()
|
|
|
|
apiTaskGroup := &structs.TaskGroup{
|
|
|
|
Name: "api",
|
|
|
|
Count: 10,
|
|
|
|
EphemeralDisk: &structs.EphemeralDisk{
|
|
|
|
SizeMB: 150,
|
|
|
|
},
|
|
|
|
RestartPolicy: &structs.RestartPolicy{
|
|
|
|
Attempts: 3,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 1 * time.Minute,
|
|
|
|
Mode: structs.RestartPolicyModeDelay,
|
|
|
|
},
|
|
|
|
ReschedulePolicy: &structs.ReschedulePolicy{
|
|
|
|
Attempts: 2,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 5 * time.Second,
|
|
|
|
DelayFunction: "constant",
|
|
|
|
},
|
|
|
|
Migrate: structs.DefaultMigrateStrategy(),
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Mode: "host",
|
|
|
|
DynamicPorts: []structs.Port{
|
|
|
|
{Label: "http"},
|
|
|
|
{Label: "admin"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Tasks: []*structs.Task{
|
|
|
|
{
|
|
|
|
Name: "api",
|
|
|
|
Driver: "exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "/bin/date",
|
|
|
|
},
|
|
|
|
Env: map[string]string{
|
|
|
|
"FOO": "bar",
|
|
|
|
},
|
|
|
|
Services: []*structs.Service{
|
|
|
|
{
|
|
|
|
Name: "${TASK}-backend",
|
|
|
|
PortLabel: "http",
|
|
|
|
Tags: []string{"pci:${meta.pci-dss}", "datacenter:${node.datacenter}"},
|
|
|
|
Checks: []*structs.ServiceCheck{
|
|
|
|
{
|
|
|
|
Name: "check-table",
|
|
|
|
Type: structs.ServiceCheckScript,
|
|
|
|
Command: "/usr/local/check-table-${meta.database}",
|
|
|
|
Args: []string{"${meta.version}"},
|
|
|
|
Interval: 30 * time.Second,
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "${TASK}-admin",
|
|
|
|
PortLabel: "admin",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"elb_check_type": "http",
|
|
|
|
"elb_check_interval": "30s",
|
|
|
|
"elb_check_min": "3",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
job.TaskGroups = append(job.TaskGroups, apiTaskGroup)
|
|
|
|
job.Canonicalize()
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2020-01-09 23:43:00 +00:00
|
|
|
func LifecycleSideTask(resources structs.Resources, i int) *structs.Task {
|
2020-01-09 19:34:46 +00:00
|
|
|
return &structs.Task{
|
2020-01-29 02:03:26 +00:00
|
|
|
Name: fmt.Sprintf("side-%d", i),
|
2020-01-09 19:34:46 +00:00
|
|
|
Driver: "exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "/bin/date",
|
|
|
|
},
|
|
|
|
Lifecycle: &structs.TaskLifecycleConfig{
|
2020-03-02 19:12:16 +00:00
|
|
|
Hook: structs.TaskLifecycleHookPrestart,
|
|
|
|
Sidecar: true,
|
2020-01-09 19:34:46 +00:00
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &resources,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 23:43:00 +00:00
|
|
|
func LifecycleInitTask(resources structs.Resources, i int) *structs.Task {
|
2020-01-09 19:34:46 +00:00
|
|
|
return &structs.Task{
|
2020-01-29 02:03:26 +00:00
|
|
|
Name: fmt.Sprintf("init-%d", i),
|
2020-01-09 19:34:46 +00:00
|
|
|
Driver: "exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "/bin/date",
|
|
|
|
},
|
|
|
|
Lifecycle: &structs.TaskLifecycleConfig{
|
2020-03-02 19:12:16 +00:00
|
|
|
Hook: structs.TaskLifecycleHookPrestart,
|
|
|
|
Sidecar: false,
|
2020-01-09 19:34:46 +00:00
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &resources,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 23:43:00 +00:00
|
|
|
func LifecycleMainTask(resources structs.Resources, i int) *structs.Task {
|
2020-01-09 19:34:46 +00:00
|
|
|
return &structs.Task{
|
2020-01-29 02:03:26 +00:00
|
|
|
Name: fmt.Sprintf("main-%d", i),
|
2020-01-09 19:34:46 +00:00
|
|
|
Driver: "exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "/bin/date",
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &resources,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func VariableLifecycleJob(resources structs.Resources, main int, init int, side int) *structs.Job {
|
|
|
|
tasks := []*structs.Task{}
|
|
|
|
for i := 0; i < main; i++ {
|
2020-01-09 23:43:00 +00:00
|
|
|
tasks = append(tasks, LifecycleMainTask(resources, i))
|
2020-01-09 19:34:46 +00:00
|
|
|
}
|
|
|
|
for i := 0; i < init; i++ {
|
2020-01-09 23:43:00 +00:00
|
|
|
tasks = append(tasks, LifecycleInitTask(resources, i))
|
2020-01-09 19:34:46 +00:00
|
|
|
}
|
|
|
|
for i := 0; i < side; i++ {
|
2020-01-09 23:43:00 +00:00
|
|
|
tasks = append(tasks, LifecycleSideTask(resources, i))
|
2020-01-09 19:34:46 +00:00
|
|
|
}
|
|
|
|
job := &structs.Job{
|
|
|
|
Region: "global",
|
|
|
|
ID: fmt.Sprintf("mock-service-%s", uuid.Generate()),
|
|
|
|
Name: "my-job",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
Type: structs.JobTypeService,
|
|
|
|
Priority: 50,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Constraints: []*structs.Constraint{
|
|
|
|
{
|
|
|
|
LTarget: "${attr.kernel.name}",
|
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Count: 1,
|
|
|
|
Tasks: tasks,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
|
|
|
},
|
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
Version: 0,
|
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
JobModifyIndex: 99,
|
|
|
|
}
|
|
|
|
job.Canonicalize()
|
|
|
|
return job
|
|
|
|
}
|
2020-08-12 16:54:14 +00:00
|
|
|
|
2020-01-07 19:50:57 +00:00
|
|
|
func LifecycleJob() *structs.Job {
|
|
|
|
job := &structs.Job{
|
|
|
|
Region: "global",
|
|
|
|
ID: fmt.Sprintf("mock-service-%s", uuid.Generate()),
|
|
|
|
Name: "my-job",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
2020-01-24 19:56:36 +00:00
|
|
|
Type: structs.JobTypeBatch,
|
2020-01-07 19:50:57 +00:00
|
|
|
Priority: 50,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Constraints: []*structs.Constraint{
|
|
|
|
{
|
|
|
|
LTarget: "${attr.kernel.name}",
|
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
|
|
|
{
|
2020-01-09 19:34:46 +00:00
|
|
|
Name: "web",
|
|
|
|
Count: 1,
|
2020-01-24 19:56:36 +00:00
|
|
|
RestartPolicy: &structs.RestartPolicy{
|
|
|
|
Attempts: 0,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 1 * time.Minute,
|
|
|
|
Mode: structs.RestartPolicyModeFail,
|
|
|
|
},
|
2020-01-07 19:50:57 +00:00
|
|
|
Tasks: []*structs.Task{
|
|
|
|
{
|
|
|
|
Name: "web",
|
2020-01-24 19:56:36 +00:00
|
|
|
Driver: "mock_driver",
|
2020-01-07 19:50:57 +00:00
|
|
|
Config: map[string]interface{}{
|
2020-01-24 19:56:36 +00:00
|
|
|
"run_for": "1s",
|
2020-01-07 19:50:57 +00:00
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
2020-01-09 19:34:46 +00:00
|
|
|
CPU: 1000,
|
2020-01-07 19:50:57 +00:00
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "side",
|
2020-01-24 19:56:36 +00:00
|
|
|
Driver: "mock_driver",
|
2020-01-07 19:50:57 +00:00
|
|
|
Config: map[string]interface{}{
|
2020-01-24 19:56:36 +00:00
|
|
|
"run_for": "1s",
|
2020-01-07 19:50:57 +00:00
|
|
|
},
|
|
|
|
Lifecycle: &structs.TaskLifecycleConfig{
|
2020-03-02 19:12:16 +00:00
|
|
|
Hook: structs.TaskLifecycleHookPrestart,
|
|
|
|
Sidecar: true,
|
2020-01-07 19:50:57 +00:00
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
2020-01-09 19:34:46 +00:00
|
|
|
CPU: 1000,
|
2020-01-07 19:50:57 +00:00
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "init",
|
2020-01-24 19:56:36 +00:00
|
|
|
Driver: "mock_driver",
|
2020-01-07 19:50:57 +00:00
|
|
|
Config: map[string]interface{}{
|
2020-01-24 19:56:36 +00:00
|
|
|
"run_for": "1s",
|
2020-01-07 19:50:57 +00:00
|
|
|
},
|
|
|
|
Lifecycle: &structs.TaskLifecycleConfig{
|
2020-03-02 19:12:16 +00:00
|
|
|
Hook: structs.TaskLifecycleHookPrestart,
|
|
|
|
Sidecar: false,
|
2020-01-07 19:50:57 +00:00
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
2020-01-09 19:34:46 +00:00
|
|
|
CPU: 1000,
|
2020-01-07 19:50:57 +00:00
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
2019-09-02 17:30:09 +00:00
|
|
|
},
|
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
Version: 0,
|
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
JobModifyIndex: 99,
|
|
|
|
}
|
|
|
|
job.Canonicalize()
|
|
|
|
return job
|
|
|
|
}
|
2020-08-12 16:54:14 +00:00
|
|
|
|
2020-01-23 18:52:17 +00:00
|
|
|
func LifecycleAlloc() *structs.Allocation {
|
|
|
|
alloc := &structs.Allocation{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
EvalID: uuid.Generate(),
|
|
|
|
NodeID: "12345678-abcd-efab-cdef-123456789abc",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
TaskGroup: "web",
|
|
|
|
|
|
|
|
// TODO Remove once clientv2 gets merged
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
TaskResources: map[string]*structs.Resources{
|
|
|
|
"web": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
"init": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
"side": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
AllocatedResources: &structs.AllocatedResources{
|
|
|
|
Tasks: map[string]*structs.AllocatedTaskResources{
|
|
|
|
"web": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"init": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"side": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Job: LifecycleJob(),
|
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
|
|
|
ClientStatus: structs.AllocClientStatusPending,
|
|
|
|
}
|
|
|
|
alloc.JobID = alloc.Job.ID
|
|
|
|
return alloc
|
|
|
|
}
|
2019-09-02 17:30:09 +00:00
|
|
|
|
2021-01-12 18:03:48 +00:00
|
|
|
func LifecycleJobWithPoststopDeploy() *structs.Job {
|
|
|
|
job := &structs.Job{
|
|
|
|
Region: "global",
|
|
|
|
ID: fmt.Sprintf("mock-service-%s", uuid.Generate()),
|
|
|
|
Name: "my-job",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
Type: structs.JobTypeBatch,
|
|
|
|
Priority: 50,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Constraints: []*structs.Constraint{
|
|
|
|
{
|
|
|
|
LTarget: "${attr.kernel.name}",
|
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Count: 1,
|
|
|
|
Migrate: structs.DefaultMigrateStrategy(),
|
|
|
|
RestartPolicy: &structs.RestartPolicy{
|
|
|
|
Attempts: 0,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 1 * time.Minute,
|
|
|
|
Mode: structs.RestartPolicyModeFail,
|
|
|
|
},
|
|
|
|
Tasks: []*structs.Task{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Driver: "mock_driver",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"run_for": "1s",
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "side",
|
|
|
|
Driver: "mock_driver",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"run_for": "1s",
|
|
|
|
},
|
|
|
|
Lifecycle: &structs.TaskLifecycleConfig{
|
|
|
|
Hook: structs.TaskLifecycleHookPrestart,
|
|
|
|
Sidecar: true,
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "post",
|
|
|
|
Driver: "mock_driver",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"run_for": "1s",
|
|
|
|
},
|
|
|
|
Lifecycle: &structs.TaskLifecycleConfig{
|
|
|
|
Hook: structs.TaskLifecycleHookPoststop,
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "init",
|
|
|
|
Driver: "mock_driver",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"run_for": "1s",
|
|
|
|
},
|
|
|
|
Lifecycle: &structs.TaskLifecycleConfig{
|
|
|
|
Hook: structs.TaskLifecycleHookPrestart,
|
|
|
|
Sidecar: false,
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
|
|
|
},
|
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
Version: 0,
|
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
JobModifyIndex: 99,
|
|
|
|
}
|
|
|
|
job.Canonicalize()
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:29:49 +00:00
|
|
|
func LifecycleJobWithPoststartDeploy() *structs.Job {
|
|
|
|
job := &structs.Job{
|
|
|
|
Region: "global",
|
|
|
|
ID: fmt.Sprintf("mock-service-%s", uuid.Generate()),
|
|
|
|
Name: "my-job",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
Type: structs.JobTypeBatch,
|
|
|
|
Priority: 50,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Constraints: []*structs.Constraint{
|
|
|
|
{
|
|
|
|
LTarget: "${attr.kernel.name}",
|
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Count: 1,
|
|
|
|
Migrate: structs.DefaultMigrateStrategy(),
|
|
|
|
RestartPolicy: &structs.RestartPolicy{
|
|
|
|
Attempts: 0,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 1 * time.Minute,
|
|
|
|
Mode: structs.RestartPolicyModeFail,
|
|
|
|
},
|
|
|
|
Tasks: []*structs.Task{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Driver: "mock_driver",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"run_for": "1s",
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "side",
|
|
|
|
Driver: "mock_driver",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"run_for": "1s",
|
|
|
|
},
|
|
|
|
Lifecycle: &structs.TaskLifecycleConfig{
|
|
|
|
Hook: structs.TaskLifecycleHookPrestart,
|
|
|
|
Sidecar: true,
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "post",
|
|
|
|
Driver: "mock_driver",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"run_for": "1s",
|
|
|
|
},
|
|
|
|
Lifecycle: &structs.TaskLifecycleConfig{
|
|
|
|
Hook: structs.TaskLifecycleHookPoststart,
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "init",
|
|
|
|
Driver: "mock_driver",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"run_for": "1s",
|
|
|
|
},
|
|
|
|
Lifecycle: &structs.TaskLifecycleConfig{
|
|
|
|
Hook: structs.TaskLifecycleHookPrestart,
|
|
|
|
Sidecar: false,
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
|
|
|
},
|
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
Version: 0,
|
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
JobModifyIndex: 99,
|
|
|
|
}
|
|
|
|
job.Canonicalize()
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2021-01-12 18:03:48 +00:00
|
|
|
func LifecycleAllocWithPoststopDeploy() *structs.Allocation {
|
|
|
|
alloc := &structs.Allocation{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
EvalID: uuid.Generate(),
|
|
|
|
NodeID: "12345678-abcd-efab-cdef-123456789abc",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
TaskGroup: "web",
|
|
|
|
|
|
|
|
// TODO Remove once clientv2 gets merged
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
TaskResources: map[string]*structs.Resources{
|
|
|
|
"web": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
"init": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
"side": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
"post": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
AllocatedResources: &structs.AllocatedResources{
|
|
|
|
Tasks: map[string]*structs.AllocatedTaskResources{
|
|
|
|
"web": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"init": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"side": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"post": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Job: LifecycleJobWithPoststopDeploy(),
|
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
|
|
|
ClientStatus: structs.AllocClientStatusPending,
|
|
|
|
}
|
|
|
|
alloc.JobID = alloc.Job.ID
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:29:49 +00:00
|
|
|
func LifecycleAllocWithPoststartDeploy() *structs.Allocation {
|
|
|
|
alloc := &structs.Allocation{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
EvalID: uuid.Generate(),
|
|
|
|
NodeID: "12345678-abcd-efab-cdef-123456789xyz",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
TaskGroup: "web",
|
|
|
|
|
|
|
|
// TODO Remove once clientv2 gets merged
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
TaskResources: map[string]*structs.Resources{
|
|
|
|
"web": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
"init": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
"side": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
"post": {
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
AllocatedResources: &structs.AllocatedResources{
|
|
|
|
Tasks: map[string]*structs.AllocatedTaskResources{
|
|
|
|
"web": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"init": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"side": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"post": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 1000,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Job: LifecycleJobWithPoststartDeploy(),
|
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
|
|
|
ClientStatus: structs.AllocClientStatusPending,
|
|
|
|
}
|
|
|
|
alloc.JobID = alloc.Job.ID
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2019-09-02 17:30:09 +00:00
|
|
|
func MaxParallelJob() *structs.Job {
|
|
|
|
update := *structs.DefaultUpdateStrategy
|
|
|
|
update.MaxParallel = 0
|
|
|
|
job := &structs.Job{
|
|
|
|
Region: "global",
|
|
|
|
ID: fmt.Sprintf("mock-service-%s", uuid.Generate()),
|
|
|
|
Name: "my-job",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
Type: structs.JobTypeService,
|
|
|
|
Priority: 50,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Constraints: []*structs.Constraint{
|
|
|
|
{
|
|
|
|
LTarget: "${attr.kernel.name}",
|
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Update: update,
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Count: 10,
|
|
|
|
EphemeralDisk: &structs.EphemeralDisk{
|
|
|
|
SizeMB: 150,
|
|
|
|
},
|
|
|
|
RestartPolicy: &structs.RestartPolicy{
|
|
|
|
Attempts: 3,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 1 * time.Minute,
|
|
|
|
Mode: structs.RestartPolicyModeDelay,
|
|
|
|
},
|
|
|
|
ReschedulePolicy: &structs.ReschedulePolicy{
|
|
|
|
Attempts: 2,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 5 * time.Second,
|
|
|
|
DelayFunction: "constant",
|
|
|
|
},
|
|
|
|
Migrate: structs.DefaultMigrateStrategy(),
|
|
|
|
Update: &update,
|
|
|
|
Tasks: []*structs.Task{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Driver: "exec",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"command": "/bin/date",
|
|
|
|
},
|
|
|
|
Env: map[string]string{
|
|
|
|
"FOO": "bar",
|
|
|
|
},
|
|
|
|
Services: []*structs.Service{
|
|
|
|
{
|
|
|
|
Name: "${TASK}-frontend",
|
|
|
|
PortLabel: "http",
|
|
|
|
Tags: []string{"pci:${meta.pci-dss}", "datacenter:${node.datacenter}"},
|
|
|
|
Checks: []*structs.ServiceCheck{
|
|
|
|
{
|
|
|
|
Name: "check-table",
|
|
|
|
Type: structs.ServiceCheckScript,
|
|
|
|
Command: "/usr/local/check-table-${meta.database}",
|
|
|
|
Args: []string{"${meta.version}"},
|
|
|
|
Interval: 30 * time.Second,
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "${TASK}-admin",
|
|
|
|
PortLabel: "admin",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 500,
|
2015-08-11 21:27:14 +00:00
|
|
|
MemoryMB: 256,
|
2015-09-13 23:40:31 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2017-12-08 22:50:06 +00:00
|
|
|
MBits: 50,
|
|
|
|
DynamicPorts: []structs.Port{
|
|
|
|
{Label: "http"},
|
|
|
|
{Label: "admin"},
|
|
|
|
},
|
2015-09-13 23:40:31 +00:00
|
|
|
},
|
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
2016-04-26 00:20:25 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"elb_check_type": "http",
|
|
|
|
"elb_check_interval": "30s",
|
|
|
|
"elb_check_min": "3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
|
|
|
},
|
2016-01-12 17:50:33 +00:00
|
|
|
Status: structs.JobStatusPending,
|
2017-04-13 20:54:57 +00:00
|
|
|
Version: 0,
|
2016-01-12 17:50:33 +00:00
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
JobModifyIndex: 99,
|
2015-08-11 21:27:14 +00:00
|
|
|
}
|
2016-07-20 23:07:15 +00:00
|
|
|
job.Canonicalize()
|
2015-08-11 21:27:14 +00:00
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:43:38 +00:00
|
|
|
// ConnectJob adds a Connect proxy sidecar group service to mock.Job.
|
2019-12-06 20:46:46 +00:00
|
|
|
//
|
|
|
|
// Note this does *not* include the Job.Register mutation that inserts the
|
|
|
|
// associated Sidecar Task (nor the hook that configures envoy as the default).
|
2019-09-03 15:43:38 +00:00
|
|
|
func ConnectJob() *structs.Job {
|
|
|
|
job := Job()
|
|
|
|
tg := job.TaskGroups[0]
|
2020-07-13 21:53:10 +00:00
|
|
|
tg.Services = []*structs.Service{{
|
|
|
|
Name: "testconnect",
|
|
|
|
PortLabel: "9999",
|
|
|
|
Connect: &structs.ConsulConnect{
|
|
|
|
SidecarService: new(structs.ConsulSidecarService),
|
2019-09-03 15:43:38 +00:00
|
|
|
},
|
2020-07-13 21:53:10 +00:00
|
|
|
}}
|
2019-12-06 20:46:46 +00:00
|
|
|
tg.Networks = structs.Networks{{
|
|
|
|
Mode: "bridge", // always bridge ... for now?
|
|
|
|
}}
|
2019-09-03 15:43:38 +00:00
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2020-07-13 21:53:10 +00:00
|
|
|
func ConnectNativeJob(mode string) *structs.Job {
|
|
|
|
job := Job()
|
|
|
|
tg := job.TaskGroups[0]
|
|
|
|
tg.Networks = []*structs.NetworkResource{{
|
|
|
|
Mode: mode,
|
|
|
|
}}
|
|
|
|
tg.Services = []*structs.Service{{
|
|
|
|
Name: "test_connect_native",
|
|
|
|
PortLabel: "9999",
|
|
|
|
Connect: &structs.ConsulConnect{
|
|
|
|
Native: true,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
tg.Tasks = []*structs.Task{{
|
|
|
|
Name: "native_task",
|
|
|
|
}}
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2020-07-28 20:12:08 +00:00
|
|
|
// ConnectIngressGatewayJob creates a structs.Job that contains the definition
|
|
|
|
// of a Consul Ingress Gateway service. The mode is the name of the network
|
|
|
|
// mode assumed by the task group. If inject is true, a corresponding Task is
|
|
|
|
// set on the group's Tasks (i.e. what the job would look like after job mutation).
|
|
|
|
func ConnectIngressGatewayJob(mode string, inject bool) *structs.Job {
|
|
|
|
job := Job()
|
|
|
|
tg := job.TaskGroups[0]
|
|
|
|
tg.Networks = []*structs.NetworkResource{{
|
|
|
|
Mode: mode,
|
|
|
|
}}
|
|
|
|
tg.Services = []*structs.Service{{
|
|
|
|
Name: "my-ingress-service",
|
|
|
|
PortLabel: "9999",
|
|
|
|
Connect: &structs.ConsulConnect{
|
|
|
|
Gateway: &structs.ConsulGateway{
|
|
|
|
Proxy: &structs.ConsulGatewayProxy{
|
2021-01-22 14:18:17 +00:00
|
|
|
ConnectTimeout: helper.TimeToPtr(3 * time.Second),
|
|
|
|
EnvoyGatewayBindAddresses: make(map[string]*structs.ConsulGatewayBindAddress),
|
2020-07-28 20:12:08 +00:00
|
|
|
},
|
|
|
|
Ingress: &structs.ConsulIngressConfigEntry{
|
|
|
|
Listeners: []*structs.ConsulIngressListener{{
|
|
|
|
Port: 2000,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []*structs.ConsulIngressService{{
|
|
|
|
Name: "service1",
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
2021-04-12 19:10:10 +00:00
|
|
|
|
|
|
|
tg.Tasks = nil
|
|
|
|
|
2020-07-28 20:12:08 +00:00
|
|
|
// some tests need to assume the gateway proxy task has already been injected
|
|
|
|
if inject {
|
|
|
|
tg.Tasks = []*structs.Task{{
|
|
|
|
Name: fmt.Sprintf("%s-%s", structs.ConnectIngressPrefix, "my-ingress-service"),
|
|
|
|
Kind: structs.NewTaskKind(structs.ConnectIngressPrefix, "my-ingress-service"),
|
|
|
|
Driver: "docker",
|
|
|
|
Config: make(map[string]interface{}),
|
|
|
|
ShutdownDelay: 5 * time.Second,
|
|
|
|
LogConfig: &structs.LogConfig{
|
|
|
|
MaxFiles: 2,
|
|
|
|
MaxFileSizeMB: 2,
|
|
|
|
},
|
|
|
|
}}
|
2021-04-12 19:10:10 +00:00
|
|
|
}
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnectTerminatingGatewayJob creates a structs.Job that contains the definition
|
|
|
|
// of a Consul Terminating Gateway service. The mode is the name of the network mode
|
|
|
|
// assumed by the task group. If inject is true, a corresponding task is set on the
|
|
|
|
// group's Tasks (i.e. what the job would look like after mutation).
|
|
|
|
func ConnectTerminatingGatewayJob(mode string, inject bool) *structs.Job {
|
|
|
|
job := Job()
|
|
|
|
tg := job.TaskGroups[0]
|
|
|
|
tg.Networks = []*structs.NetworkResource{{
|
|
|
|
Mode: mode,
|
|
|
|
}}
|
|
|
|
tg.Services = []*structs.Service{{
|
|
|
|
Name: "my-terminating-service",
|
|
|
|
PortLabel: "9999",
|
|
|
|
Connect: &structs.ConsulConnect{
|
|
|
|
Gateway: &structs.ConsulGateway{
|
|
|
|
Proxy: &structs.ConsulGatewayProxy{
|
|
|
|
ConnectTimeout: helper.TimeToPtr(3 * time.Second),
|
|
|
|
EnvoyGatewayBindAddresses: make(map[string]*structs.ConsulGatewayBindAddress),
|
|
|
|
},
|
|
|
|
Terminating: &structs.ConsulTerminatingConfigEntry{
|
|
|
|
Services: []*structs.ConsulLinkedService{{
|
|
|
|
Name: "service1",
|
|
|
|
CAFile: "/ssl/ca_file",
|
|
|
|
CertFile: "/ssl/cert_file",
|
|
|
|
KeyFile: "/ssl/key_file",
|
|
|
|
SNI: "sni-name",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
tg.Tasks = nil
|
|
|
|
|
|
|
|
// some tests need to assume the gateway proxy task has already been injected
|
|
|
|
if inject {
|
|
|
|
tg.Tasks = []*structs.Task{{
|
|
|
|
Name: fmt.Sprintf("%s-%s", structs.ConnectTerminatingPrefix, "my-terminating-service"),
|
|
|
|
Kind: structs.NewTaskKind(structs.ConnectTerminatingPrefix, "my-terminating-service"),
|
|
|
|
Driver: "docker",
|
|
|
|
Config: make(map[string]interface{}),
|
|
|
|
ShutdownDelay: 5 * time.Second,
|
|
|
|
LogConfig: &structs.LogConfig{
|
|
|
|
MaxFiles: 2,
|
|
|
|
MaxFileSizeMB: 2,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnectMeshGatewayJob creates a structs.Job that contains the definition of a
|
|
|
|
// Consul Mesh Gateway service. The mode is the name of the network mode assumed
|
|
|
|
// by the task group. If inject is true, a corresponding task is set on the group's
|
|
|
|
// Tasks (i.e. what the job would look like after job mutation).
|
|
|
|
func ConnectMeshGatewayJob(mode string, inject bool) *structs.Job {
|
|
|
|
job := Job()
|
|
|
|
tg := job.TaskGroups[0]
|
|
|
|
tg.Networks = []*structs.NetworkResource{{
|
|
|
|
Mode: mode,
|
|
|
|
}}
|
|
|
|
tg.Services = []*structs.Service{{
|
|
|
|
Name: "my-mesh-service",
|
|
|
|
PortLabel: "public_port",
|
|
|
|
Connect: &structs.ConsulConnect{
|
|
|
|
Gateway: &structs.ConsulGateway{
|
|
|
|
Proxy: &structs.ConsulGatewayProxy{
|
|
|
|
ConnectTimeout: helper.TimeToPtr(3 * time.Second),
|
|
|
|
EnvoyGatewayBindAddresses: make(map[string]*structs.ConsulGatewayBindAddress),
|
|
|
|
},
|
|
|
|
Mesh: &structs.ConsulMeshConfigEntry{
|
|
|
|
// nothing to configure
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
tg.Tasks = nil
|
|
|
|
|
|
|
|
// some tests need to assume the gateway task has already been injected
|
|
|
|
if inject {
|
|
|
|
tg.Tasks = []*structs.Task{{
|
|
|
|
Name: fmt.Sprintf("%s-%s", structs.ConnectMeshPrefix, "my-mesh-service"),
|
|
|
|
Kind: structs.NewTaskKind(structs.ConnectMeshPrefix, "my-mesh-service"),
|
|
|
|
Driver: "docker",
|
|
|
|
Config: make(map[string]interface{}),
|
|
|
|
ShutdownDelay: 5 * time.Second,
|
|
|
|
LogConfig: &structs.LogConfig{
|
|
|
|
MaxFiles: 2,
|
|
|
|
MaxFileSizeMB: 2,
|
|
|
|
},
|
|
|
|
}}
|
2020-07-28 20:12:08 +00:00
|
|
|
}
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2020-09-04 17:50:11 +00:00
|
|
|
func ConnectSidecarTask() *structs.Task {
|
|
|
|
return &structs.Task{
|
|
|
|
Name: "mysidecar-sidecar-task",
|
|
|
|
Driver: "docker",
|
|
|
|
User: "nobody",
|
|
|
|
Config: map[string]interface{}{
|
2020-12-11 15:57:13 +00:00
|
|
|
"image": envoy.SidecarConfigVar,
|
2020-09-04 17:50:11 +00:00
|
|
|
},
|
|
|
|
Env: nil,
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 150,
|
|
|
|
MemoryMB: 350,
|
|
|
|
},
|
|
|
|
Kind: structs.NewTaskKind(structs.ConnectProxyPrefix, "mysidecar"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-20 21:49:17 +00:00
|
|
|
func BatchJob() *structs.Job {
|
|
|
|
job := &structs.Job{
|
|
|
|
Region: "global",
|
2018-03-28 18:57:47 +00:00
|
|
|
ID: fmt.Sprintf("mock-batch-%s", uuid.Generate()),
|
2018-03-20 21:49:17 +00:00
|
|
|
Name: "batch-job",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
Type: structs.JobTypeBatch,
|
|
|
|
Priority: 50,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
|
|
|
{
|
2018-11-16 23:29:59 +00:00
|
|
|
Name: "web",
|
2018-03-20 21:49:17 +00:00
|
|
|
Count: 10,
|
|
|
|
EphemeralDisk: &structs.EphemeralDisk{
|
|
|
|
SizeMB: 150,
|
|
|
|
},
|
|
|
|
RestartPolicy: &structs.RestartPolicy{
|
|
|
|
Attempts: 3,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 1 * time.Minute,
|
|
|
|
Mode: structs.RestartPolicyModeDelay,
|
|
|
|
},
|
|
|
|
ReschedulePolicy: &structs.ReschedulePolicy{
|
|
|
|
Attempts: 2,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 5 * time.Second,
|
2018-03-26 19:45:09 +00:00
|
|
|
DelayFunction: "constant",
|
2018-03-20 21:49:17 +00:00
|
|
|
},
|
|
|
|
Tasks: []*structs.Task{
|
|
|
|
{
|
2018-11-16 23:29:59 +00:00
|
|
|
Name: "web",
|
2018-03-20 21:49:17 +00:00
|
|
|
Driver: "mock_driver",
|
|
|
|
Config: map[string]interface{}{
|
2018-11-13 02:52:12 +00:00
|
|
|
"run_for": "500ms",
|
2018-03-20 21:49:17 +00:00
|
|
|
},
|
|
|
|
Env: map[string]string{
|
|
|
|
"FOO": "bar",
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 100,
|
|
|
|
MemoryMB: 100,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
MBits: 50,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
Version: 0,
|
|
|
|
CreateIndex: 43,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
JobModifyIndex: 99,
|
|
|
|
}
|
|
|
|
job.Canonicalize()
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2015-10-14 23:43:06 +00:00
|
|
|
func SystemJob() *structs.Job {
|
|
|
|
job := &structs.Job{
|
|
|
|
Region: "global",
|
2017-09-07 23:56:15 +00:00
|
|
|
Namespace: structs.DefaultNamespace,
|
2018-03-28 18:57:47 +00:00
|
|
|
ID: fmt.Sprintf("mock-system-%s", uuid.Generate()),
|
2015-10-14 23:43:06 +00:00
|
|
|
Name: "my-job",
|
|
|
|
Type: structs.JobTypeSystem,
|
|
|
|
Priority: 100,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
Constraints: []*structs.Constraint{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2016-02-05 00:50:20 +00:00
|
|
|
LTarget: "${attr.kernel.name}",
|
2015-10-14 23:43:06 +00:00
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-10-15 20:14:44 +00:00
|
|
|
Name: "web",
|
|
|
|
Count: 1,
|
2015-10-31 01:34:23 +00:00
|
|
|
RestartPolicy: &structs.RestartPolicy{
|
2016-02-02 23:08:07 +00:00
|
|
|
Attempts: 3,
|
|
|
|
Interval: 10 * time.Minute,
|
|
|
|
Delay: 1 * time.Minute,
|
|
|
|
Mode: structs.RestartPolicyModeDelay,
|
2015-10-31 01:34:23 +00:00
|
|
|
},
|
2016-09-14 22:43:42 +00:00
|
|
|
EphemeralDisk: structs.DefaultEphemeralDisk(),
|
2015-10-14 23:43:06 +00:00
|
|
|
Tasks: []*structs.Task{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-10-14 23:43:06 +00:00
|
|
|
Name: "web",
|
|
|
|
Driver: "exec",
|
2015-11-14 02:09:42 +00:00
|
|
|
Config: map[string]interface{}{
|
2015-10-14 23:43:06 +00:00
|
|
|
"command": "/bin/date",
|
|
|
|
},
|
2016-08-16 17:49:45 +00:00
|
|
|
Env: map[string]string{},
|
2015-10-14 23:43:06 +00:00
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
Networks: []*structs.NetworkResource{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-10-14 23:43:06 +00:00
|
|
|
MBits: 50,
|
2015-11-14 02:35:49 +00:00
|
|
|
DynamicPorts: []structs.Port{{Label: "http"}},
|
2015-10-14 23:43:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-02-11 01:46:35 +00:00
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
2015-10-14 23:43:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
|
|
|
},
|
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
}
|
2016-12-12 21:32:30 +00:00
|
|
|
job.Canonicalize()
|
2015-10-14 23:43:06 +00:00
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2015-12-18 20:26:28 +00:00
|
|
|
func PeriodicJob() *structs.Job {
|
|
|
|
job := Job()
|
2015-12-05 00:53:36 +00:00
|
|
|
job.Type = structs.JobTypeBatch
|
2015-12-18 20:26:28 +00:00
|
|
|
job.Periodic = &structs.PeriodicConfig{
|
|
|
|
Enabled: true,
|
|
|
|
SpecType: structs.PeriodicSpecCron,
|
2015-12-05 00:53:36 +00:00
|
|
|
Spec: "*/30 * * * *",
|
2015-12-18 20:26:28 +00:00
|
|
|
}
|
2016-12-12 21:32:30 +00:00
|
|
|
job.Status = structs.JobStatusRunning
|
2018-02-23 18:42:43 +00:00
|
|
|
job.TaskGroups[0].Migrate = nil
|
2015-12-18 20:26:28 +00:00
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2015-08-11 21:27:14 +00:00
|
|
|
func Eval() *structs.Evaluation {
|
2019-08-07 16:50:35 +00:00
|
|
|
now := time.Now().UTC().UnixNano()
|
2015-08-11 21:27:14 +00:00
|
|
|
eval := &structs.Evaluation{
|
2019-08-07 16:50:35 +00:00
|
|
|
ID: uuid.Generate(),
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
Priority: 50,
|
|
|
|
Type: structs.JobTypeService,
|
|
|
|
JobID: uuid.Generate(),
|
|
|
|
Status: structs.EvalStatusPending,
|
|
|
|
CreateTime: now,
|
|
|
|
ModifyTime: now,
|
2015-08-11 21:27:14 +00:00
|
|
|
}
|
|
|
|
return eval
|
|
|
|
}
|
|
|
|
|
2021-04-29 19:03:45 +00:00
|
|
|
func BlockedEval() *structs.Evaluation {
|
|
|
|
e := Eval()
|
|
|
|
e.Status = structs.EvalStatusBlocked
|
|
|
|
e.FailedTGAllocs = map[string]*structs.AllocMetric{
|
|
|
|
"cache": {
|
|
|
|
DimensionExhausted: map[string]int{
|
|
|
|
"memory": 1,
|
|
|
|
},
|
|
|
|
ResourcesExhausted: map[string]*structs.Resources{
|
|
|
|
"redis": {
|
|
|
|
CPU: 100,
|
|
|
|
MemoryMB: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2016-07-20 21:09:03 +00:00
|
|
|
func JobSummary(jobID string) *structs.JobSummary {
|
2020-10-09 21:31:38 +00:00
|
|
|
return &structs.JobSummary{
|
2017-09-07 23:56:15 +00:00
|
|
|
JobID: jobID,
|
|
|
|
Namespace: structs.DefaultNamespace,
|
2016-07-20 21:09:03 +00:00
|
|
|
Summary: map[string]structs.TaskGroupSummary{
|
2016-07-21 21:43:21 +00:00
|
|
|
"web": {
|
|
|
|
Queued: 0,
|
|
|
|
Starting: 0,
|
2016-07-20 21:09:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-09 21:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func JobSysBatchSummary(jobID string) *structs.JobSummary {
|
|
|
|
return &structs.JobSummary{
|
|
|
|
JobID: jobID,
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
Summary: map[string]structs.TaskGroupSummary{
|
|
|
|
"pinger": {
|
|
|
|
Queued: 0,
|
|
|
|
Starting: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-07-20 21:09:03 +00:00
|
|
|
}
|
|
|
|
|
2015-08-11 21:27:14 +00:00
|
|
|
func Alloc() *structs.Allocation {
|
api: implement fuzzy search API
This PR introduces the /v1/search/fuzzy API endpoint, used for fuzzy
searching objects in Nomad. The fuzzy search endpoint routes requests
to the Nomad Server leader, which implements the Search.FuzzySearch RPC
method.
Requests to the fuzzy search API are based on the api.FuzzySearchRequest
object, e.g.
{
"Text": "ed",
"Context": "all"
}
Responses from the fuzzy search API are based on the api.FuzzySearchResponse
object, e.g.
{
"Index": 27,
"KnownLeader": true,
"LastContact": 0,
"Matches": {
"tasks": [
{
"ID": "redis",
"Scope": [
"default",
"example",
"cache"
]
}
],
"evals": [],
"deployment": [],
"volumes": [],
"scaling_policy": [],
"images": [
{
"ID": "redis:3.2",
"Scope": [
"default",
"example",
"cache",
"redis"
]
}
]
},
"Truncations": {
"volumes": false,
"scaling_policy": false,
"evals": false,
"deployment": false
}
}
The API is tunable using the new server.search stanza, e.g.
server {
search {
fuzzy_enabled = true
limit_query = 200
limit_results = 1000
min_term_length = 5
}
}
These values can be increased or decreased, so as to provide more
search results or to reduce load on the Nomad Server. The fuzzy search
API can be disabled entirely by setting `fuzzy_enabled` to `false`.
2021-02-23 20:24:52 +00:00
|
|
|
job := Job()
|
2015-08-11 21:27:14 +00:00
|
|
|
alloc := &structs.Allocation{
|
2017-09-29 16:58:48 +00:00
|
|
|
ID: uuid.Generate(),
|
|
|
|
EvalID: uuid.Generate(),
|
2016-01-14 20:57:43 +00:00
|
|
|
NodeID: "12345678-abcd-efab-cdef-123456789abc",
|
2017-09-07 23:56:15 +00:00
|
|
|
Namespace: structs.DefaultNamespace,
|
2015-08-29 23:24:01 +00:00
|
|
|
TaskGroup: "web",
|
2018-10-03 16:47:18 +00:00
|
|
|
|
|
|
|
// TODO Remove once clientv2 gets merged
|
2015-08-11 21:27:14 +00:00
|
|
|
Resources: &structs.Resources{
|
2015-09-23 18:14:32 +00:00
|
|
|
CPU: 500,
|
2015-09-14 00:06:34 +00:00
|
|
|
MemoryMB: 256,
|
2016-08-29 19:49:52 +00:00
|
|
|
DiskMB: 150,
|
2015-08-11 21:27:14 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-09-13 02:13:00 +00:00
|
|
|
Device: "eth0",
|
2015-09-14 00:06:34 +00:00
|
|
|
IP: "192.168.0.100",
|
2017-12-08 22:50:06 +00:00
|
|
|
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
|
2016-03-01 22:09:25 +00:00
|
|
|
MBits: 50,
|
2015-11-14 02:35:49 +00:00
|
|
|
DynamicPorts: []structs.Port{{Label: "http"}},
|
2015-09-14 00:06:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskResources: map[string]*structs.Resources{
|
2017-09-26 22:26:33 +00:00
|
|
|
"web": {
|
2015-09-23 18:14:32 +00:00
|
|
|
CPU: 500,
|
2015-09-14 00:06:34 +00:00
|
|
|
MemoryMB: 256,
|
|
|
|
Networks: []*structs.NetworkResource{
|
2017-09-26 22:26:33 +00:00
|
|
|
{
|
2015-09-14 00:06:34 +00:00
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
2017-12-08 22:50:06 +00:00
|
|
|
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
|
2015-09-14 00:06:34 +00:00
|
|
|
MBits: 50,
|
2017-12-19 00:18:42 +00:00
|
|
|
DynamicPorts: []structs.Port{{Label: "http", Value: 9876}},
|
2015-09-14 00:06:34 +00:00
|
|
|
},
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-08-29 19:49:52 +00:00
|
|
|
SharedResources: &structs.Resources{
|
|
|
|
DiskMB: 150,
|
|
|
|
},
|
2018-10-03 16:47:18 +00:00
|
|
|
|
|
|
|
AllocatedResources: &structs.AllocatedResources{
|
|
|
|
Tasks: map[string]*structs.AllocatedTaskResources{
|
|
|
|
"web": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 500,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
|
|
|
|
MBits: 50,
|
|
|
|
DynamicPorts: []structs.Port{{Label: "http", Value: 9876}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Shared: structs.AllocatedSharedResources{
|
|
|
|
DiskMB: 150,
|
|
|
|
},
|
|
|
|
},
|
api: implement fuzzy search API
This PR introduces the /v1/search/fuzzy API endpoint, used for fuzzy
searching objects in Nomad. The fuzzy search endpoint routes requests
to the Nomad Server leader, which implements the Search.FuzzySearch RPC
method.
Requests to the fuzzy search API are based on the api.FuzzySearchRequest
object, e.g.
{
"Text": "ed",
"Context": "all"
}
Responses from the fuzzy search API are based on the api.FuzzySearchResponse
object, e.g.
{
"Index": 27,
"KnownLeader": true,
"LastContact": 0,
"Matches": {
"tasks": [
{
"ID": "redis",
"Scope": [
"default",
"example",
"cache"
]
}
],
"evals": [],
"deployment": [],
"volumes": [],
"scaling_policy": [],
"images": [
{
"ID": "redis:3.2",
"Scope": [
"default",
"example",
"cache",
"redis"
]
}
]
},
"Truncations": {
"volumes": false,
"scaling_policy": false,
"evals": false,
"deployment": false
}
}
The API is tunable using the new server.search stanza, e.g.
server {
search {
fuzzy_enabled = true
limit_query = 200
limit_results = 1000
min_term_length = 5
}
}
These values can be increased or decreased, so as to provide more
search results or to reduce load on the Nomad Server. The fuzzy search
API can be disabled entirely by setting `fuzzy_enabled` to `false`.
2021-02-23 20:24:52 +00:00
|
|
|
Job: job,
|
2015-08-25 23:19:21 +00:00
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
2018-03-27 21:10:14 +00:00
|
|
|
ClientStatus: structs.AllocClientStatusPending,
|
|
|
|
}
|
|
|
|
alloc.JobID = alloc.Job.ID
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2022-01-15 01:09:14 +00:00
|
|
|
func AllocWithoutReservedPort() *structs.Allocation {
|
|
|
|
alloc := Alloc()
|
|
|
|
alloc.Resources.Networks[0].ReservedPorts = nil
|
|
|
|
alloc.TaskResources["web"].Networks[0].ReservedPorts = nil
|
|
|
|
alloc.AllocatedResources.Tasks["web"].Networks[0].ReservedPorts = nil
|
|
|
|
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
|
|
|
func AllocForNode(n *structs.Node) *structs.Allocation {
|
|
|
|
nodeIP := n.NodeResources.NodeNetworks[0].Addresses[0].Address
|
|
|
|
|
|
|
|
dynamicPortRange := structs.DefaultMaxDynamicPort - structs.DefaultMinDynamicPort
|
|
|
|
randomDynamicPort := rand.Intn(dynamicPortRange) + structs.DefaultMinDynamicPort
|
|
|
|
|
|
|
|
alloc := Alloc()
|
|
|
|
alloc.NodeID = n.ID
|
|
|
|
|
|
|
|
// Set node IP address.
|
|
|
|
alloc.Resources.Networks[0].IP = nodeIP
|
|
|
|
alloc.TaskResources["web"].Networks[0].IP = nodeIP
|
|
|
|
alloc.AllocatedResources.Tasks["web"].Networks[0].IP = nodeIP
|
|
|
|
|
|
|
|
// Set dynamic port to a random value.
|
|
|
|
alloc.TaskResources["web"].Networks[0].DynamicPorts = []structs.Port{{Label: "http", Value: randomDynamicPort}}
|
|
|
|
alloc.AllocatedResources.Tasks["web"].Networks[0].DynamicPorts = []structs.Port{{Label: "http", Value: randomDynamicPort}}
|
|
|
|
|
|
|
|
return alloc
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func AllocForNodeWithoutReservedPort(n *structs.Node) *structs.Allocation {
|
|
|
|
nodeIP := n.NodeResources.NodeNetworks[0].Addresses[0].Address
|
|
|
|
|
|
|
|
dynamicPortRange := structs.DefaultMaxDynamicPort - structs.DefaultMinDynamicPort
|
|
|
|
randomDynamicPort := rand.Intn(dynamicPortRange) + structs.DefaultMinDynamicPort
|
|
|
|
|
|
|
|
alloc := AllocWithoutReservedPort()
|
|
|
|
alloc.NodeID = n.ID
|
|
|
|
|
|
|
|
// Set node IP address.
|
|
|
|
alloc.Resources.Networks[0].IP = nodeIP
|
|
|
|
alloc.TaskResources["web"].Networks[0].IP = nodeIP
|
|
|
|
alloc.AllocatedResources.Tasks["web"].Networks[0].IP = nodeIP
|
|
|
|
|
|
|
|
// Set dynamic port to a random value.
|
|
|
|
alloc.TaskResources["web"].Networks[0].DynamicPorts = []structs.Port{{Label: "http", Value: randomDynamicPort}}
|
|
|
|
alloc.AllocatedResources.Tasks["web"].Networks[0].DynamicPorts = []structs.Port{{Label: "http", Value: randomDynamicPort}}
|
|
|
|
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2021-08-30 09:08:12 +00:00
|
|
|
// ConnectAlloc adds a Connect proxy sidecar group service to mock.Alloc.
|
2019-09-03 15:43:38 +00:00
|
|
|
func ConnectAlloc() *structs.Allocation {
|
|
|
|
alloc := Alloc()
|
|
|
|
alloc.Job = ConnectJob()
|
|
|
|
alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Mode: "bridge",
|
|
|
|
IP: "10.0.0.1",
|
|
|
|
DynamicPorts: []structs.Port{
|
|
|
|
{
|
|
|
|
Label: "connect-proxy-testconnect",
|
|
|
|
Value: 9999,
|
|
|
|
To: 9999,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2020-07-28 20:12:08 +00:00
|
|
|
// ConnectNativeAlloc creates an alloc with a connect native task.
|
2020-07-13 21:53:10 +00:00
|
|
|
func ConnectNativeAlloc(mode string) *structs.Allocation {
|
|
|
|
alloc := Alloc()
|
|
|
|
alloc.Job = ConnectNativeJob(mode)
|
|
|
|
alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{{
|
|
|
|
Mode: mode,
|
|
|
|
IP: "10.0.0.1",
|
|
|
|
}}
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2020-07-28 20:12:08 +00:00
|
|
|
func ConnectIngressGatewayAlloc(mode string) *structs.Allocation {
|
|
|
|
alloc := Alloc()
|
|
|
|
alloc.Job = ConnectIngressGatewayJob(mode, true)
|
|
|
|
alloc.AllocatedResources.Shared.Networks = []*structs.NetworkResource{{
|
|
|
|
Mode: mode,
|
|
|
|
IP: "10.0.0.1",
|
|
|
|
}}
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2019-12-06 20:46:46 +00:00
|
|
|
func BatchConnectJob() *structs.Job {
|
|
|
|
job := &structs.Job{
|
|
|
|
Region: "global",
|
|
|
|
ID: fmt.Sprintf("mock-connect-batch-job%s", uuid.Generate()),
|
|
|
|
Name: "mock-connect-batch-job",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
Type: structs.JobTypeBatch,
|
|
|
|
Priority: 50,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
|
|
|
TaskGroups: []*structs.TaskGroup{{
|
|
|
|
Name: "mock-connect-batch-job",
|
|
|
|
Count: 1,
|
|
|
|
EphemeralDisk: &structs.EphemeralDisk{SizeMB: 150},
|
|
|
|
Networks: []*structs.NetworkResource{{
|
|
|
|
Mode: "bridge",
|
|
|
|
}},
|
|
|
|
Tasks: []*structs.Task{{
|
|
|
|
Name: "connect-proxy-testconnect",
|
|
|
|
Kind: "connect-proxy:testconnect",
|
|
|
|
Driver: "mock_driver",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"run_for": "500ms",
|
|
|
|
},
|
|
|
|
LogConfig: structs.DefaultLogConfig(),
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
Networks: []*structs.NetworkResource{{
|
|
|
|
MBits: 50,
|
|
|
|
DynamicPorts: []structs.Port{{Label: "port1"}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
Services: []*structs.Service{{
|
|
|
|
Name: "testconnect",
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
Meta: map[string]string{"owner": "shoenig"},
|
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
Version: 0,
|
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
|
|
|
JobModifyIndex: 99,
|
|
|
|
}
|
2021-01-14 20:46:35 +00:00
|
|
|
job.Canonicalize()
|
2019-12-06 20:46:46 +00:00
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
|
|
|
// BatchConnectAlloc is useful for testing task runner things.
|
|
|
|
func BatchConnectAlloc() *structs.Allocation {
|
|
|
|
alloc := &structs.Allocation{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
EvalID: uuid.Generate(),
|
|
|
|
NodeID: "12345678-abcd-efab-cdef-123456789abc",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
TaskGroup: "mock-connect-batch-job",
|
|
|
|
TaskResources: map[string]*structs.Resources{
|
|
|
|
"connect-proxy-testconnect": {
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
AllocatedResources: &structs.AllocatedResources{
|
|
|
|
Tasks: map[string]*structs.AllocatedTaskResources{
|
|
|
|
"connect-proxy-testconnect": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{CpuShares: 500},
|
|
|
|
Memory: structs.AllocatedMemoryResources{MemoryMB: 256},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Shared: structs.AllocatedSharedResources{
|
|
|
|
Networks: []*structs.NetworkResource{{
|
|
|
|
Mode: "bridge",
|
|
|
|
IP: "10.0.0.1",
|
|
|
|
DynamicPorts: []structs.Port{{
|
|
|
|
Label: "connect-proxy-testconnect",
|
|
|
|
Value: 9999,
|
|
|
|
To: 9999,
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
DiskMB: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Job: BatchConnectJob(),
|
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
|
|
|
ClientStatus: structs.AllocClientStatusPending,
|
|
|
|
}
|
|
|
|
alloc.JobID = alloc.Job.ID
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2018-03-27 21:10:14 +00:00
|
|
|
func BatchAlloc() *structs.Allocation {
|
|
|
|
alloc := &structs.Allocation{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
EvalID: uuid.Generate(),
|
|
|
|
NodeID: "12345678-abcd-efab-cdef-123456789abc",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
2018-11-16 23:29:59 +00:00
|
|
|
TaskGroup: "web",
|
2018-10-03 16:47:18 +00:00
|
|
|
|
|
|
|
// TODO Remove once clientv2 gets merged
|
2018-03-27 21:10:14 +00:00
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 150,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
|
|
|
|
MBits: 50,
|
|
|
|
DynamicPorts: []structs.Port{{Label: "http"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskResources: map[string]*structs.Resources{
|
2018-10-03 16:47:18 +00:00
|
|
|
"web": {
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
2018-03-27 21:10:14 +00:00
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
2018-10-03 16:47:18 +00:00
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
|
|
|
|
MBits: 50,
|
|
|
|
DynamicPorts: []structs.Port{{Label: "http", Value: 9876}},
|
2018-03-27 21:10:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SharedResources: &structs.Resources{
|
|
|
|
DiskMB: 150,
|
|
|
|
},
|
2018-10-03 16:47:18 +00:00
|
|
|
|
|
|
|
AllocatedResources: &structs.AllocatedResources{
|
|
|
|
Tasks: map[string]*structs.AllocatedTaskResources{
|
|
|
|
"web": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 500,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
|
|
|
|
MBits: 50,
|
|
|
|
DynamicPorts: []structs.Port{{Label: "http", Value: 9876}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Shared: structs.AllocatedSharedResources{
|
|
|
|
DiskMB: 150,
|
|
|
|
},
|
|
|
|
},
|
2018-03-27 21:10:14 +00:00
|
|
|
Job: BatchJob(),
|
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
|
|
|
ClientStatus: structs.AllocClientStatusPending,
|
|
|
|
}
|
|
|
|
alloc.JobID = alloc.Job.ID
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2020-10-09 21:31:38 +00:00
|
|
|
func SysBatchAlloc() *structs.Allocation {
|
|
|
|
job := SystemBatchJob()
|
|
|
|
return &structs.Allocation{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
EvalID: uuid.Generate(),
|
|
|
|
NodeID: "12345678-abcd-efab-cdef-123456789abc",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
TaskGroup: "pinger",
|
|
|
|
AllocatedResources: &structs.AllocatedResources{
|
|
|
|
Tasks: map[string]*structs.AllocatedTaskResources{
|
|
|
|
"ping-example": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{CpuShares: 500},
|
|
|
|
Memory: structs.AllocatedMemoryResources{MemoryMB: 256},
|
|
|
|
Networks: []*structs.NetworkResource{{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Shared: structs.AllocatedSharedResources{DiskMB: 150},
|
|
|
|
},
|
|
|
|
Job: job,
|
|
|
|
JobID: job.ID,
|
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
|
|
|
ClientStatus: structs.AllocClientStatusPending,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-27 21:10:14 +00:00
|
|
|
func SystemAlloc() *structs.Allocation {
|
|
|
|
alloc := &structs.Allocation{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
EvalID: uuid.Generate(),
|
|
|
|
NodeID: "12345678-abcd-efab-cdef-123456789abc",
|
|
|
|
Namespace: structs.DefaultNamespace,
|
|
|
|
TaskGroup: "web",
|
2018-10-03 16:47:18 +00:00
|
|
|
|
|
|
|
// TODO Remove once clientv2 gets merged
|
2018-03-27 21:10:14 +00:00
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 150,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
|
|
|
|
MBits: 50,
|
|
|
|
DynamicPorts: []structs.Port{{Label: "http"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskResources: map[string]*structs.Resources{
|
|
|
|
"web": {
|
|
|
|
CPU: 500,
|
|
|
|
MemoryMB: 256,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
|
|
|
|
MBits: 50,
|
|
|
|
DynamicPorts: []structs.Port{{Label: "http", Value: 9876}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SharedResources: &structs.Resources{
|
|
|
|
DiskMB: 150,
|
|
|
|
},
|
2018-10-03 16:47:18 +00:00
|
|
|
|
|
|
|
AllocatedResources: &structs.AllocatedResources{
|
|
|
|
Tasks: map[string]*structs.AllocatedTaskResources{
|
|
|
|
"web": {
|
|
|
|
Cpu: structs.AllocatedCpuResources{
|
|
|
|
CpuShares: 500,
|
|
|
|
},
|
|
|
|
Memory: structs.AllocatedMemoryResources{
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
{
|
|
|
|
Device: "eth0",
|
|
|
|
IP: "192.168.0.100",
|
|
|
|
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
|
|
|
|
MBits: 50,
|
|
|
|
DynamicPorts: []structs.Port{{Label: "http", Value: 9876}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Shared: structs.AllocatedSharedResources{
|
|
|
|
DiskMB: 150,
|
|
|
|
},
|
|
|
|
},
|
2018-03-27 21:10:14 +00:00
|
|
|
Job: SystemJob(),
|
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
2015-08-25 23:19:21 +00:00
|
|
|
ClientStatus: structs.AllocClientStatusPending,
|
2015-08-11 21:27:14 +00:00
|
|
|
}
|
|
|
|
alloc.JobID = alloc.Job.ID
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
2016-08-19 01:14:58 +00:00
|
|
|
func VaultAccessor() *structs.VaultAccessor {
|
|
|
|
return &structs.VaultAccessor{
|
2017-09-29 16:58:48 +00:00
|
|
|
Accessor: uuid.Generate(),
|
|
|
|
NodeID: uuid.Generate(),
|
|
|
|
AllocID: uuid.Generate(),
|
2016-08-19 01:14:58 +00:00
|
|
|
CreationTTL: 86400,
|
|
|
|
Task: "foo",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 20:46:46 +00:00
|
|
|
func SITokenAccessor() *structs.SITokenAccessor {
|
|
|
|
return &structs.SITokenAccessor{
|
|
|
|
NodeID: uuid.Generate(),
|
|
|
|
AllocID: uuid.Generate(),
|
|
|
|
AccessorID: uuid.Generate(),
|
|
|
|
TaskName: "foo",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-24 21:49:23 +00:00
|
|
|
func Deployment() *structs.Deployment {
|
|
|
|
return &structs.Deployment{
|
2017-09-29 16:58:48 +00:00
|
|
|
ID: uuid.Generate(),
|
|
|
|
JobID: uuid.Generate(),
|
2017-09-07 23:56:15 +00:00
|
|
|
Namespace: structs.DefaultNamespace,
|
2017-05-05 20:52:01 +00:00
|
|
|
JobVersion: 2,
|
|
|
|
JobModifyIndex: 20,
|
|
|
|
JobCreateIndex: 18,
|
|
|
|
TaskGroups: map[string]*structs.DeploymentState{
|
2017-09-26 22:26:33 +00:00
|
|
|
"web": {
|
2017-05-05 20:52:01 +00:00
|
|
|
DesiredTotal: 10,
|
|
|
|
},
|
|
|
|
},
|
2017-04-24 21:49:23 +00:00
|
|
|
Status: structs.DeploymentStatusRunning,
|
2017-06-29 05:00:18 +00:00
|
|
|
StatusDescription: structs.DeploymentStatusDescriptionRunning,
|
2017-04-24 21:49:23 +00:00
|
|
|
ModifyIndex: 23,
|
|
|
|
CreateIndex: 21,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-11 21:27:14 +00:00
|
|
|
func Plan() *structs.Plan {
|
|
|
|
return &structs.Plan{
|
|
|
|
Priority: 50,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func PlanResult() *structs.PlanResult {
|
|
|
|
return &structs.PlanResult{}
|
|
|
|
}
|
2017-08-07 21:21:00 +00:00
|
|
|
|
|
|
|
func ACLPolicy() *structs.ACLPolicy {
|
2017-08-30 17:06:56 +00:00
|
|
|
ap := &structs.ACLPolicy{
|
2017-09-29 16:58:48 +00:00
|
|
|
Name: fmt.Sprintf("policy-%s", uuid.Generate()),
|
2017-08-08 06:02:03 +00:00
|
|
|
Description: "Super cool policy!",
|
2017-08-07 21:21:00 +00:00
|
|
|
Rules: `
|
|
|
|
namespace "default" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
2017-08-08 06:10:39 +00:00
|
|
|
node {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
agent {
|
|
|
|
policy = "read"
|
|
|
|
}
|
2017-08-07 21:21:00 +00:00
|
|
|
`,
|
|
|
|
CreateIndex: 10,
|
|
|
|
ModifyIndex: 20,
|
|
|
|
}
|
2017-08-30 17:06:56 +00:00
|
|
|
ap.SetHash()
|
|
|
|
return ap
|
2017-08-07 21:21:00 +00:00
|
|
|
}
|
2017-08-12 22:18:47 +00:00
|
|
|
|
|
|
|
func ACLToken() *structs.ACLToken {
|
2017-08-30 17:06:56 +00:00
|
|
|
tk := &structs.ACLToken{
|
2017-09-29 16:58:48 +00:00
|
|
|
AccessorID: uuid.Generate(),
|
|
|
|
SecretID: uuid.Generate(),
|
|
|
|
Name: "my cool token " + uuid.Generate(),
|
2017-08-12 22:18:47 +00:00
|
|
|
Type: "client",
|
|
|
|
Policies: []string{"foo", "bar"},
|
|
|
|
Global: false,
|
|
|
|
CreateTime: time.Now().UTC(),
|
|
|
|
CreateIndex: 10,
|
|
|
|
ModifyIndex: 20,
|
|
|
|
}
|
2017-08-30 17:06:56 +00:00
|
|
|
tk.SetHash()
|
|
|
|
return tk
|
2017-08-12 22:18:47 +00:00
|
|
|
}
|
2017-08-21 02:59:25 +00:00
|
|
|
|
|
|
|
func ACLManagementToken() *structs.ACLToken {
|
|
|
|
return &structs.ACLToken{
|
2017-09-29 16:58:48 +00:00
|
|
|
AccessorID: uuid.Generate(),
|
|
|
|
SecretID: uuid.Generate(),
|
|
|
|
Name: "management " + uuid.Generate(),
|
2017-08-21 02:59:25 +00:00
|
|
|
Type: "management",
|
|
|
|
Global: true,
|
|
|
|
CreateTime: time.Now().UTC(),
|
|
|
|
CreateIndex: 10,
|
|
|
|
ModifyIndex: 20,
|
|
|
|
}
|
|
|
|
}
|
2020-01-15 20:51:57 +00:00
|
|
|
|
|
|
|
func ScalingPolicy() *structs.ScalingPolicy {
|
|
|
|
return &structs.ScalingPolicy{
|
2020-09-29 21:57:46 +00:00
|
|
|
ID: uuid.Generate(),
|
|
|
|
Min: 1,
|
|
|
|
Max: 100,
|
|
|
|
Type: structs.ScalingPolicyTypeHorizontal,
|
2020-02-21 21:23:30 +00:00
|
|
|
Target: map[string]string{
|
|
|
|
structs.ScalingTargetNamespace: structs.DefaultNamespace,
|
|
|
|
structs.ScalingTargetJob: uuid.Generate(),
|
|
|
|
structs.ScalingTargetGroup: uuid.Generate(),
|
2020-09-29 21:57:46 +00:00
|
|
|
structs.ScalingTargetTask: uuid.Generate(),
|
2020-02-21 21:23:30 +00:00
|
|
|
},
|
2020-01-15 20:51:57 +00:00
|
|
|
Policy: map[string]interface{}{
|
|
|
|
"a": "b",
|
|
|
|
},
|
2020-09-09 22:30:40 +00:00
|
|
|
Enabled: true,
|
2020-01-15 20:51:57 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-16 20:12:52 +00:00
|
|
|
|
|
|
|
func JobWithScalingPolicy() (*structs.Job, *structs.ScalingPolicy) {
|
|
|
|
job := Job()
|
|
|
|
policy := &structs.ScalingPolicy{
|
2020-02-21 21:23:30 +00:00
|
|
|
ID: uuid.Generate(),
|
2020-03-22 11:54:04 +00:00
|
|
|
Min: int64(job.TaskGroups[0].Count),
|
|
|
|
Max: int64(job.TaskGroups[0].Count),
|
2020-09-29 21:57:46 +00:00
|
|
|
Type: structs.ScalingPolicyTypeHorizontal,
|
2020-02-21 21:23:30 +00:00
|
|
|
Policy: map[string]interface{}{},
|
|
|
|
Enabled: true,
|
2020-01-16 20:12:52 +00:00
|
|
|
}
|
|
|
|
policy.TargetTaskGroup(job, job.TaskGroups[0])
|
|
|
|
job.TaskGroups[0].Scaling = policy
|
|
|
|
return job, policy
|
|
|
|
}
|
2020-03-30 15:17:16 +00:00
|
|
|
|
2020-06-15 20:18:14 +00:00
|
|
|
func MultiregionJob() *structs.Job {
|
|
|
|
job := Job()
|
2020-07-14 14:57:37 +00:00
|
|
|
update := *structs.DefaultUpdateStrategy
|
|
|
|
job.Update = update
|
|
|
|
job.TaskGroups[0].Update = &update
|
2020-06-15 20:18:14 +00:00
|
|
|
job.Multiregion = &structs.Multiregion{
|
|
|
|
Strategy: &structs.MultiregionStrategy{
|
|
|
|
MaxParallel: 1,
|
2020-06-16 19:17:53 +00:00
|
|
|
OnFailure: "fail_all",
|
2020-06-15 20:18:14 +00:00
|
|
|
},
|
|
|
|
Regions: []*structs.MultiregionRegion{
|
|
|
|
{
|
|
|
|
Name: "west",
|
|
|
|
Count: 2,
|
|
|
|
Datacenters: []string{"west-1", "west-2"},
|
|
|
|
Meta: map[string]string{"region_code": "W"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "east",
|
|
|
|
Count: 1,
|
|
|
|
Datacenters: []string{"east-1"},
|
|
|
|
Meta: map[string]string{"region_code": "E"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2020-03-30 15:17:16 +00:00
|
|
|
func CSIPlugin() *structs.CSIPlugin {
|
|
|
|
return &structs.CSIPlugin{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
Provider: "com.hashicorp:mock",
|
|
|
|
Version: "0.1",
|
|
|
|
ControllerRequired: true,
|
|
|
|
Controllers: map[string]*structs.CSIInfo{},
|
|
|
|
Nodes: map[string]*structs.CSIInfo{},
|
|
|
|
Allocations: []*structs.AllocListStub{},
|
|
|
|
ControllersHealthy: 0,
|
|
|
|
NodesHealthy: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func CSIVolume(plugin *structs.CSIPlugin) *structs.CSIVolume {
|
|
|
|
return &structs.CSIVolume{
|
|
|
|
ID: uuid.Generate(),
|
|
|
|
Name: "test-vol",
|
|
|
|
ExternalID: "vol-01",
|
|
|
|
Namespace: "default",
|
|
|
|
Topologies: []*structs.CSITopology{},
|
|
|
|
AccessMode: structs.CSIVolumeAccessModeSingleNodeWriter,
|
|
|
|
AttachmentMode: structs.CSIVolumeAttachmentModeFilesystem,
|
|
|
|
MountOptions: &structs.CSIMountOptions{},
|
2020-05-11 21:12:51 +00:00
|
|
|
Secrets: structs.CSISecrets{},
|
2020-05-15 12:16:01 +00:00
|
|
|
Parameters: map[string]string{},
|
|
|
|
Context: map[string]string{},
|
2020-03-30 15:17:16 +00:00
|
|
|
ReadAllocs: map[string]*structs.Allocation{},
|
|
|
|
WriteAllocs: map[string]*structs.Allocation{},
|
2020-04-23 15:06:23 +00:00
|
|
|
ReadClaims: map[string]*structs.CSIVolumeClaim{},
|
|
|
|
WriteClaims: map[string]*structs.CSIVolumeClaim{},
|
|
|
|
PastClaims: map[string]*structs.CSIVolumeClaim{},
|
2020-03-30 15:17:16 +00:00
|
|
|
PluginID: plugin.ID,
|
|
|
|
Provider: plugin.Provider,
|
|
|
|
ProviderVersion: plugin.Version,
|
|
|
|
ControllerRequired: plugin.ControllerRequired,
|
|
|
|
ControllersHealthy: plugin.ControllersHealthy,
|
|
|
|
ControllersExpected: len(plugin.Controllers),
|
|
|
|
NodesHealthy: plugin.NodesHealthy,
|
|
|
|
NodesExpected: len(plugin.Nodes),
|
|
|
|
}
|
|
|
|
}
|
2020-10-04 19:12:35 +00:00
|
|
|
|
2022-02-09 16:51:49 +00:00
|
|
|
func CSIPluginJob(pluginType structs.CSIPluginType, pluginID string) *structs.Job {
|
|
|
|
|
|
|
|
job := new(structs.Job)
|
|
|
|
|
|
|
|
switch pluginType {
|
|
|
|
case structs.CSIPluginTypeController:
|
|
|
|
job = Job()
|
|
|
|
job.ID = fmt.Sprintf("mock-controller-%s", pluginID)
|
|
|
|
job.Name = "job-plugin-controller"
|
|
|
|
job.TaskGroups[0].Count = 2
|
|
|
|
case structs.CSIPluginTypeNode:
|
|
|
|
job = SystemJob()
|
|
|
|
job.ID = fmt.Sprintf("mock-node-%s", pluginID)
|
|
|
|
job.Name = "job-plugin-node"
|
|
|
|
case structs.CSIPluginTypeMonolith:
|
|
|
|
job = SystemJob()
|
|
|
|
job.ID = fmt.Sprintf("mock-monolith-%s", pluginID)
|
|
|
|
job.Name = "job-plugin-monolith"
|
|
|
|
}
|
|
|
|
|
|
|
|
job.TaskGroups[0].Name = "plugin"
|
|
|
|
job.TaskGroups[0].Tasks[0].Name = "plugin"
|
|
|
|
job.TaskGroups[0].Tasks[0].Driver = "docker"
|
|
|
|
job.TaskGroups[0].Tasks[0].Services = nil
|
|
|
|
job.TaskGroups[0].Tasks[0].CSIPluginConfig = &structs.TaskCSIPluginConfig{
|
|
|
|
ID: pluginID,
|
|
|
|
Type: pluginType,
|
|
|
|
MountDir: "/csi",
|
|
|
|
}
|
|
|
|
job.Canonicalize()
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
2020-10-04 19:12:35 +00:00
|
|
|
func Events(index uint64) *structs.Events {
|
|
|
|
return &structs.Events{
|
|
|
|
Index: index,
|
|
|
|
Events: []structs.Event{
|
|
|
|
{
|
|
|
|
Index: index,
|
|
|
|
Topic: "Node",
|
|
|
|
Type: "update",
|
|
|
|
Key: uuid.Generate(),
|
|
|
|
Payload: Node(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Index: index,
|
|
|
|
Topic: "Eval",
|
|
|
|
Type: "update",
|
|
|
|
Key: uuid.Generate(),
|
|
|
|
Payload: Eval(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-10-20 20:15:37 +00:00
|
|
|
|
|
|
|
func AllocNetworkStatus() *structs.AllocNetworkStatus {
|
|
|
|
return &structs.AllocNetworkStatus{
|
|
|
|
InterfaceName: "eth0",
|
|
|
|
Address: "192.168.0.100",
|
|
|
|
DNS: &structs.DNSConfig{
|
|
|
|
Servers: []string{"1.1.1.1"},
|
|
|
|
Searches: []string{"localdomain"},
|
|
|
|
Options: []string{"ndots:5"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-10-21 04:16:25 +00:00
|
|
|
|
|
|
|
func Namespace() *structs.Namespace {
|
|
|
|
ns := &structs.Namespace{
|
|
|
|
Name: fmt.Sprintf("team-%s", uuid.Generate()),
|
|
|
|
Description: "test namespace",
|
|
|
|
CreateIndex: 100,
|
|
|
|
ModifyIndex: 200,
|
|
|
|
}
|
|
|
|
ns.SetHash()
|
|
|
|
return ns
|
|
|
|
}
|