Unverified Commit c4be2c60 authored by Piotr Kazmierczak's avatar Piotr Kazmierczak Committed by GitHub
Browse files

cleanup: replace TypeToPtr helper methods with pointer.Of (#14151)

Bumping compile time requirement to go 1.18 allows us to simplify our pointer helper methods.
parent b9fec224
Showing with 996 additions and 988 deletions
+996 -988
......@@ -145,7 +145,7 @@ lint-deps: ## Install linter dependencies
@echo "==> Updating linter dependencies..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0
go install github.com/client9/misspell/cmd/misspell@v0.3.4
go install github.com/hashicorp/go-hclog/hclogvet@v0.1.4
go install github.com/hashicorp/go-hclog/hclogvet@v0.1.5
.PHONY: git-hooks
git-dir = $(shell git rev-parse --git-dir)
......
......@@ -159,13 +159,13 @@ func TestAllocations_RescheduleInfo(t *testing.T) {
testutil.Parallel(t)
// Create a job, task group and alloc
job := &Job{
Name: stringToPtr("foo"),
Namespace: stringToPtr(DefaultNamespace),
ID: stringToPtr("bar"),
ParentID: stringToPtr("lol"),
Name: pointerOf("foo"),
Namespace: pointerOf(DefaultNamespace),
ID: pointerOf("bar"),
ParentID: pointerOf("lol"),
TaskGroups: []*TaskGroup{
{
Name: stringToPtr("bar"),
Name: pointerOf("bar"),
Tasks: []*Task{
{
Name: "task1",
......@@ -205,8 +205,8 @@ func TestAllocations_RescheduleInfo(t *testing.T) {
{
desc: "no reschedule events",
reschedulePolicy: &ReschedulePolicy{
Attempts: intToPtr(3),
Interval: timeToPtr(15 * time.Minute),
Attempts: pointerOf(3),
Interval: pointerOf(15 * time.Minute),
},
expAttempted: 0,
expTotal: 3,
......@@ -214,8 +214,8 @@ func TestAllocations_RescheduleInfo(t *testing.T) {
{
desc: "all reschedule events within interval",
reschedulePolicy: &ReschedulePolicy{
Attempts: intToPtr(3),
Interval: timeToPtr(15 * time.Minute),
Attempts: pointerOf(3),
Interval: pointerOf(15 * time.Minute),
},
time: time.Now(),
rescheduleTracker: &RescheduleTracker{
......@@ -231,8 +231,8 @@ func TestAllocations_RescheduleInfo(t *testing.T) {
{
desc: "some reschedule events outside interval",
reschedulePolicy: &ReschedulePolicy{
Attempts: intToPtr(3),
Interval: timeToPtr(15 * time.Minute),
Attempts: pointerOf(3),
Interval: pointerOf(15 * time.Minute),
},
time: time.Now(),
rescheduleTracker: &RescheduleTracker{
......@@ -276,13 +276,13 @@ func TestAllocations_ExecErrors(t *testing.T) {
a := c.Allocations()
job := &Job{
Name: stringToPtr("foo"),
Namespace: stringToPtr(DefaultNamespace),
ID: stringToPtr("bar"),
ParentID: stringToPtr("lol"),
Name: pointerOf("foo"),
Namespace: pointerOf(DefaultNamespace),
ID: pointerOf("bar"),
ParentID: pointerOf("lol"),
TaskGroups: []*TaskGroup{
{
Name: stringToPtr("bar"),
Name: pointerOf("bar"),
Tasks: []*Task{
{
Name: "task1",
......@@ -392,9 +392,9 @@ func TestAllocation_ClientTerminalStatus(t *testing.T) {
func TestAllocations_ShouldMigrate(t *testing.T) {
testutil.Parallel(t)
require.True(t, DesiredTransition{Migrate: boolToPtr(true)}.ShouldMigrate())
require.True(t, DesiredTransition{Migrate: pointerOf(true)}.ShouldMigrate())
require.False(t, DesiredTransition{}.ShouldMigrate())
require.False(t, DesiredTransition{Migrate: boolToPtr(false)}.ShouldMigrate())
require.False(t, DesiredTransition{Migrate: pointerOf(false)}.ShouldMigrate())
}
func TestAllocations_Services(t *testing.T) {
......
......@@ -15,13 +15,13 @@ func TestCompose(t *testing.T) {
SetMeta("foo", "bar").
Constrain(NewConstraint("kernel.name", "=", "linux")).
Require(&Resources{
CPU: intToPtr(1250),
MemoryMB: intToPtr(1024),
DiskMB: intToPtr(2048),
CPU: pointerOf(1250),
MemoryMB: pointerOf(1024),
DiskMB: pointerOf(2048),
Networks: []*NetworkResource{
{
CIDR: "0.0.0.0/0",
MBits: intToPtr(100),
MBits: pointerOf(100),
ReservedPorts: []Port{{"", 80, 0, ""}, {"", 443, 0, ""}},
},
},
......@@ -47,11 +47,11 @@ func TestCompose(t *testing.T) {
// Check that the composed result looks correct
expect := &Job{
Region: stringToPtr("global"),
ID: stringToPtr("job1"),
Name: stringToPtr("myjob"),
Type: stringToPtr(JobTypeService),
Priority: intToPtr(2),
Region: pointerOf("global"),
ID: pointerOf("job1"),
Name: pointerOf("myjob"),
Type: pointerOf(JobTypeService),
Priority: pointerOf(2),
Datacenters: []string{
"dc1",
},
......@@ -67,8 +67,8 @@ func TestCompose(t *testing.T) {
},
TaskGroups: []*TaskGroup{
{
Name: stringToPtr("grp1"),
Count: intToPtr(2),
Name: pointerOf("grp1"),
Count: pointerOf(2),
Constraints: []*Constraint{
{
LTarget: "kernel.name",
......@@ -81,13 +81,13 @@ func TestCompose(t *testing.T) {
LTarget: "${node.class}",
RTarget: "large",
Operand: "=",
Weight: int8ToPtr(50),
Weight: pointerOf(int8(50)),
},
},
Spreads: []*Spread{
{
Attribute: "${node.datacenter}",
Weight: int8ToPtr(30),
Weight: pointerOf(int8(30)),
SpreadTarget: []*SpreadTarget{
{
Value: "dc1",
......@@ -105,13 +105,13 @@ func TestCompose(t *testing.T) {
Name: "task1",
Driver: "exec",
Resources: &Resources{
CPU: intToPtr(1250),
MemoryMB: intToPtr(1024),
DiskMB: intToPtr(2048),
CPU: pointerOf(1250),
MemoryMB: pointerOf(1024),
DiskMB: pointerOf(2048),
Networks: []*NetworkResource{
{
CIDR: "0.0.0.0/0",
MBits: intToPtr(100),
MBits: pointerOf(100),
ReservedPorts: []Port{
{"", 80, 0, ""},
{"", 443, 0, ""},
......
package api
import "time"
import (
"time"
)
// Consul represents configuration related to consul.
type Consul struct {
......@@ -121,11 +123,11 @@ func (st *SidecarTask) Canonicalize() {
}
if st.KillTimeout == nil {
st.KillTimeout = timeToPtr(5 * time.Second)
st.KillTimeout = pointerOf(5 * time.Second)
}
if st.ShutdownDelay == nil {
st.ShutdownDelay = timeToPtr(0)
st.ShutdownDelay = pointerOf(time.Duration(0))
}
}
......@@ -313,7 +315,7 @@ func (p *ConsulGatewayProxy) Canonicalize() {
if p.ConnectTimeout == nil {
// same as the default from consul
p.ConnectTimeout = timeToPtr(defaultGatewayConnectTimeout)
p.ConnectTimeout = pointerOf(defaultGatewayConnectTimeout)
}
if len(p.EnvoyGatewayBindAddresses) == 0 {
......@@ -347,7 +349,7 @@ func (p *ConsulGatewayProxy) Copy() *ConsulGatewayProxy {
}
return &ConsulGatewayProxy{
ConnectTimeout: timeToPtr(*p.ConnectTimeout),
ConnectTimeout: pointerOf(*p.ConnectTimeout),
EnvoyGatewayBindTaggedAddresses: p.EnvoyGatewayBindTaggedAddresses,
EnvoyGatewayBindAddresses: binds,
EnvoyGatewayNoDefaultBind: p.EnvoyGatewayNoDefaultBind,
......
......@@ -39,7 +39,7 @@ func TestConsul_MergeNamespace(t *testing.T) {
testutil.Parallel(t)
t.Run("already set", func(t *testing.T) {
a := &Consul{Namespace: "foo"}
ns := stringToPtr("bar")
ns := pointerOf("bar")
a.MergeNamespace(ns)
require.Equal(t, "foo", a.Namespace)
require.Equal(t, "bar", *ns)
......@@ -47,7 +47,7 @@ func TestConsul_MergeNamespace(t *testing.T) {
t.Run("inherit", func(t *testing.T) {
a := &Consul{Namespace: ""}
ns := stringToPtr("bar")
ns := pointerOf("bar")
a.MergeNamespace(ns)
require.Equal(t, "bar", a.Namespace)
require.Equal(t, "bar", *ns)
......@@ -228,9 +228,9 @@ func TestSidecarTask_Canonicalize(t *testing.T) {
t.Run("non empty sidecar_task resources", func(t *testing.T) {
exp := DefaultResources()
exp.MemoryMB = intToPtr(333)
exp.MemoryMB = pointerOf(333)
st := &SidecarTask{
Resources: &Resources{MemoryMB: intToPtr(333)},
Resources: &Resources{MemoryMB: pointerOf(333)},
}
st.Canonicalize()
require.Equal(t, exp, st.Resources)
......@@ -263,7 +263,7 @@ func TestConsulGateway_Canonicalize(t *testing.T) {
},
}
cg.Canonicalize()
require.Equal(t, timeToPtr(5*time.Second), cg.Proxy.ConnectTimeout)
require.Equal(t, pointerOf(5*time.Second), cg.Proxy.ConnectTimeout)
require.True(t, cg.Proxy.EnvoyGatewayBindTaggedAddresses)
require.Nil(t, cg.Proxy.EnvoyGatewayBindAddresses)
require.True(t, cg.Proxy.EnvoyGatewayNoDefaultBind)
......@@ -283,7 +283,7 @@ func TestConsulGateway_Copy(t *testing.T) {
gateway := &ConsulGateway{
Proxy: &ConsulGatewayProxy{
ConnectTimeout: timeToPtr(3 * time.Second),
ConnectTimeout: pointerOf(3 * time.Second),
EnvoyGatewayBindTaggedAddresses: true,
EnvoyGatewayBindAddresses: map[string]*ConsulGatewayBindAddress{
"listener1": {Address: "10.0.0.1", Port: 2000},
......
......@@ -240,8 +240,8 @@ func TestEventStream_PayloadValueHelpers(t *testing.T) {
j, err := event.Job()
require.NoError(t, err)
require.Equal(t, &Job{
ID: stringToPtr("some-id"),
Namespace: stringToPtr("some-namespace-id"),
ID: pointerOf("some-id"),
Namespace: pointerOf("some-namespace-id"),
}, j)
},
},
......
......@@ -63,13 +63,13 @@ func TestFS_Logs(t *testing.T) {
}
job := &Job{
ID: stringToPtr("TestFS_Logs"),
Region: stringToPtr("global"),
ID: pointerOf("TestFS_Logs"),
Region: pointerOf("global"),
Datacenters: []string{"dc1"},
Type: stringToPtr("batch"),
Type: pointerOf("batch"),
TaskGroups: []*TaskGroup{
{
Name: stringToPtr("TestFS_LogsGroup"),
Name: pointerOf("TestFS_LogsGroup"),
Tasks: []*Task{
{
Name: "logger",
......
module github.com/hashicorp/nomad/api
go 1.17
go 1.18
require (
github.com/docker/go-units v0.4.0
......@@ -11,11 +11,13 @@ require (
github.com/kr/pretty v0.3.0
github.com/mitchellh/go-testing-interface v1.14.1
github.com/mitchellh/mapstructure v1.5.0
github.com/shoenig/test v0.3.0
github.com/stretchr/testify v1.8.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
......
......@@ -4,6 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/cronexpr v1.1.1 h1:NJZDd87hGXjoZBdvyCF9mX4DCq5Wy7+A/w+A7q0wn6c=
......@@ -29,6 +31,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/shoenig/test v0.3.0 h1:H6tfSvgLrPHRR5NH9S40+lOfoyeH2PbswBr4twgn9Po=
github.com/shoenig/test v0.3.0/go.mod h1:xYtyGBC5Q3kzCNyJg/SjgNpfAa2kvmgA0i5+lQso8x0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
......
......@@ -189,7 +189,7 @@ func (j *Jobs) Scale(jobID, group string, count *int, message string, error bool
var count64 *int64
if count != nil {
count64 = int64ToPtr(int64(*count))
count64 = pointerOf(int64(*count))
}
req := &ScalingRequest{
Count: count64,
......@@ -513,15 +513,15 @@ type UpdateStrategy struct {
// jobs with the old policy or for populating field defaults.
func DefaultUpdateStrategy() *UpdateStrategy {
return &UpdateStrategy{
Stagger: timeToPtr(30 * time.Second),
MaxParallel: intToPtr(1),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(10 * time.Second),
HealthyDeadline: timeToPtr(5 * time.Minute),
ProgressDeadline: timeToPtr(10 * time.Minute),
AutoRevert: boolToPtr(false),
Canary: intToPtr(0),
AutoPromote: boolToPtr(false),
Stagger: pointerOf(30 * time.Second),
MaxParallel: pointerOf(1),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(10 * time.Second),
HealthyDeadline: pointerOf(5 * time.Minute),
ProgressDeadline: pointerOf(10 * time.Minute),
AutoRevert: pointerOf(false),
Canary: pointerOf(0),
AutoPromote: pointerOf(false),
}
}
......@@ -533,39 +533,39 @@ func (u *UpdateStrategy) Copy() *UpdateStrategy {
copy := new(UpdateStrategy)
if u.Stagger != nil {
copy.Stagger = timeToPtr(*u.Stagger)
copy.Stagger = pointerOf(*u.Stagger)
}
if u.MaxParallel != nil {
copy.MaxParallel = intToPtr(*u.MaxParallel)
copy.MaxParallel = pointerOf(*u.MaxParallel)
}
if u.HealthCheck != nil {
copy.HealthCheck = stringToPtr(*u.HealthCheck)
copy.HealthCheck = pointerOf(*u.HealthCheck)
}
if u.MinHealthyTime != nil {
copy.MinHealthyTime = timeToPtr(*u.MinHealthyTime)
copy.MinHealthyTime = pointerOf(*u.MinHealthyTime)
}
if u.HealthyDeadline != nil {
copy.HealthyDeadline = timeToPtr(*u.HealthyDeadline)
copy.HealthyDeadline = pointerOf(*u.HealthyDeadline)
}
if u.ProgressDeadline != nil {
copy.ProgressDeadline = timeToPtr(*u.ProgressDeadline)
copy.ProgressDeadline = pointerOf(*u.ProgressDeadline)
}
if u.AutoRevert != nil {
copy.AutoRevert = boolToPtr(*u.AutoRevert)
copy.AutoRevert = pointerOf(*u.AutoRevert)
}
if u.Canary != nil {
copy.Canary = intToPtr(*u.Canary)
copy.Canary = pointerOf(*u.Canary)
}
if u.AutoPromote != nil {
copy.AutoPromote = boolToPtr(*u.AutoPromote)
copy.AutoPromote = pointerOf(*u.AutoPromote)
}
return copy
......@@ -577,39 +577,39 @@ func (u *UpdateStrategy) Merge(o *UpdateStrategy) {
}
if o.Stagger != nil {
u.Stagger = timeToPtr(*o.Stagger)
u.Stagger = pointerOf(*o.Stagger)
}
if o.MaxParallel != nil {
u.MaxParallel = intToPtr(*o.MaxParallel)
u.MaxParallel = pointerOf(*o.MaxParallel)
}
if o.HealthCheck != nil {
u.HealthCheck = stringToPtr(*o.HealthCheck)
u.HealthCheck = pointerOf(*o.HealthCheck)
}
if o.MinHealthyTime != nil {
u.MinHealthyTime = timeToPtr(*o.MinHealthyTime)
u.MinHealthyTime = pointerOf(*o.MinHealthyTime)
}
if o.HealthyDeadline != nil {
u.HealthyDeadline = timeToPtr(*o.HealthyDeadline)
u.HealthyDeadline = pointerOf(*o.HealthyDeadline)
}
if o.ProgressDeadline != nil {
u.ProgressDeadline = timeToPtr(*o.ProgressDeadline)
u.ProgressDeadline = pointerOf(*o.ProgressDeadline)
}
if o.AutoRevert != nil {
u.AutoRevert = boolToPtr(*o.AutoRevert)
u.AutoRevert = pointerOf(*o.AutoRevert)
}
if o.Canary != nil {
u.Canary = intToPtr(*o.Canary)
u.Canary = pointerOf(*o.Canary)
}
if o.AutoPromote != nil {
u.AutoPromote = boolToPtr(*o.AutoPromote)
u.AutoPromote = pointerOf(*o.AutoPromote)
}
}
......@@ -706,15 +706,15 @@ type Multiregion struct {
func (m *Multiregion) Canonicalize() {
if m.Strategy == nil {
m.Strategy = &MultiregionStrategy{
MaxParallel: intToPtr(0),
OnFailure: stringToPtr(""),
MaxParallel: pointerOf(0),
OnFailure: pointerOf(""),
}
} else {
if m.Strategy.MaxParallel == nil {
m.Strategy.MaxParallel = intToPtr(0)
m.Strategy.MaxParallel = pointerOf(0)
}
if m.Strategy.OnFailure == nil {
m.Strategy.OnFailure = stringToPtr("")
m.Strategy.OnFailure = pointerOf("")
}
}
if m.Regions == nil {
......@@ -722,7 +722,7 @@ func (m *Multiregion) Canonicalize() {
}
for _, region := range m.Regions {
if region.Count == nil {
region.Count = intToPtr(1)
region.Count = pointerOf(1)
}
if region.Datacenters == nil {
region.Datacenters = []string{}
......@@ -740,13 +740,13 @@ func (m *Multiregion) Copy() *Multiregion {
copy := new(Multiregion)
if m.Strategy != nil {
copy.Strategy = new(MultiregionStrategy)
copy.Strategy.MaxParallel = intToPtr(*m.Strategy.MaxParallel)
copy.Strategy.OnFailure = stringToPtr(*m.Strategy.OnFailure)
copy.Strategy.MaxParallel = pointerOf(*m.Strategy.MaxParallel)
copy.Strategy.OnFailure = pointerOf(*m.Strategy.OnFailure)
}
for _, region := range m.Regions {
copyRegion := new(MultiregionRegion)
copyRegion.Name = region.Name
copyRegion.Count = intToPtr(*region.Count)
copyRegion.Count = pointerOf(*region.Count)
copyRegion.Datacenters = append(copyRegion.Datacenters, region.Datacenters...)
for k, v := range region.Meta {
copyRegion.Meta[k] = v
......@@ -779,19 +779,19 @@ type PeriodicConfig struct {
func (p *PeriodicConfig) Canonicalize() {
if p.Enabled == nil {
p.Enabled = boolToPtr(true)
p.Enabled = pointerOf(true)
}
if p.Spec == nil {
p.Spec = stringToPtr("")
p.Spec = pointerOf("")
}
if p.SpecType == nil {
p.SpecType = stringToPtr(PeriodicSpecCron)
p.SpecType = pointerOf(PeriodicSpecCron)
}
if p.ProhibitOverlap == nil {
p.ProhibitOverlap = boolToPtr(false)
p.ProhibitOverlap = pointerOf(false)
}
if p.TimeZone == nil || *p.TimeZone == "" {
p.TimeZone = stringToPtr("UTC")
p.TimeZone = pointerOf("UTC")
}
}
......@@ -904,70 +904,70 @@ func (j *Job) IsMultiregion() bool {
func (j *Job) Canonicalize() {
if j.ID == nil {
j.ID = stringToPtr("")
j.ID = pointerOf("")
}
if j.Name == nil {
j.Name = stringToPtr(*j.ID)
j.Name = pointerOf(*j.ID)
}
if j.ParentID == nil {
j.ParentID = stringToPtr("")
j.ParentID = pointerOf("")
}
if j.Namespace == nil {
j.Namespace = stringToPtr(DefaultNamespace)
j.Namespace = pointerOf(DefaultNamespace)
}
if j.Priority == nil {
j.Priority = intToPtr(50)
j.Priority = pointerOf(50)
}
if j.Stop == nil {
j.Stop = boolToPtr(false)
j.Stop = pointerOf(false)
}
if j.Region == nil {
j.Region = stringToPtr(GlobalRegion)
j.Region = pointerOf(GlobalRegion)
}
if j.Namespace == nil {
j.Namespace = stringToPtr("default")
j.Namespace = pointerOf("default")
}
if j.Type == nil {
j.Type = stringToPtr("service")
j.Type = pointerOf("service")
}
if j.AllAtOnce == nil {
j.AllAtOnce = boolToPtr(false)
j.AllAtOnce = pointerOf(false)
}
if j.ConsulToken == nil {
j.ConsulToken = stringToPtr("")
j.ConsulToken = pointerOf("")
}
if j.ConsulNamespace == nil {
j.ConsulNamespace = stringToPtr("")
j.ConsulNamespace = pointerOf("")
}
if j.VaultToken == nil {
j.VaultToken = stringToPtr("")
j.VaultToken = pointerOf("")
}
if j.VaultNamespace == nil {
j.VaultNamespace = stringToPtr("")
j.VaultNamespace = pointerOf("")
}
if j.NomadTokenID == nil {
j.NomadTokenID = stringToPtr("")
j.NomadTokenID = pointerOf("")
}
if j.Status == nil {
j.Status = stringToPtr("")
j.Status = pointerOf("")
}
if j.StatusDescription == nil {
j.StatusDescription = stringToPtr("")
j.StatusDescription = pointerOf("")
}
if j.Stable == nil {
j.Stable = boolToPtr(false)
j.Stable = pointerOf(false)
}
if j.Version == nil {
j.Version = uint64ToPtr(0)
j.Version = pointerOf(uint64(0))
}
if j.CreateIndex == nil {
j.CreateIndex = uint64ToPtr(0)
j.CreateIndex = pointerOf(uint64(0))
}
if j.ModifyIndex == nil {
j.ModifyIndex = uint64ToPtr(0)
j.ModifyIndex = pointerOf(uint64(0))
}
if j.JobModifyIndex == nil {
j.JobModifyIndex = uint64ToPtr(0)
j.JobModifyIndex = pointerOf(uint64(0))
}
if j.Periodic != nil {
j.Periodic.Canonicalize()
......
This diff is collapsed.
......@@ -669,15 +669,15 @@ func TestNodeStatValueFormatting(t *testing.T) {
}{
{
"true",
StatValue{BoolVal: boolToPtr(true)},
StatValue{BoolVal: pointerOf(true)},
},
{
"false",
StatValue{BoolVal: boolToPtr(false)},
StatValue{BoolVal: pointerOf(false)},
},
{
"myvalue",
StatValue{StringVal: stringToPtr("myvalue")},
StatValue{StringVal: pointerOf("myvalue")},
},
{
"2.718",
......@@ -710,28 +710,28 @@ func TestNodeStatValueFormatting(t *testing.T) {
{
"2",
StatValue{
IntNumeratorVal: int64ToPtr(2),
IntNumeratorVal: pointerOf(int64(2)),
},
},
{
"2 / 3",
StatValue{
IntNumeratorVal: int64ToPtr(2),
IntDenominatorVal: int64ToPtr(3),
IntNumeratorVal: pointerOf(int64(2)),
IntDenominatorVal: pointerOf(int64(3)),
},
},
{
"2 MHz",
StatValue{
IntNumeratorVal: int64ToPtr(2),
IntNumeratorVal: pointerOf(int64(2)),
Unit: "MHz",
},
},
{
"2 / 3 MHz",
StatValue{
IntNumeratorVal: int64ToPtr(2),
IntDenominatorVal: int64ToPtr(3),
IntNumeratorVal: pointerOf(int64(2)),
IntDenominatorVal: pointerOf(int64(3)),
Unit: "MHz",
},
},
......
......@@ -38,7 +38,7 @@ func (r *Resources) Canonicalize() {
// CPU will be set to the default if cores is nil above.
// If cpu is nil here then cores has been set and cpu should be 0
if r.CPU == nil {
r.CPU = intToPtr(0)
r.CPU = pointerOf(0)
}
if r.MemoryMB == nil {
......@@ -55,9 +55,9 @@ func (r *Resources) Canonicalize() {
// and should be kept in sync.
func DefaultResources() *Resources {
return &Resources{
CPU: intToPtr(100),
Cores: intToPtr(0),
MemoryMB: intToPtr(300),
CPU: pointerOf(100),
Cores: pointerOf(0),
MemoryMB: pointerOf(300),
}
}
......@@ -68,9 +68,9 @@ func DefaultResources() *Resources {
// IN nomad/structs/structs.go and should be kept in sync.
func MinResources() *Resources {
return &Resources{
CPU: intToPtr(1),
Cores: intToPtr(0),
MemoryMB: intToPtr(10),
CPU: pointerOf(1),
Cores: pointerOf(0),
MemoryMB: pointerOf(10),
}
}
......@@ -268,7 +268,7 @@ type RequestedDevice struct {
func (d *RequestedDevice) Canonicalize() {
if d.Count == nil {
d.Count = uint64ToPtr(1)
d.Count = pointerOf(uint64(1))
}
for _, a := range d.Affinities {
......
......@@ -23,25 +23,25 @@ func TestResources_Canonicalize(t *testing.T) {
{
name: "cores",
input: &Resources{
Cores: intToPtr(2),
MemoryMB: intToPtr(1024),
Cores: pointerOf(2),
MemoryMB: pointerOf(1024),
},
expected: &Resources{
CPU: intToPtr(0),
Cores: intToPtr(2),
MemoryMB: intToPtr(1024),
CPU: pointerOf(0),
Cores: pointerOf(2),
MemoryMB: pointerOf(1024),
},
},
{
name: "cpu",
input: &Resources{
CPU: intToPtr(500),
MemoryMB: intToPtr(1024),
CPU: pointerOf(500),
MemoryMB: pointerOf(1024),
},
expected: &Resources{
CPU: intToPtr(500),
Cores: intToPtr(0),
MemoryMB: intToPtr(1024),
CPU: pointerOf(500),
Cores: pointerOf(0),
MemoryMB: pointerOf(1024),
},
},
}
......
......@@ -35,7 +35,7 @@ func (s *Scaling) GetPolicy(id string, q *QueryOptions) (*ScalingPolicy, *QueryM
func (p *ScalingPolicy) Canonicalize(taskGroupCount int) {
if p.Enabled == nil {
p.Enabled = boolToPtr(true)
p.Enabled = pointerOf(true)
}
if p.Min == nil {
var m int64 = int64(taskGroupCount)
......
......@@ -24,7 +24,7 @@ func TestScalingPolicies_ListPolicies(t *testing.T) {
// Register a job with a scaling policy
job := testJob()
job.TaskGroups[0].Scaling = &ScalingPolicy{
Max: int64ToPtr(100),
Max: pointerOf(int64(100)),
}
_, _, err = jobs.Register(job, nil)
require.NoError(err)
......@@ -77,9 +77,9 @@ func TestScalingPolicies_GetPolicy(t *testing.T) {
// Register a job with a scaling policy
job := testJob()
policy := &ScalingPolicy{
Enabled: boolToPtr(true),
Min: int64ToPtr(1),
Max: int64ToPtr(1),
Enabled: pointerOf(true),
Min: pointerOf(int64(1)),
Max: pointerOf(int64(1)),
Policy: map[string]interface{}{
"key": "value",
},
......
......@@ -144,7 +144,7 @@ func (c *CheckRestart) Canonicalize() {
}
if c.Grace == nil {
c.Grace = timeToPtr(1 * time.Second)
c.Grace = pointerOf(1 * time.Second)
}
}
......
......@@ -24,8 +24,8 @@ func TestServiceRegistrations_Delete(t *testing.T) {
func TestService_Canonicalize(t *testing.T) {
testutil.Parallel(t)
j := &Job{Name: stringToPtr("job")}
tg := &TaskGroup{Name: stringToPtr("group")}
j := &Job{Name: pointerOf("job")}
tg := &TaskGroup{Name: pointerOf("group")}
task := &Task{Name: "task"}
s := &Service{
TaggedAddresses: make(map[string]string),
......@@ -45,8 +45,8 @@ func TestService_Canonicalize(t *testing.T) {
func TestServiceCheck_Canonicalize(t *testing.T) {
testutil.Parallel(t)
j := &Job{Name: stringToPtr("job")}
tg := &TaskGroup{Name: stringToPtr("group")}
j := &Job{Name: pointerOf("job")}
tg := &TaskGroup{Name: pointerOf("group")}
task := &Task{Name: "task"}
s := &Service{
Checks: []ServiceCheck{
......@@ -64,8 +64,8 @@ func TestServiceCheck_Canonicalize(t *testing.T) {
func TestService_Check_PassFail(t *testing.T) {
testutil.Parallel(t)
job := &Job{Name: stringToPtr("job")}
tg := &TaskGroup{Name: stringToPtr("group")}
job := &Job{Name: pointerOf("job")}
tg := &TaskGroup{Name: pointerOf("group")}
task := &Task{Name: "task"}
t.Run("enforce minimums", func(t *testing.T) {
......@@ -100,13 +100,13 @@ func TestService_Check_PassFail(t *testing.T) {
func TestService_CheckRestart(t *testing.T) {
testutil.Parallel(t)
job := &Job{Name: stringToPtr("job")}
tg := &TaskGroup{Name: stringToPtr("group")}
job := &Job{Name: pointerOf("job")}
tg := &TaskGroup{Name: pointerOf("group")}
task := &Task{Name: "task"}
service := &Service{
CheckRestart: &CheckRestart{
Limit: 11,
Grace: timeToPtr(11 * time.Second),
Grace: pointerOf(11 * time.Second),
IgnoreWarnings: true,
},
Checks: []ServiceCheck{
......@@ -114,7 +114,7 @@ func TestService_CheckRestart(t *testing.T) {
Name: "all-set",
CheckRestart: &CheckRestart{
Limit: 22,
Grace: timeToPtr(22 * time.Second),
Grace: pointerOf(22 * time.Second),
IgnoreWarnings: true,
},
},
......@@ -122,7 +122,7 @@ func TestService_CheckRestart(t *testing.T) {
Name: "some-set",
CheckRestart: &CheckRestart{
Limit: 33,
Grace: timeToPtr(33 * time.Second),
Grace: pointerOf(33 * time.Second),
},
},
{
......@@ -148,8 +148,8 @@ func TestService_CheckRestart(t *testing.T) {
func TestService_Connect_proxy_settings(t *testing.T) {
testutil.Parallel(t)
job := &Job{Name: stringToPtr("job")}
tg := &TaskGroup{Name: stringToPtr("group")}
job := &Job{Name: pointerOf("job")}
tg := &TaskGroup{Name: pointerOf("group")}
task := &Task{Name: "task"}
service := &Service{
Connect: &ConsulConnect{
......@@ -183,8 +183,8 @@ func TestService_Tags(t *testing.T) {
r := require.New(t)
// canonicalize does not modify eto or tags
job := &Job{Name: stringToPtr("job")}
tg := &TaskGroup{Name: stringToPtr("group")}
job := &Job{Name: pointerOf("job")}
tg := &TaskGroup{Name: pointerOf("group")}
task := &Task{Name: "task"}
service := &Service{
Tags: []string{"a", "b"},
......
......@@ -170,13 +170,13 @@ func NewAffinity(lTarget string, operand string, rTarget string, weight int8) *A
LTarget: lTarget,
RTarget: rTarget,
Operand: operand,
Weight: int8ToPtr(weight),
Weight: pointerOf(int8(weight)),
}
}
func (a *Affinity) Canonicalize() {
if a.Weight == nil {
a.Weight = int8ToPtr(50)
a.Weight = pointerOf(int8(50))
}
}
......@@ -187,35 +187,35 @@ func NewDefaultReschedulePolicy(jobType string) *ReschedulePolicy {
// This needs to be in sync with DefaultServiceJobReschedulePolicy
// in nomad/structs/structs.go
dp = &ReschedulePolicy{
Delay: timeToPtr(30 * time.Second),
DelayFunction: stringToPtr("exponential"),
MaxDelay: timeToPtr(1 * time.Hour),
Unlimited: boolToPtr(true),
Delay: pointerOf(30 * time.Second),
DelayFunction: pointerOf("exponential"),
MaxDelay: pointerOf(1 * time.Hour),
Unlimited: pointerOf(true),
Attempts: intToPtr(0),
Interval: timeToPtr(0),
Attempts: pointerOf(0),
Interval: pointerOf(time.Duration(0)),
}
case "batch":
// This needs to be in sync with DefaultBatchJobReschedulePolicy
// in nomad/structs/structs.go
dp = &ReschedulePolicy{
Attempts: intToPtr(1),
Interval: timeToPtr(24 * time.Hour),
Delay: timeToPtr(5 * time.Second),
DelayFunction: stringToPtr("constant"),
Attempts: pointerOf(1),
Interval: pointerOf(24 * time.Hour),
Delay: pointerOf(5 * time.Second),
DelayFunction: pointerOf("constant"),
MaxDelay: timeToPtr(0),
Unlimited: boolToPtr(false),
MaxDelay: pointerOf(time.Duration(0)),
Unlimited: pointerOf(false),
}
case "system":
dp = &ReschedulePolicy{
Attempts: intToPtr(0),
Interval: timeToPtr(0),
Delay: timeToPtr(0),
DelayFunction: stringToPtr(""),
MaxDelay: timeToPtr(0),
Unlimited: boolToPtr(false),
Attempts: pointerOf(0),
Interval: pointerOf(time.Duration(0)),
Delay: pointerOf(time.Duration(0)),
DelayFunction: pointerOf(""),
MaxDelay: pointerOf(time.Duration(0)),
Unlimited: pointerOf(false),
}
default:
......@@ -223,12 +223,12 @@ func NewDefaultReschedulePolicy(jobType string) *ReschedulePolicy {
// function and we need to ensure a non-nil object is returned so that
// the canonicalization runs without panicking.
dp = &ReschedulePolicy{
Attempts: intToPtr(0),
Interval: timeToPtr(0),
Delay: timeToPtr(0),
DelayFunction: stringToPtr(""),
MaxDelay: timeToPtr(0),
Unlimited: boolToPtr(false),
Attempts: pointerOf(0),
Interval: pointerOf(time.Duration(0)),
Delay: pointerOf(time.Duration(0)),
DelayFunction: pointerOf(""),
MaxDelay: pointerOf(time.Duration(0)),
Unlimited: pointerOf(false),
}
}
return dp
......@@ -276,14 +276,14 @@ func NewSpreadTarget(value string, percent uint8) *SpreadTarget {
func NewSpread(attribute string, weight int8, spreadTargets []*SpreadTarget) *Spread {
return &Spread{
Attribute: attribute,
Weight: int8ToPtr(weight),
Weight: pointerOf(int8(weight)),
SpreadTarget: spreadTargets,
}
}
func (s *Spread) Canonicalize() {
if s.Weight == nil {
s.Weight = int8ToPtr(50)
s.Weight = pointerOf(int8(50))
}
}
......@@ -296,21 +296,21 @@ type EphemeralDisk struct {
func DefaultEphemeralDisk() *EphemeralDisk {
return &EphemeralDisk{
Sticky: boolToPtr(false),
Migrate: boolToPtr(false),
SizeMB: intToPtr(300),
Sticky: pointerOf(false),
Migrate: pointerOf(false),
SizeMB: pointerOf(300),
}
}
func (e *EphemeralDisk) Canonicalize() {
if e.Sticky == nil {
e.Sticky = boolToPtr(false)
e.Sticky = pointerOf(false)
}
if e.Migrate == nil {
e.Migrate = boolToPtr(false)
e.Migrate = pointerOf(false)
}
if e.SizeMB == nil {
e.SizeMB = intToPtr(300)
e.SizeMB = pointerOf(300)
}
}
......@@ -325,10 +325,10 @@ type MigrateStrategy struct {
func DefaultMigrateStrategy() *MigrateStrategy {
return &MigrateStrategy{
MaxParallel: intToPtr(1),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(10 * time.Second),
HealthyDeadline: timeToPtr(5 * time.Minute),
MaxParallel: pointerOf(1),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(10 * time.Second),
HealthyDeadline: pointerOf(5 * time.Minute),
}
}
......@@ -405,10 +405,10 @@ type VolumeMount struct {
func (vm *VolumeMount) Canonicalize() {
if vm.PropagationMode == nil {
vm.PropagationMode = stringToPtr(VolumeMountPropagationPrivate)
vm.PropagationMode = pointerOf(VolumeMountPropagationPrivate)
}
if vm.ReadOnly == nil {
vm.ReadOnly = boolToPtr(false)
vm.ReadOnly = pointerOf(false)
}
}
......@@ -439,22 +439,22 @@ type TaskGroup struct {
// NewTaskGroup creates a new TaskGroup.
func NewTaskGroup(name string, count int) *TaskGroup {
return &TaskGroup{
Name: stringToPtr(name),
Count: intToPtr(count),
Name: pointerOf(name),
Count: pointerOf(count),
}
}
// Canonicalize sets defaults and merges settings that should be inherited from the job
func (g *TaskGroup) Canonicalize(job *Job) {
if g.Name == nil {
g.Name = stringToPtr("")
g.Name = pointerOf("")
}
if g.Count == nil {
if g.Scaling != nil && g.Scaling.Min != nil {
g.Count = intToPtr(int(*g.Scaling.Min))
g.Count = pointerOf(int(*g.Scaling.Min))
} else {
g.Count = intToPtr(1)
g.Count = pointerOf(1)
}
}
if g.Scaling != nil {
......@@ -558,10 +558,10 @@ func (g *TaskGroup) Canonicalize(job *Job) {
// in nomad/structs/structs.go
func defaultServiceJobRestartPolicy() *RestartPolicy {
return &RestartPolicy{
Delay: timeToPtr(15 * time.Second),
Attempts: intToPtr(2),
Interval: timeToPtr(30 * time.Minute),
Mode: stringToPtr(RestartPolicyModeFail),
Delay: pointerOf(15 * time.Second),
Attempts: pointerOf(2),
Interval: pointerOf(30 * time.Minute),
Mode: pointerOf(RestartPolicyModeFail),
}
}
......@@ -569,10 +569,10 @@ func defaultServiceJobRestartPolicy() *RestartPolicy {
// in nomad/structs/structs.go
func defaultBatchJobRestartPolicy() *RestartPolicy {
return &RestartPolicy{
Delay: timeToPtr(15 * time.Second),
Attempts: intToPtr(3),
Interval: timeToPtr(24 * time.Hour),
Mode: stringToPtr(RestartPolicyModeFail),
Delay: pointerOf(15 * time.Second),
Attempts: pointerOf(3),
Interval: pointerOf(24 * time.Hour),
Mode: pointerOf(RestartPolicyModeFail),
}
}
......@@ -623,17 +623,17 @@ type LogConfig struct {
func DefaultLogConfig() *LogConfig {
return &LogConfig{
MaxFiles: intToPtr(10),
MaxFileSizeMB: intToPtr(10),
MaxFiles: pointerOf(10),
MaxFileSizeMB: pointerOf(10),
}
}
func (l *LogConfig) Canonicalize() {
if l.MaxFiles == nil {
l.MaxFiles = intToPtr(10)
l.MaxFiles = pointerOf(10)
}
if l.MaxFileSizeMB == nil {
l.MaxFileSizeMB = intToPtr(10)
l.MaxFileSizeMB = pointerOf(10)
}
}
......@@ -694,7 +694,7 @@ func (t *Task) Canonicalize(tg *TaskGroup, job *Job) {
t.Resources.Canonicalize()
if t.KillTimeout == nil {
t.KillTimeout = timeToPtr(5 * time.Second)
t.KillTimeout = pointerOf(5 * time.Second)
}
if t.LogConfig == nil {
t.LogConfig = DefaultLogConfig()
......@@ -746,11 +746,11 @@ type TaskArtifact struct {
func (a *TaskArtifact) Canonicalize() {
if a.GetterMode == nil {
a.GetterMode = stringToPtr("any")
a.GetterMode = pointerOf("any")
}
if a.GetterSource == nil {
// Shouldn't be possible, but we don't want to panic
a.GetterSource = stringToPtr("")
a.GetterSource = pointerOf("")
}
if len(a.GetterOptions) == 0 {
a.GetterOptions = nil
......@@ -768,7 +768,7 @@ func (a *TaskArtifact) Canonicalize() {
a.RelativeDest = &dest
default:
// Default to a directory
a.RelativeDest = stringToPtr("local/")
a.RelativeDest = pointerOf("local/")
}
}
}
......@@ -810,52 +810,52 @@ type Template struct {
func (tmpl *Template) Canonicalize() {
if tmpl.SourcePath == nil {
tmpl.SourcePath = stringToPtr("")
tmpl.SourcePath = pointerOf("")
}
if tmpl.DestPath == nil {
tmpl.DestPath = stringToPtr("")
tmpl.DestPath = pointerOf("")
}
if tmpl.EmbeddedTmpl == nil {
tmpl.EmbeddedTmpl = stringToPtr("")
tmpl.EmbeddedTmpl = pointerOf("")
}
if tmpl.ChangeMode == nil {
tmpl.ChangeMode = stringToPtr("restart")
tmpl.ChangeMode = pointerOf("restart")
}
if tmpl.ChangeSignal == nil {
if *tmpl.ChangeMode == "signal" {
tmpl.ChangeSignal = stringToPtr("SIGHUP")
tmpl.ChangeSignal = pointerOf("SIGHUP")
} else {
tmpl.ChangeSignal = stringToPtr("")
tmpl.ChangeSignal = pointerOf("")
}
} else {
sig := *tmpl.ChangeSignal
tmpl.ChangeSignal = stringToPtr(strings.ToUpper(sig))
tmpl.ChangeSignal = pointerOf(strings.ToUpper(sig))
}
if tmpl.Splay == nil {
tmpl.Splay = timeToPtr(5 * time.Second)
tmpl.Splay = pointerOf(5 * time.Second)
}
if tmpl.Perms == nil {
tmpl.Perms = stringToPtr("0644")
tmpl.Perms = pointerOf("0644")
}
if tmpl.Uid == nil {
tmpl.Uid = intToPtr(-1)
tmpl.Uid = pointerOf(-1)
}
if tmpl.Gid == nil {
tmpl.Gid = intToPtr(-1)
tmpl.Gid = pointerOf(-1)
}
if tmpl.LeftDelim == nil {
tmpl.LeftDelim = stringToPtr("{{")
tmpl.LeftDelim = pointerOf("{{")
}
if tmpl.RightDelim == nil {
tmpl.RightDelim = stringToPtr("}}")
tmpl.RightDelim = pointerOf("}}")
}
if tmpl.Envvars == nil {
tmpl.Envvars = boolToPtr(false)
tmpl.Envvars = pointerOf(false)
}
//COMPAT(0.12) VaultGrace is deprecated and unused as of Vault 0.5
if tmpl.VaultGrace == nil {
tmpl.VaultGrace = timeToPtr(0)
tmpl.VaultGrace = pointerOf(time.Duration(0))
}
}
......@@ -869,16 +869,16 @@ type Vault struct {
func (v *Vault) Canonicalize() {
if v.Env == nil {
v.Env = boolToPtr(true)
v.Env = pointerOf(true)
}
if v.Namespace == nil {
v.Namespace = stringToPtr("")
v.Namespace = pointerOf("")
}
if v.ChangeMode == nil {
v.ChangeMode = stringToPtr("restart")
v.ChangeMode = pointerOf("restart")
}
if v.ChangeSignal == nil {
v.ChangeSignal = stringToPtr("SIGHUP")
v.ChangeSignal = pointerOf("SIGHUP")
}
}
......
......@@ -15,8 +15,8 @@ func TestTaskGroup_NewTaskGroup(t *testing.T) {
testutil.Parallel(t)
grp := NewTaskGroup("grp1", 2)
expect := &TaskGroup{
Name: stringToPtr("grp1"),
Count: intToPtr(2),
Name: pointerOf("grp1"),
Count: pointerOf(2),
}
if !reflect.DeepEqual(grp, expect) {
t.Fatalf("expect: %#v, got: %#v", expect, grp)
......@@ -79,13 +79,13 @@ func TestTaskGroup_AddAffinity(t *testing.T) {
LTarget: "kernel.version",
RTarget: "4.6",
Operand: "=",
Weight: int8ToPtr(100),
Weight: pointerOf(int8(100)),
},
{
LTarget: "${node.affinity}",
RTarget: "dc2",
Operand: "=",
Weight: int8ToPtr(50),
Weight: pointerOf(int8(50)),
},
}
if !reflect.DeepEqual(grp.Affinities, expect) {
......@@ -143,7 +143,7 @@ func TestTaskGroup_AddSpread(t *testing.T) {
expect := []*Spread{
{
Attribute: "${meta.rack}",
Weight: int8ToPtr(100),
Weight: pointerOf(int8(100)),
SpreadTarget: []*SpreadTarget{
{
Value: "r1",
......@@ -153,7 +153,7 @@ func TestTaskGroup_AddSpread(t *testing.T) {
},
{
Attribute: "${node.datacenter}",
Weight: int8ToPtr(100),
Weight: pointerOf(int8(100)),
SpreadTarget: []*SpreadTarget{
{
Value: "dc1",
......@@ -263,13 +263,13 @@ func TestTask_Require(t *testing.T) {
// Create some require resources
resources := &Resources{
CPU: intToPtr(1250),
MemoryMB: intToPtr(128),
DiskMB: intToPtr(2048),
CPU: pointerOf(1250),
MemoryMB: pointerOf(128),
DiskMB: pointerOf(2048),
Networks: []*NetworkResource{
{
CIDR: "0.0.0.0/0",
MBits: intToPtr(100),
MBits: pointerOf(100),
ReservedPorts: []Port{{"", 80, 0, ""}, {"", 443, 0, ""}},
},
},
......@@ -340,13 +340,13 @@ func TestTask_AddAffinity(t *testing.T) {
LTarget: "kernel.version",
RTarget: "4.6",
Operand: "=",
Weight: int8ToPtr(100),
Weight: pointerOf(int8(100)),
},
{
LTarget: "${node.datacenter}",
RTarget: "dc2",
Operand: "=",
Weight: int8ToPtr(50),
Weight: pointerOf(int8(50)),
},
}
if !reflect.DeepEqual(task.Affinities, expect) {
......@@ -357,8 +357,8 @@ func TestTask_AddAffinity(t *testing.T) {
func TestTask_Artifact(t *testing.T) {
testutil.Parallel(t)
a := TaskArtifact{
GetterSource: stringToPtr("http://localhost/foo.txt"),
GetterMode: stringToPtr("file"),
GetterSource: pointerOf("http://localhost/foo.txt"),
GetterMode: pointerOf("file"),
GetterHeaders: make(map[string]string),
GetterOptions: make(map[string]string),
}
......@@ -396,10 +396,10 @@ func TestTask_Canonicalize_TaskLifecycle(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tg := &TaskGroup{
Name: stringToPtr("foo"),
Name: pointerOf("foo"),
}
j := &Job{
ID: stringToPtr("test"),
ID: pointerOf("test"),
}
tc.task.Canonicalize(tg, j)
require.Equal(t, tc.expected, tc.task.Lifecycle)
......@@ -429,16 +429,16 @@ func TestTask_Template_WaitConfig_Canonicalize_and_Copy(t *testing.T) {
{
name: "all-fields",
task: taskWithWait(&WaitConfig{
Min: timeToPtr(5),
Max: timeToPtr(10),
Min: pointerOf(time.Duration(5)),
Max: pointerOf(time.Duration(10)),
}),
canonicalized: &WaitConfig{
Min: timeToPtr(5),
Max: timeToPtr(10),
Min: pointerOf(time.Duration(5)),
Max: pointerOf(time.Duration(10)),
},
copied: &WaitConfig{
Min: timeToPtr(5),
Max: timeToPtr(10),
Min: pointerOf(time.Duration(5)),
Max: pointerOf(time.Duration(10)),
},
},
{
......@@ -456,25 +456,25 @@ func TestTask_Template_WaitConfig_Canonicalize_and_Copy(t *testing.T) {
{
name: "min-only",
task: taskWithWait(&WaitConfig{
Min: timeToPtr(5),
Min: pointerOf(time.Duration(5)),
}),
canonicalized: &WaitConfig{
Min: timeToPtr(5),
Min: pointerOf(time.Duration(5)),
},
copied: &WaitConfig{
Min: timeToPtr(5),
Min: pointerOf(time.Duration(5)),
},
},
{
name: "max-only",
task: taskWithWait(&WaitConfig{
Max: timeToPtr(10),
Max: pointerOf(time.Duration(10)),
}),
canonicalized: &WaitConfig{
Max: timeToPtr(10),
Max: pointerOf(time.Duration(10)),
},
copied: &WaitConfig{
Max: timeToPtr(10),
Max: pointerOf(time.Duration(10)),
},
},
}
......@@ -482,10 +482,10 @@ func TestTask_Template_WaitConfig_Canonicalize_and_Copy(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tg := &TaskGroup{
Name: stringToPtr("foo"),
Name: pointerOf("foo"),
}
j := &Job{
ID: stringToPtr("test"),
ID: pointerOf("test"),
}
require.Equal(t, tc.copied, tc.task.Templates[0].Wait.Copy())
tc.task.Canonicalize(tg, j)
......@@ -504,10 +504,10 @@ func TestTask_Canonicalize_Vault(t *testing.T) {
name: "empty",
input: &Vault{},
expected: &Vault{
Env: boolToPtr(true),
Namespace: stringToPtr(""),
ChangeMode: stringToPtr("restart"),
ChangeSignal: stringToPtr("SIGHUP"),
Env: pointerOf(true),
Namespace: pointerOf(""),
ChangeMode: pointerOf("restart"),
ChangeSignal: pointerOf("SIGHUP"),
},
},
}
......@@ -525,22 +525,22 @@ func TestTaskGroup_Canonicalize_Update(t *testing.T) {
testutil.Parallel(t)
// Job with an Empty() Update
job := &Job{
ID: stringToPtr("test"),
ID: pointerOf("test"),
Update: &UpdateStrategy{
AutoRevert: boolToPtr(false),
AutoPromote: boolToPtr(false),
Canary: intToPtr(0),
HealthCheck: stringToPtr(""),
HealthyDeadline: timeToPtr(0),
ProgressDeadline: timeToPtr(0),
MaxParallel: intToPtr(0),
MinHealthyTime: timeToPtr(0),
Stagger: timeToPtr(0),
AutoRevert: pointerOf(false),
AutoPromote: pointerOf(false),
Canary: pointerOf(0),
HealthCheck: pointerOf(""),
HealthyDeadline: pointerOf(time.Duration(0)),
ProgressDeadline: pointerOf(time.Duration(0)),
MaxParallel: pointerOf(0),
MinHealthyTime: pointerOf(time.Duration(0)),
Stagger: pointerOf(time.Duration(0)),
},
}
job.Canonicalize()
tg := &TaskGroup{
Name: stringToPtr("foo"),
Name: pointerOf("foo"),
}
tg.Canonicalize(job)
assert.NotNil(t, job.Update)
......@@ -552,15 +552,15 @@ func TestTaskGroup_Canonicalize_Scaling(t *testing.T) {
require := require.New(t)
job := &Job{
ID: stringToPtr("test"),
ID: pointerOf("test"),
}
job.Canonicalize()
tg := &TaskGroup{
Name: stringToPtr("foo"),
Name: pointerOf("foo"),
Count: nil,
Scaling: &ScalingPolicy{
Min: nil,
Max: int64ToPtr(10),
Max: pointerOf(int64(10)),
Policy: nil,
Enabled: nil,
CreateIndex: 0,
......@@ -578,7 +578,7 @@ func TestTaskGroup_Canonicalize_Scaling(t *testing.T) {
// count == nil => count = Scaling.Min
tg.Count = nil
tg.Scaling.Min = int64ToPtr(5)
tg.Scaling.Min = pointerOf(int64(5))
tg.Canonicalize(job)
require.NotNil(tg.Count)
require.NotNil(tg.Scaling.Min)
......@@ -586,7 +586,7 @@ func TestTaskGroup_Canonicalize_Scaling(t *testing.T) {
require.EqualValues(*tg.Count, *tg.Scaling.Min)
// Scaling.Min == nil => Scaling.Min == count
tg.Count = intToPtr(5)
tg.Count = pointerOf(5)
tg.Scaling.Min = nil
tg.Canonicalize(job)
require.NotNil(tg.Count)
......@@ -595,8 +595,8 @@ func TestTaskGroup_Canonicalize_Scaling(t *testing.T) {
require.EqualValues(*tg.Scaling.Min, *tg.Count)
// both present, both persisted
tg.Count = intToPtr(5)
tg.Scaling.Min = int64ToPtr(1)
tg.Count = pointerOf(5)
tg.Scaling.Min = pointerOf(int64(1))
tg.Canonicalize(job)
require.NotNil(tg.Count)
require.NotNil(tg.Scaling.Min)
......@@ -607,32 +607,32 @@ func TestTaskGroup_Canonicalize_Scaling(t *testing.T) {
func TestTaskGroup_Merge_Update(t *testing.T) {
testutil.Parallel(t)
job := &Job{
ID: stringToPtr("test"),
ID: pointerOf("test"),
Update: &UpdateStrategy{},
}
job.Canonicalize()
// Merge and canonicalize part of an update stanza
tg := &TaskGroup{
Name: stringToPtr("foo"),
Name: pointerOf("foo"),
Update: &UpdateStrategy{
AutoRevert: boolToPtr(true),
Canary: intToPtr(5),
HealthCheck: stringToPtr("foo"),
AutoRevert: pointerOf(true),
Canary: pointerOf(5),
HealthCheck: pointerOf("foo"),
},
}
tg.Canonicalize(job)
require.Equal(t, &UpdateStrategy{
AutoRevert: boolToPtr(true),
AutoPromote: boolToPtr(false),
Canary: intToPtr(5),
HealthCheck: stringToPtr("foo"),
HealthyDeadline: timeToPtr(5 * time.Minute),
ProgressDeadline: timeToPtr(10 * time.Minute),
MaxParallel: intToPtr(1),
MinHealthyTime: timeToPtr(10 * time.Second),
Stagger: timeToPtr(30 * time.Second),
AutoRevert: pointerOf(true),
AutoPromote: pointerOf(false),
Canary: pointerOf(5),
HealthCheck: pointerOf("foo"),
HealthyDeadline: pointerOf(5 * time.Minute),
ProgressDeadline: pointerOf(10 * time.Minute),
MaxParallel: pointerOf(1),
MinHealthyTime: pointerOf(10 * time.Second),
Stagger: pointerOf(30 * time.Second),
}, tg.Update)
}
......@@ -661,44 +661,44 @@ func TestTaskGroup_Canonicalize_MigrateStrategy(t *testing.T) {
jobMigrate: nil,
taskMigrate: nil,
expected: &MigrateStrategy{
MaxParallel: intToPtr(1),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(10 * time.Second),
HealthyDeadline: timeToPtr(5 * time.Minute),
MaxParallel: pointerOf(1),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(10 * time.Second),
HealthyDeadline: pointerOf(5 * time.Minute),
},
},
{
desc: "Empty job migrate strategy",
jobType: "service",
jobMigrate: &MigrateStrategy{
MaxParallel: intToPtr(0),
HealthCheck: stringToPtr(""),
MinHealthyTime: timeToPtr(0),
HealthyDeadline: timeToPtr(0),
MaxParallel: pointerOf(0),
HealthCheck: pointerOf(""),
MinHealthyTime: pointerOf(time.Duration(0)),
HealthyDeadline: pointerOf(time.Duration(0)),
},
taskMigrate: nil,
expected: &MigrateStrategy{
MaxParallel: intToPtr(0),
HealthCheck: stringToPtr(""),
MinHealthyTime: timeToPtr(0),
HealthyDeadline: timeToPtr(0),
MaxParallel: pointerOf(0),
HealthCheck: pointerOf(""),
MinHealthyTime: pointerOf(time.Duration(0)),
HealthyDeadline: pointerOf(time.Duration(0)),
},
},
{
desc: "Inherit from job",
jobType: "service",
jobMigrate: &MigrateStrategy{
MaxParallel: intToPtr(3),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(2),
HealthyDeadline: timeToPtr(2),
MaxParallel: pointerOf(3),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(time.Duration(2)),
HealthyDeadline: pointerOf(time.Duration(2)),
},
taskMigrate: nil,
expected: &MigrateStrategy{
MaxParallel: intToPtr(3),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(2),
HealthyDeadline: timeToPtr(2),
MaxParallel: pointerOf(3),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(time.Duration(2)),
HealthyDeadline: pointerOf(time.Duration(2)),
},
},
{
......@@ -706,67 +706,67 @@ func TestTaskGroup_Canonicalize_MigrateStrategy(t *testing.T) {
jobType: "service",
jobMigrate: nil,
taskMigrate: &MigrateStrategy{
MaxParallel: intToPtr(3),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(2),
HealthyDeadline: timeToPtr(2),
MaxParallel: pointerOf(3),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(time.Duration(2)),
HealthyDeadline: pointerOf(time.Duration(2)),
},
expected: &MigrateStrategy{
MaxParallel: intToPtr(3),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(2),
HealthyDeadline: timeToPtr(2),
MaxParallel: pointerOf(3),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(time.Duration(2)),
HealthyDeadline: pointerOf(time.Duration(2)),
},
},
{
desc: "Merge from job",
jobType: "service",
jobMigrate: &MigrateStrategy{
MaxParallel: intToPtr(11),
MaxParallel: pointerOf(11),
},
taskMigrate: &MigrateStrategy{
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(2),
HealthyDeadline: timeToPtr(2),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(time.Duration(2)),
HealthyDeadline: pointerOf(time.Duration(2)),
},
expected: &MigrateStrategy{
MaxParallel: intToPtr(11),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(2),
HealthyDeadline: timeToPtr(2),
MaxParallel: pointerOf(11),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(time.Duration(2)),
HealthyDeadline: pointerOf(time.Duration(2)),
},
},
{
desc: "Override from group",
jobType: "service",
jobMigrate: &MigrateStrategy{
MaxParallel: intToPtr(11),
MaxParallel: pointerOf(11),
},
taskMigrate: &MigrateStrategy{
MaxParallel: intToPtr(5),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(2),
HealthyDeadline: timeToPtr(2),
MaxParallel: pointerOf(5),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(time.Duration(2)),
HealthyDeadline: pointerOf(time.Duration(2)),
},
expected: &MigrateStrategy{
MaxParallel: intToPtr(5),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(2),
HealthyDeadline: timeToPtr(2),
MaxParallel: pointerOf(5),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(time.Duration(2)),
HealthyDeadline: pointerOf(time.Duration(2)),
},
},
{
desc: "Parallel from job, defaulting",
jobType: "service",
jobMigrate: &MigrateStrategy{
MaxParallel: intToPtr(5),
MaxParallel: pointerOf(5),
},
taskMigrate: nil,
expected: &MigrateStrategy{
MaxParallel: intToPtr(5),
HealthCheck: stringToPtr("checks"),
MinHealthyTime: timeToPtr(10 * time.Second),
HealthyDeadline: timeToPtr(5 * time.Minute),
MaxParallel: pointerOf(5),
HealthCheck: pointerOf("checks"),
MinHealthyTime: pointerOf(10 * time.Second),
HealthyDeadline: pointerOf(5 * time.Minute),
},
},
}
......@@ -774,13 +774,13 @@ func TestTaskGroup_Canonicalize_MigrateStrategy(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
job := &Job{
ID: stringToPtr("test"),
ID: pointerOf("test"),
Migrate: tc.jobMigrate,
Type: stringToPtr(tc.jobType),
Type: pointerOf(tc.jobType),
}
job.Canonicalize()
tg := &TaskGroup{
Name: stringToPtr("foo"),
Name: pointerOf("foo"),
Migrate: tc.taskMigrate,
}
tg.Canonicalize(job)
......@@ -793,12 +793,12 @@ func TestTaskGroup_Canonicalize_MigrateStrategy(t *testing.T) {
func TestSpread_Canonicalize(t *testing.T) {
testutil.Parallel(t)
job := &Job{
ID: stringToPtr("test"),
Type: stringToPtr("batch"),
ID: pointerOf("test"),
Type: pointerOf("batch"),
}
job.Canonicalize()
tg := &TaskGroup{
Name: stringToPtr("foo"),
Name: pointerOf("foo"),
}
type testCase struct {
desc string
......@@ -818,7 +818,7 @@ func TestSpread_Canonicalize(t *testing.T) {
"Zero spread",
&Spread{
Attribute: "test",
Weight: int8ToPtr(0),
Weight: pointerOf(int8(0)),
},
0,
},
......@@ -826,7 +826,7 @@ func TestSpread_Canonicalize(t *testing.T) {
"Non Zero spread",
&Spread{
Attribute: "test",
Weight: int8ToPtr(100),
Weight: pointerOf(int8(100)),
},
100,
},
......@@ -854,48 +854,48 @@ func Test_NewDefaultReschedulePolicy(t *testing.T) {
desc: "service job type",
inputJobType: "service",
expected: &ReschedulePolicy{
Attempts: intToPtr(0),
Interval: timeToPtr(0),
Delay: timeToPtr(30 * time.Second),
DelayFunction: stringToPtr("exponential"),
MaxDelay: timeToPtr(1 * time.Hour),
Unlimited: boolToPtr(true),
Attempts: pointerOf(0),
Interval: pointerOf(time.Duration(0)),
Delay: pointerOf(30 * time.Second),
DelayFunction: pointerOf("exponential"),
MaxDelay: pointerOf(1 * time.Hour),
Unlimited: pointerOf(true),
},
},
{
desc: "batch job type",
inputJobType: "batch",
expected: &ReschedulePolicy{
Attempts: intToPtr(1),
Interval: timeToPtr(24 * time.Hour),
Delay: timeToPtr(5 * time.Second),
DelayFunction: stringToPtr("constant"),
MaxDelay: timeToPtr(0),
Unlimited: boolToPtr(false),
Attempts: pointerOf(1),
Interval: pointerOf(24 * time.Hour),
Delay: pointerOf(5 * time.Second),
DelayFunction: pointerOf("constant"),
MaxDelay: pointerOf(time.Duration(0)),
Unlimited: pointerOf(false),
},
},
{
desc: "system job type",
inputJobType: "system",
expected: &ReschedulePolicy{
Attempts: intToPtr(0),
Interval: timeToPtr(0),
Delay: timeToPtr(0),
DelayFunction: stringToPtr(""),
MaxDelay: timeToPtr(0),
Unlimited: boolToPtr(false),
Attempts: pointerOf(0),
Interval: pointerOf(time.Duration(0)),
Delay: pointerOf(time.Duration(0)),
DelayFunction: pointerOf(""),
MaxDelay: pointerOf(time.Duration(0)),
Unlimited: pointerOf(false),
},
},
{
desc: "unrecognised job type",
inputJobType: "unrecognised",
expected: &ReschedulePolicy{
Attempts: intToPtr(0),
Interval: timeToPtr(0),
Delay: timeToPtr(0),
DelayFunction: stringToPtr(""),
MaxDelay: timeToPtr(0),
Unlimited: boolToPtr(false),
Attempts: pointerOf(0),
Interval: pointerOf(time.Duration(0)),
Delay: pointerOf(time.Duration(0)),
DelayFunction: pointerOf(""),
MaxDelay: pointerOf(time.Duration(0)),
Unlimited: pointerOf(false),
},
},
}
......@@ -912,13 +912,13 @@ func TestTaskGroup_Canonicalize_Consul(t *testing.T) {
testutil.Parallel(t)
t.Run("override job consul in group", func(t *testing.T) {
job := &Job{
ID: stringToPtr("job"),
ConsulNamespace: stringToPtr("ns1"),
ID: pointerOf("job"),
ConsulNamespace: pointerOf("ns1"),
}
job.Canonicalize()
tg := &TaskGroup{
Name: stringToPtr("group"),
Name: pointerOf("group"),
Consul: &Consul{Namespace: "ns2"},
}
tg.Canonicalize(job)
......@@ -929,13 +929,13 @@ func TestTaskGroup_Canonicalize_Consul(t *testing.T) {
t.Run("inherit job consul in group", func(t *testing.T) {
job := &Job{
ID: stringToPtr("job"),
ConsulNamespace: stringToPtr("ns1"),
ID: pointerOf("job"),
ConsulNamespace: pointerOf("ns1"),
}
job.Canonicalize()
tg := &TaskGroup{
Name: stringToPtr("group"),
Name: pointerOf("group"),
Consul: nil, // not set, inherit from job
}
tg.Canonicalize(job)
......@@ -946,13 +946,13 @@ func TestTaskGroup_Canonicalize_Consul(t *testing.T) {
t.Run("set in group only", func(t *testing.T) {
job := &Job{
ID: stringToPtr("job"),
ID: pointerOf("job"),
ConsulNamespace: nil,
}
job.Canonicalize()
tg := &TaskGroup{
Name: stringToPtr("group"),
Name: pointerOf("group"),
Consul: &Consul{Namespace: "ns2"},
}
tg.Canonicalize(job)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment