services: cr followup

This commit is contained in:
Seth Hoenig
2022-04-22 08:43:53 -05:00
parent 2e26098614
commit ed37d2116d
5 changed files with 16 additions and 11 deletions

View File

@@ -9,8 +9,9 @@ import (
)
// GetAddress returns the IP (or custom advertise address) and port to use for a
// service or check registration. If no port label is specified (an empty value),
// zero values are returned because no address could be resolved.
// service or check registration. If no port label is specified (an empty value)
// and no custom address is specified, zero values are returned because no address
// could be resolved.
func GetAddress(
address, // custom address, if set
addressMode,
@@ -30,7 +31,7 @@ func GetAddress(
}
// A custom advertise address can be used with a port map; using the
// Value and ignoring the IP. The routing from your custom address to
// the group network address is DIY.
// the group network address is DIY. (e.g. EC2 public address)
if mapping, exists := ports.Get(portLabel); exists {
return address, mapping.Value, nil
}

View File

@@ -26,6 +26,7 @@ func TestInterpolateServices(t *testing.T) {
CanaryMeta: map[string]string{
"canarymeta-key": "${canarymeta}",
},
Address: "${address}",
Checks: []*structs.ServiceCheck{
{
Name: "${checkname}",
@@ -51,6 +52,7 @@ func TestInterpolateServices(t *testing.T) {
"portlabel": "portlabel",
"tags": "tags",
"meta": "meta-value",
"address": "example.com",
"canarymeta": "canarymeta-value",
"checkname": "checkname",
"checktype": "checktype",
@@ -80,6 +82,7 @@ func TestInterpolateServices(t *testing.T) {
CanaryMeta: map[string]string{
"canarymeta-key": "canarymeta-value",
},
Address: "example.com",
Checks: []*structs.ServiceCheck{
{
Name: "checkname",

View File

@@ -49,7 +49,7 @@ type ServiceCheck struct {
Protocol string // Protocol to use if check is http, defaults to http
PortLabel string // The port to use for tcp/http checks
Expose bool // Whether to have Envoy expose the check path (connect-enabled group-services only)
AddressMode string // Must be empty, "alloc", "host", or "driver'
AddressMode string // Must be empty, "alloc", "host", or "driver"
Interval time.Duration // Interval of the check
Timeout time.Duration // Timeout of the response from the check before consul fails the check
InitialStatus string // Initial status of the check
@@ -449,12 +449,12 @@ type Service struct {
// address, specify an empty host in the PortLabel (e.g. `:port`).
PortLabel string
// AddressMode specifies how the Advertise address used in service registration
// is determined. Must be "auto" (default), "host", "driver", or "alloc".
// AddressMode specifies how the address in service registration is
// determined. Must be "auto" (default), "host", "driver", or "alloc".
AddressMode string
// Advertise enables explicitly setting and advertise address used in service
// registration. AddressMode must be "auto" if Advertise is set.
// Address enables explicitly setting a custom address to use in service
// registration. AddressMode must be "auto" if Address is set.
Address string
// EnableTagOverride will disable Consul's anti-entropy mechanism for the

View File

@@ -247,7 +247,7 @@ func TestService_Hash(t *testing.T) {
// these tests use tweaker to modify 1 field and make the false assertion
// on comparing the resulting hash output
t.Run("mod advertise", func(t *testing.T) {
t.Run("mod address", func(t *testing.T) {
try(t, func(s *svc) { s.Address = "example.com" })
})

View File

@@ -142,8 +142,9 @@ Connect][connect] integration.
for more information. Only available where `provider = "consul"`.
- `address` `(string: <optional>)` - Specifies a custom address to advertise in
Consul or Nomad service registration. Can be an IP address or domain name. If
set, `address_mode` must be in `auto` mode.
Consul or Nomad service registration. If set, `address_mode` must be in `auto`
mode. Useful with interpolation - for example to advertise the public IP address
of an AWS EC2 instance set this to `${attr.unique.platform.aws.public-ipv4}`.
- `address_mode` `(string: "auto")` - Specifies which address (host, alloc or
driver-specific) this service should advertise. See [below for