fix(daemon): relay a loopback State Store with external NATS, and only for the task's container
This commit is contained in:
1 parent
b395eec893
commit
2ca7c9b2b9
5 files changed
+136
-43
No files matched your search
@@ -3,6 +3,7 @@ package container
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
|
||||
"github.com/moby/moby/client"
|
||||
)
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
func (p *Pool) NetworkName() string { return p.network }
|
||||
|
||||
// HostGateway is the host-side IPv4 gateway of NetworkName. It is non-empty
|
||||
// only when Config.RequireHostGateway requested embedded broker reachability.
|
||||
// only when Config.RequireHostGateway asked for it.
|
||||
func (p *Pool) HostGateway() string { return p.hostGateway }
|
||||
|
||||
func resolveHostGateway(
|
||||
@@ -25,14 +26,14 @@ func resolveHostGateway(
|
||||
}
|
||||
result, err := cli.NetworkInspect(ctx, networkName, client.NetworkInspectOptions{})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("inspect Docker network %q for embedded NATS: %w", networkName, err)
|
||||
return "", fmt.Errorf("inspect Docker network %q for task containers: %w", networkName, err)
|
||||
}
|
||||
network := result.Network.Network
|
||||
if network.Driver != "bridge" {
|
||||
return "", fmt.Errorf("docker network %q uses driver %q, want bridge for embedded NATS", networkName, network.Driver)
|
||||
return "", fmt.Errorf("docker network %q uses driver %q, want bridge for task containers", networkName, network.Driver)
|
||||
}
|
||||
if network.Scope != "" && network.Scope != "local" {
|
||||
return "", fmt.Errorf("docker network %q has scope %q, want local for embedded NATS", networkName, network.Scope)
|
||||
return "", fmt.Errorf("docker network %q has scope %q, want local for task containers", networkName, network.Scope)
|
||||
}
|
||||
for _, ipam := range network.IPAM.Config {
|
||||
gateway := ipam.Gateway
|
||||
@@ -40,5 +41,22 @@ func resolveHostGateway(
|
||||
return gateway.String(), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("docker network %q has no usable IPv4 host gateway for embedded NATS", networkName)
|
||||
return "", fmt.Errorf("docker network %q has no usable IPv4 host gateway for task containers", networkName)
|
||||
}
|
||||
|
||||
// ContainerAddrs is every address container id holds on its networks.
|
||||
func (p *Pool) ContainerAddrs(ctx context.Context, id string) ([]netip.Addr, error) {
|
||||
inspected, err := p.cli.ContainerInspect(ctx, id, client.ContainerInspectOptions{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("inspect container %s: %w", id, err)
|
||||
}
|
||||
var addrs []netip.Addr
|
||||
if settings := inspected.Container.NetworkSettings; settings != nil {
|
||||
for _, endpoint := range settings.Networks {
|
||||
if endpoint != nil && endpoint.IPAddress.IsValid() {
|
||||
addrs = append(addrs, endpoint.IPAddress)
|
||||
}
|
||||
}
|
||||
}
|
||||
return addrs, nil
|
||||
}
|
||||
Reference in new issue
Block a user