Skip to content

Commit

Permalink
Docker aliases deprecation caused failure to detect Kind cluster.
Browse files Browse the repository at this point in the history
The logic for detecting if a cluster is a local Kind cluster, and
therefore needs some special attention when using `telepresence connect
--docker`, relied on the presence of `Aliases` in the Docker network
that a Kind cluster sets up. In Docker versions from 26 and up, this
value is no longer used, but the corresponding info can instead be found
in the new `DNSNames` field.

Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed May 3, 2024
1 parent c48e3e1 commit 87d9f66
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ items:
- version: 2.19.0
date: (TBD)
notes:
- type: bugfix
title: Docker aliases deprecation caused failure to detect Kind cluster.
body: >-
The logic for detecting if a cluster is a local Kind cluster, and therefore needs some special attention when
using <code>telepresence connect --docker</code>, relied on the presence of <code>Aliases</code> in the Docker
network that a Kind cluster sets up. In Docker versions from 26 and up, this value is no longer used, but the
corresponding info can instead be found in the new <code>DNSNames</code> field.
docs: https://docs.docker.com/engine/deprecated/#container-short-id-in-network-aliases-field
- type: bugfix
title: Include svc as a top-level domain in the DNS resolver.
body: ->
body: >-
It's not uncommon that use-cases involving Kafka or other middleware use FQNs that end with
&quot;svc&quot;. The core-DNS resolver in Kubernetes can resolve such names. With this bugfix,
the Telepresence DNS resolver will also be able to resolve them, and thereby remove the need
Expand Down
26 changes: 20 additions & 6 deletions pkg/client/docker/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,30 @@ func detectKind(ctx context.Context, cns []types.ContainerJSON, hostAddrPort net
if cfg, ns := cn.Config, cn.NetworkSettings; cfg != nil && ns != nil && cfg.Labels["io.x-k8s.kind.role"] == "control-plane" {
if port, isIPv6 := containerPort(hostAddrPort, ns); port != 0 {
for n, nw := range ns.Networks {
for _, alias := range nw.Aliases {
if strings.HasSuffix(alias, "-control-plane") {
addr, err := localAddr(ctx, cn.ID, nw.NetworkID, isIPv6)
if err != nil {
dlog.Error(ctx, err)
found := false
for _, names := range nw.DNSNames {
if strings.HasSuffix(names, "-control-plane") {
found = true
break
}
}
if !found {
// Aliases got deprecated in favor of DNSNames in Docker versions 25+
for _, alias := range nw.Aliases {
if strings.HasSuffix(alias, "-control-plane") {
found = true
break
}
return netip.AddrPortFrom(addr, port), n
}
}
if found {
addr, err := localAddr(ctx, cn.ID, nw.NetworkID, isIPv6)
if err != nil {
dlog.Error(ctx, err)
break
}
return netip.AddrPortFrom(addr, port), n
}
}
}
}
Expand Down

0 comments on commit 87d9f66

Please sign in to comment.