From 87d9f663fcf083522409e05a24ceb4d18682ee66 Mon Sep 17 00:00:00 2001 From: Thomas Hallgren Date: Fri, 3 May 2024 07:11:37 +0200 Subject: [PATCH] Docker aliases deprecation caused failure to detect Kind cluster. 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 --- CHANGELOG.yml | 10 +++++++++- pkg/client/docker/daemon.go | 26 ++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.yml b/CHANGELOG.yml index bafdb6d4dd..601f1f4a6c 100644 --- a/CHANGELOG.yml +++ b/CHANGELOG.yml @@ -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 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. + 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 "svc". 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 diff --git a/pkg/client/docker/daemon.go b/pkg/client/docker/daemon.go index 62bc7c9a8c..a3bf11b61a 100644 --- a/pkg/client/docker/daemon.go +++ b/pkg/client/docker/daemon.go @@ -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 + } } } }