Skip to content

Commit

Permalink
consul/connect: improve regex from CR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Jul 8, 2021
1 parent 86283ad commit 82f4245
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion command/agent/consul/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ func maybeConnectSidecar(id string) bool {
}

var (
sidecarProxyCheckRe = regexp.MustCompile(`service:_nomad-.+-sidecar-proxy(:[\d]+)?`)
sidecarProxyCheckRe = regexp.MustCompile(`^service:_nomad-.+-sidecar-proxy(:[\d]+)?$`)
)

// maybeSidecarProxyCheck returns true if the ID likely matches a Nomad generated
Expand Down
2 changes: 2 additions & 0 deletions command/agent/consul/service_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,5 +636,7 @@ func TestSyncLogic_maybeSidecarProxyCheck(t *testing.T) {
try("service:_nomad-task-2f5fb517-57d4-44ee-7780-dc1cb6e103cd-group-api-count-api-9001-sidecar-proxy:2", true)
try("service:_nomad-task-2f5fb517-57d4-44ee-7780-dc1cb6e103cd-group-api-count-api-9001", false)
try("_nomad-task-2f5fb517-57d4-44ee-7780-dc1cb6e103cd-group-api-count-api-9001-sidecar-proxy:1", false)
try("service:_nomad-task-2f5fb517-57d4-44ee-7780-dc1cb6e103cd-group-api-count-api-9001-sidecar-proxy:X", false)
try("service:_nomad-task-2f5fb517-57d4-44ee-7780-dc1cb6e103cd-group-api-count-api-9001-sidecar-proxy: ", false)
try("service", false)
}

0 comments on commit 82f4245

Please sign in to comment.