mirror of https://github.com/linkerd/linkerd2.git
				
				
				
			Fix `linkerd dg endpoints` to work with IPv6 (#12541)
``` # BEFORE $ bin/linkerd dg endpoints family-server.default.svc.cluster.local:8080 NAMESPACE IP PORT POD SERVICE default 0.0.0.0 8080 family-server-7cf95b6b89-x6cb9 family-server.default # AFTER $ bin/linkerd dg endpoints family-server.default.svc.cluster.local:8080 NAMESPACE IP PORT POD SERVICE default fd00:10:244::5 8080 family-server-7cf95b6b89-x6cb9 family-server.default ```
This commit is contained in:
		
							parent
							
								
									137eac9df3
								
							
						
					
					
						commit
						5114e8e45a
					
				|  | @ -3,11 +3,9 @@ package cmd | ||||||
| import ( | import ( | ||||||
| 	"bytes" | 	"bytes" | ||||||
| 	"context" | 	"context" | ||||||
| 	"encoding/binary" |  | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"sort" | 	"sort" | ||||||
| 	"strings" | 	"strings" | ||||||
|  | @ -17,6 +15,7 @@ import ( | ||||||
| 	destinationPb "github.com/linkerd/linkerd2-proxy-api/go/destination" | 	destinationPb "github.com/linkerd/linkerd2-proxy-api/go/destination" | ||||||
| 	netPb "github.com/linkerd/linkerd2-proxy-api/go/net" | 	netPb "github.com/linkerd/linkerd2-proxy-api/go/net" | ||||||
| 	"github.com/linkerd/linkerd2/controller/api/destination" | 	"github.com/linkerd/linkerd2/controller/api/destination" | ||||||
|  | 	"github.com/linkerd/linkerd2/pkg/addr" | ||||||
| 	pkgcmd "github.com/linkerd/linkerd2/pkg/cmd" | 	pkgcmd "github.com/linkerd/linkerd2/pkg/cmd" | ||||||
| 	"github.com/linkerd/linkerd2/pkg/k8s" | 	"github.com/linkerd/linkerd2/pkg/k8s" | ||||||
| 	log "github.com/sirupsen/logrus" | 	log "github.com/sirupsen/logrus" | ||||||
|  | @ -218,10 +217,11 @@ func requestEndpointsFromAPI(client destinationPb.DestinationClient, token strin | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getIP(tcpAddr *netPb.TcpAddress) string { | func getIP(tcpAddr *netPb.TcpAddress) string { | ||||||
| 	ip := tcpAddr.GetIp().GetIpv4() | 	ip := addr.FromProxyAPI(tcpAddr.GetIp()) | ||||||
| 	b := make([]byte, 4) | 	if ip == nil { | ||||||
| 	binary.BigEndian.PutUint32(b, ip) | 		return "" | ||||||
| 	return net.IP(b).String() | 	} | ||||||
|  | 	return addr.PublicIPToString(ip) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func renderEndpoints(endpoints endpointsInfo, options *endpointsOptions) string { | func renderEndpoints(endpoints endpointsInfo, options *endpointsOptions) string { | ||||||
|  |  | ||||||
|  | @ -46,7 +46,7 @@ func PublicIPToString(ip *l5dNetPb.IPAddress) string { | ||||||
| 
 | 
 | ||||||
| // ProxyAddressToString formats a Proxy API TCPAddress as a string.
 | // ProxyAddressToString formats a Proxy API TCPAddress as a string.
 | ||||||
| func ProxyAddressToString(addr *pb.TcpAddress) string { | func ProxyAddressToString(addr *pb.TcpAddress) string { | ||||||
| 	vizIP := proxyToVizIPAddr(addr.GetIp()) | 	vizIP := FromProxyAPI(addr.GetIp()) | ||||||
| 	if vizIP == nil { | 	if vizIP == nil { | ||||||
| 		return "" | 		return "" | ||||||
| 	} | 	} | ||||||
|  | @ -90,13 +90,13 @@ func ParsePublicIP(ip string) (*l5dNetPb.IPAddress, error) { | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	return proxyToVizIPAddr(addr), nil | 	return FromProxyAPI(addr), nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // NetToPublic converts a Proxy API TCPAddress to a Viz API
 | // NetToPublic converts a Proxy API TCPAddress to a Viz API
 | ||||||
| // TCPAddress.
 | // TCPAddress.
 | ||||||
| func NetToPublic(net *pb.TcpAddress) *l5dNetPb.TcpAddress { | func NetToPublic(net *pb.TcpAddress) *l5dNetPb.TcpAddress { | ||||||
| 	ip := proxyToVizIPAddr(net.GetIp()) | 	ip := FromProxyAPI(net.GetIp()) | ||||||
| 
 | 
 | ||||||
| 	return &l5dNetPb.TcpAddress{ | 	return &l5dNetPb.TcpAddress{ | ||||||
| 		Ip:   ip, | 		Ip:   ip, | ||||||
|  | @ -104,7 +104,9 @@ func NetToPublic(net *pb.TcpAddress) *l5dNetPb.TcpAddress { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func proxyToVizIPAddr(net *pb.IPAddress) *l5dNetPb.IPAddress { | // FromProxyAPI casts an IPAddress from the linkerd2-proxy-api.go.net package
 | ||||||
|  | // to the linkerd2.controller.gen.common.net package
 | ||||||
|  | func FromProxyAPI(net *pb.IPAddress) *l5dNetPb.IPAddress { | ||||||
| 	switch ip := net.GetIp().(type) { | 	switch ip := net.GetIp().(type) { | ||||||
| 	case *pb.IPAddress_Ipv6: | 	case *pb.IPAddress_Ipv6: | ||||||
| 		return &l5dNetPb.IPAddress{ | 		return &l5dNetPb.IPAddress{ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue