Skip to content

Commit b73323a

Browse files
committed
Remove the script field from checks in favor of args
1 parent cc214d4 commit b73323a

File tree

14 files changed

+33
-93
lines changed

14 files changed

+33
-93
lines changed

agent/agent.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,11 +1823,6 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType,
18231823
check.CheckID, checks.MinInterval))
18241824
chkType.Interval = checks.MinInterval
18251825
}
1826-
if chkType.Script != "" {
1827-
a.logger.Printf("[WARN] agent: check %q has the 'script' field, which has been deprecated "+
1828-
"and replaced with the 'args' field. See https://www.consul.io/docs/agent/checks.html",
1829-
check.CheckID)
1830-
}
18311826

18321827
if a.dockerClient == nil {
18331828
dc, err := checks.NewDockerClient(os.Getenv("DOCKER_HOST"), checks.BufSize)
@@ -1844,7 +1839,6 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType,
18441839
CheckID: check.CheckID,
18451840
DockerContainerID: chkType.DockerContainerID,
18461841
Shell: chkType.Shell,
1847-
Script: chkType.Script,
18481842
ScriptArgs: chkType.ScriptArgs,
18491843
Interval: chkType.Interval,
18501844
Logger: a.logger,
@@ -1866,16 +1860,10 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType,
18661860
check.CheckID, checks.MinInterval)
18671861
chkType.Interval = checks.MinInterval
18681862
}
1869-
if chkType.Script != "" {
1870-
a.logger.Printf("[WARN] agent: check %q has the 'script' field, which has been deprecated "+
1871-
"and replaced with the 'args' field. See https://www.consul.io/docs/agent/checks.html",
1872-
check.CheckID)
1873-
}
18741863

18751864
monitor := &checks.CheckMonitor{
18761865
Notify: a.State,
18771866
CheckID: check.CheckID,
1878-
Script: chkType.Script,
18791867
ScriptArgs: chkType.ScriptArgs,
18801868
Interval: chkType.Interval,
18811869
Timeout: chkType.Timeout,

agent/agent_endpoint_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -716,14 +716,6 @@ func TestAgent_RegisterCheck_Scripts(t *testing.T) {
716716
name string
717717
check map[string]interface{}
718718
}{
719-
{
720-
"< Consul 1.0.0",
721-
map[string]interface{}{
722-
"Name": "test",
723-
"Interval": "2s",
724-
"Script": "true",
725-
},
726-
},
727719
{
728720
"== Consul 1.0.0",
729721
map[string]interface{}{

agent/agent_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ func TestAgent_AddCheck(t *testing.T) {
651651
Status: api.HealthCritical,
652652
}
653653
chk := &structs.CheckType{
654-
Script: "exit 0",
655-
Interval: 15 * time.Second,
654+
ScriptArgs: []string{"exit", "0"},
655+
Interval: 15 * time.Second,
656656
}
657657
err := a.AddCheck(health, chk, false, "")
658658
if err != nil {
@@ -690,8 +690,8 @@ func TestAgent_AddCheck_StartPassing(t *testing.T) {
690690
Status: api.HealthPassing,
691691
}
692692
chk := &structs.CheckType{
693-
Script: "exit 0",
694-
Interval: 15 * time.Second,
693+
ScriptArgs: []string{"exit", "0"},
694+
Interval: 15 * time.Second,
695695
}
696696
err := a.AddCheck(health, chk, false, "")
697697
if err != nil {
@@ -729,8 +729,8 @@ func TestAgent_AddCheck_MinInterval(t *testing.T) {
729729
Status: api.HealthCritical,
730730
}
731731
chk := &structs.CheckType{
732-
Script: "exit 0",
733-
Interval: time.Microsecond,
732+
ScriptArgs: []string{"exit", "0"},
733+
Interval: time.Microsecond,
734734
}
735735
err := a.AddCheck(health, chk, false, "")
736736
if err != nil {
@@ -764,8 +764,8 @@ func TestAgent_AddCheck_MissingService(t *testing.T) {
764764
ServiceID: "baz",
765765
}
766766
chk := &structs.CheckType{
767-
Script: "exit 0",
768-
Interval: time.Microsecond,
767+
ScriptArgs: []string{"exit", "0"},
768+
Interval: time.Microsecond,
769769
}
770770
err := a.AddCheck(health, chk, false, "")
771771
if err == nil || err.Error() != `ServiceID "baz" does not exist` {
@@ -829,8 +829,8 @@ func TestAgent_AddCheck_ExecDisable(t *testing.T) {
829829
Status: api.HealthCritical,
830830
}
831831
chk := &structs.CheckType{
832-
Script: "exit 0",
833-
Interval: 15 * time.Second,
832+
ScriptArgs: []string{"exit", "0"},
833+
Interval: 15 * time.Second,
834834
}
835835
err := a.AddCheck(health, chk, false, "")
836836
if err == nil || !strings.Contains(err.Error(), "Scripts are disabled on this agent") {
@@ -904,8 +904,8 @@ func TestAgent_RemoveCheck(t *testing.T) {
904904
Status: api.HealthCritical,
905905
}
906906
chk := &structs.CheckType{
907-
Script: "exit 0",
908-
Interval: 15 * time.Second,
907+
ScriptArgs: []string{"exit", "0"},
908+
Interval: 15 * time.Second,
909909
}
910910
err := a.AddCheck(health, chk, false, "")
911911
if err != nil {
@@ -1315,8 +1315,8 @@ func TestAgent_PersistCheck(t *testing.T) {
13151315
Status: api.HealthPassing,
13161316
}
13171317
chkType := &structs.CheckType{
1318-
Script: "/bin/true",
1319-
Interval: 10 * time.Second,
1318+
ScriptArgs: []string{"/bin/true"},
1319+
Interval: 10 * time.Second,
13201320
}
13211321

13221322
file := filepath.Join(a.Config.DataDir, checksDir, checkIDHash(check.CheckID))
@@ -1473,7 +1473,7 @@ func TestAgent_PurgeCheckOnDuplicate(t *testing.T) {
14731473
id = "mem"
14741474
name = "memory check"
14751475
notes = "my cool notes"
1476-
script = "/bin/check-redis.py"
1476+
args = ["/bin/check-redis.py"]
14771477
interval = "30s"
14781478
}
14791479
`)

agent/config/builder.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,6 @@ func (b *Builder) checkVal(v *CheckDefinition) *structs.CheckDefinition {
967967
ServiceID: b.stringVal(v.ServiceID),
968968
Token: b.stringVal(v.Token),
969969
Status: b.stringVal(v.Status),
970-
Script: b.stringVal(v.Script),
971970
ScriptArgs: v.ScriptArgs,
972971
HTTP: b.stringVal(v.HTTP),
973972
Header: v.Header,

agent/config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ type CheckDefinition struct {
331331
ServiceID *string `json:"service_id,omitempty" hcl:"service_id" mapstructure:"service_id"`
332332
Token *string `json:"token,omitempty" hcl:"token" mapstructure:"token"`
333333
Status *string `json:"status,omitempty" hcl:"status" mapstructure:"status"`
334-
Script *string `json:"script,omitempty" hcl:"script" mapstructure:"script"`
335334
ScriptArgs []string `json:"args,omitempty" hcl:"args" mapstructure:"args"`
336335
HTTP *string `json:"http,omitempty" hcl:"http" mapstructure:"http"`
337336
Header map[string][]string `json:"header,omitempty" hcl:"header" mapstructure:"header"`

0 commit comments

Comments
 (0)