networkop / meshnet-cni

a (K8s) CNI plugin to create arbitrary virtual network topologies
BSD 3-Clause "New" or "Revised" License
116 stars 28 forks source link

Fix gRPC issue in IPv6 only cluster #83

Open maxgoffart opened 6 months ago

maxgoffart commented 6 months ago

Hi,

This PR fixes an issue encountered with gRPC in an IPv6 only clusters.

Current implementation

The current implementation is using fmt.Sprintf to combine the hostname and port number used when calling grpc.Dial(...). See daemon/grpcwire/grpcwire.go for instance.

Yet, this yields the following (important part highlighted) when doing kubectl describe pod/<podName>:

Warning FailedCreatePodSandBox 10m kubelet Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "ae67dda14b109f585fd51fdde5f54087955ae7b5f91d563957dbbe85a72ce021": plugin type="meshnet" name="meshnet" failed (add): rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp: address fc00:f853:ccd:e793::4:51111: too many colons in address"

Fix

The solution is to use Go's net.JoinHostPort(...) instead of fmt.Sprintf to combine the hostname and port number.

This method will automatically add [] around the hostname when it's an IPv6, which is using :.

See grpc-go issue 3399 for more details.

Test

The fix has been tested on the following: