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 (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
|
@ -17,6 +15,7 @@ import (
|
|||
destinationPb "github.com/linkerd/linkerd2-proxy-api/go/destination"
|
||||
netPb "github.com/linkerd/linkerd2-proxy-api/go/net"
|
||||
"github.com/linkerd/linkerd2/controller/api/destination"
|
||||
"github.com/linkerd/linkerd2/pkg/addr"
|
||||
pkgcmd "github.com/linkerd/linkerd2/pkg/cmd"
|
||||
"github.com/linkerd/linkerd2/pkg/k8s"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
|
@ -218,10 +217,11 @@ func requestEndpointsFromAPI(client destinationPb.DestinationClient, token strin
|
|||
}
|
||||
|
||||
func getIP(tcpAddr *netPb.TcpAddress) string {
|
||||
ip := tcpAddr.GetIp().GetIpv4()
|
||||
b := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(b, ip)
|
||||
return net.IP(b).String()
|
||||
ip := addr.FromProxyAPI(tcpAddr.GetIp())
|
||||
if ip == nil {
|
||||
return ""
|
||||
}
|
||||
return addr.PublicIPToString(ip)
|
||||
}
|
||||
|
||||
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.
|
||||
func ProxyAddressToString(addr *pb.TcpAddress) string {
|
||||
vizIP := proxyToVizIPAddr(addr.GetIp())
|
||||
vizIP := FromProxyAPI(addr.GetIp())
|
||||
if vizIP == nil {
|
||||
return ""
|
||||
}
|
||||
|
|
@ -90,13 +90,13 @@ func ParsePublicIP(ip string) (*l5dNetPb.IPAddress, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return proxyToVizIPAddr(addr), nil
|
||||
return FromProxyAPI(addr), nil
|
||||
}
|
||||
|
||||
// NetToPublic converts a Proxy API TCPAddress to a Viz API
|
||||
// TCPAddress.
|
||||
func NetToPublic(net *pb.TcpAddress) *l5dNetPb.TcpAddress {
|
||||
ip := proxyToVizIPAddr(net.GetIp())
|
||||
ip := FromProxyAPI(net.GetIp())
|
||||
|
||||
return &l5dNetPb.TcpAddress{
|
||||
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) {
|
||||
case *pb.IPAddress_Ipv6:
|
||||
return &l5dNetPb.IPAddress{
|
||||
|
|
|
|||
Loading…
Reference in New Issue