customized default sidecar checks
This commit is contained in:
parent
eff180be91
commit
78465bbd23
|
@ -149,7 +149,6 @@ const nomadCNIConfigTemplate = `{
|
|||
"ipMasq": true,
|
||||
"isGateway": true,
|
||||
"forceAddress": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"ranges": [
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/hashicorp/consul/api"
|
||||
"github.com/hashicorp/consul/ipaddr"
|
||||
"github.com/hashicorp/nomad/helper"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
@ -11,7 +12,7 @@ import (
|
|||
// newConnect creates a new Consul AgentServiceConnect struct based on a Nomad
|
||||
// Connect struct. If the nomad Connect struct is nil, nil will be returned to
|
||||
// disable Connect for this service.
|
||||
func newConnect(serviceName string, nc *structs.ConsulConnect, networks structs.Networks) (*api.AgentServiceConnect, error) {
|
||||
func newConnect(serviceId string, serviceName string, nc *structs.ConsulConnect, networks structs.Networks) (*api.AgentServiceConnect, error) {
|
||||
switch {
|
||||
case nc == nil:
|
||||
// no connect stanza means there is no connect service to register
|
||||
|
@ -27,7 +28,7 @@ func newConnect(serviceName string, nc *structs.ConsulConnect, networks structs.
|
|||
|
||||
case nc.HasSidecar():
|
||||
// must register the sidecar for this service
|
||||
sidecarReg, err := connectSidecarRegistration(serviceName, nc.SidecarService, networks)
|
||||
sidecarReg, err := connectSidecarRegistration(serviceId, serviceName, nc.SidecarService, networks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -84,7 +85,7 @@ func newConnectGateway(serviceName string, connect *structs.ConsulConnect) *api.
|
|||
return &api.AgentServiceConnectProxyConfig{Config: envoyConfig}
|
||||
}
|
||||
|
||||
func connectSidecarRegistration(serviceName string, css *structs.ConsulSidecarService, networks structs.Networks) (*api.AgentServiceRegistration, error) {
|
||||
func connectSidecarRegistration(serviceId string, serviceName string, css *structs.ConsulSidecarService, networks structs.Networks) (*api.AgentServiceRegistration, error) {
|
||||
if css == nil {
|
||||
// no sidecar stanza means there is no sidecar service to register
|
||||
return nil, nil
|
||||
|
@ -105,6 +106,17 @@ func connectSidecarRegistration(serviceName string, css *structs.ConsulSidecarSe
|
|||
Port: cPort.Value,
|
||||
Address: cNet.IP,
|
||||
Proxy: proxy,
|
||||
Checks: api.AgentServiceChecks{
|
||||
{
|
||||
Name: "Connect Sidecar Listening",
|
||||
TCP: ipaddr.FormatAddressPort(cNet.IP, cPort.Value),
|
||||
Interval: "10s",
|
||||
},
|
||||
{
|
||||
Name: "Connect Sidecar Aliasing " + serviceId,
|
||||
AliasService: serviceId,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -866,7 +866,8 @@ func (c *ServiceClient) serviceRegs(ops *operations, service *structs.Service, w
|
|||
}
|
||||
|
||||
// newConnect returns (nil, nil) if there's no Connect-enabled service.
|
||||
connect, err := newConnect(service.Name, service.Connect, workload.Networks)
|
||||
sidecarId = id + sidecarSuffix
|
||||
connect, err := newConnect(sidecarId, service.Name, service.Connect, workload.Networks)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid Consul Connect configuration for service %q: %v", service.Name, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue