From af68cc03829176dce99c2053a53bda0aba4bcf94 Mon Sep 17 00:00:00 2001 From: db Date: Sun, 19 Feb 2023 22:35:42 +0100 Subject: [PATCH] fix: handle colima host k3d mostly works flawlessly on github.com/abiosoft/colima, but host.k3d.interal points to nowhere useful. We detect colima runtime by the name in docker info output, then resolve the host IP by querying host.lima.internal. How to test: $ colima start $ k3d cluster create $ nc -l 0.0.0.0 1234 In another terminal $ kubectl run -it --rm --image alpine:latest test -- \ /bin/sh -c 'echo "hello there" | nc host.k3d.internal 1234' --- pkg/client/host.go | 15 +++++++++++++++ pkg/runtimes/docker/info.go | 1 + pkg/runtimes/types/types.go | 1 + 3 files changed, 17 insertions(+) diff --git a/pkg/client/host.go b/pkg/client/host.go index 3d381c81f..cd28e54bf 100644 --- a/pkg/client/host.go +++ b/pkg/client/host.go @@ -91,6 +91,21 @@ func GetHostIP(ctx context.Context, runtime runtimes.Runtime, cluster *k3d.Clust } + // Colima + if rtimeInfo.InfoName == "colima" { + toolsNode, err := EnsureToolsNode(ctx, runtime, cluster) + if err != nil { + return nil, fmt.Errorf("failed to ensure that k3d-tools node is running to get host IP :%w", err) + } + + limaIP, err := resolveHostnameFromInside(ctx, runtime, toolsNode, "host.lima.internal", ResolveHostCmdGetEnt) + if err == nil { + return limaIP, nil + } + + l.Log().Debugf("[GetHostIP on colima] failed to resolve 'host.lima.internal' from inside the k3d-tools node: %v", err) + } + ip, err := runtime.GetHostIP(ctx, cluster.Network.Name) if err != nil { return nil, fmt.Errorf("runtime failed to get host IP: %w", err) diff --git a/pkg/runtimes/docker/info.go b/pkg/runtimes/docker/info.go index ea43ac32e..0c66e8c0d 100644 --- a/pkg/runtimes/docker/info.go +++ b/pkg/runtimes/docker/info.go @@ -53,6 +53,7 @@ func (d Docker) Info() (*runtimeTypes.RuntimeInfo, error) { CgroupVersion: info.CgroupVersion, CgroupDriver: info.CgroupDriver, Filesystem: "UNKNOWN", + InfoName: info.Name, } // Get the backing filesystem for the storage driver diff --git a/pkg/runtimes/types/types.go b/pkg/runtimes/types/types.go index 95ae7c8a2..6af48dbc3 100644 --- a/pkg/runtimes/types/types.go +++ b/pkg/runtimes/types/types.go @@ -31,6 +31,7 @@ type RuntimeInfo struct { CgroupVersion string `json:"cgroupversion,omitempty"` CgroupDriver string `json:"cgroupdriver,omitempty"` Filesystem string `json:"filesystem,omitempty"` + InfoName string `json:"infoname,omitempty"` } type NodeLogsOpts struct {