mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
Merge pull request #2854 from hashicorp/b-2827-agent-services
Never remove unknown agent services
This commit is contained in:
@@ -779,7 +779,9 @@ func createCheckReg(serviceID, checkID string, check *structs.ServiceCheck, host
|
||||
}
|
||||
|
||||
// isNomadService returns true if the ID matches the pattern of a Nomad managed
|
||||
// service.
|
||||
// service. Agent services return false as independent client and server agents
|
||||
// may be running on the same machine. #2827
|
||||
func isNomadService(id string) bool {
|
||||
return strings.HasPrefix(id, nomadServicePrefix)
|
||||
const prefix = nomadServicePrefix + "-executor"
|
||||
return strings.HasPrefix(id, prefix)
|
||||
}
|
||||
|
||||
@@ -1231,3 +1231,27 @@ func TestConsul_DriverNetwork_Change(t *testing.T) {
|
||||
|
||||
syncAndAssertPort(net.PortMap["x"])
|
||||
}
|
||||
|
||||
// TestIsNomadService asserts the isNomadService helper returns true for Nomad
|
||||
// task IDs and false for unknown IDs and Nomad agent IDs (see #2827).
|
||||
func TestIsNomadService(t *testing.T) {
|
||||
tests := []struct {
|
||||
id string
|
||||
result bool
|
||||
}{
|
||||
{"_nomad-client-nomad-client-http", false},
|
||||
{"_nomad-server-nomad-serf", false},
|
||||
{"_nomad-executor-abc", true},
|
||||
{"_nomad-executor", true},
|
||||
{"not-nomad", false},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.id, func(t *testing.T) {
|
||||
actual := isNomadService(test.id)
|
||||
if actual != test.result {
|
||||
t.Error("%q should be %t but found %t", test.id, test.result, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user