Skip to content

Commit

Permalink
Fix for IPv6 cluster
Browse files Browse the repository at this point in the history
Related issue:deployments-k8s/5775
Related PRs:
cmd-nsmgr/488
sdk/1281

Signed-off-by: Laszlo Kiraly <[email protected]>
  • Loading branch information
ljkiraly committed May 10, 2022
1 parent e96c4ba commit ade9039
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/imports/imports_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package imports

import (
_ "context"
_ "fmt"
_ "github.com/antonfisher/nested-logrus-formatter"
_ "github.com/edwarnicke/grpcfd"
_ "github.com/golang/protobuf/ptypes/empty"
Expand All @@ -24,6 +23,7 @@ import (
_ "github.com/networkservicemesh/sdk/pkg/registry/common/sendfd"
_ "github.com/networkservicemesh/sdk/pkg/tools/debug"
_ "github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
_ "github.com/networkservicemesh/sdk/pkg/tools/listenonurl"
_ "github.com/networkservicemesh/sdk/pkg/tools/log"
_ "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
_ "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
Expand Down
27 changes: 4 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package main

import (
"context"
"fmt"
"net"
"net/url"
"os"
Expand Down Expand Up @@ -55,6 +54,7 @@ import (
registrysendfd "github.com/networkservicemesh/sdk/pkg/registry/common/sendfd"
"github.com/networkservicemesh/sdk/pkg/tools/debug"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
"github.com/networkservicemesh/sdk/pkg/tools/listenonurl"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
"github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
Expand Down Expand Up @@ -230,7 +230,7 @@ func main() {
registrysendfd.NewNetworkServiceEndpointRegistryClient(),
),
)
nse := getNseEndpoint(listenOn, cfg)
nse := getNseEndpoint(listenOn, cfg, logger)

nse, err = nseRegistryClient.Register(ctx, nse)
logrus.Infof("nse: %+v", nse)
Expand Down Expand Up @@ -261,33 +261,14 @@ func exitOnErr(ctx context.Context, cancel context.CancelFunc, errCh <-chan erro
}(ctx, errCh)
}

func getPublicURL(u *url.URL) string {
if u.Port() == "" || len(u.Host) != len(":")+len(u.Port()) {
return u.String()
}
addrs, err := net.InterfaceAddrs()
if err != nil {
logrus.Warn(err.Error())
return u.String()
}
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return fmt.Sprintf("tcp://%v:%v", ipnet.IP.String(), u.Port())
}
}
}
return u.String()
}

func getNseEndpoint(listenOn *url.URL, cfg *config.Config) *registryapi.NetworkServiceEndpoint {
func getNseEndpoint(listenOn *url.URL, cfg *config.Config, logger log.Logger) *registryapi.NetworkServiceEndpoint {
expireTime := timestamppb.New(time.Now().Add(cfg.MaxTokenLifetime))

nse := &registryapi.NetworkServiceEndpoint{
Name: cfg.Name,
NetworkServiceNames: make([]string, len(cfg.Services)),
NetworkServiceLabels: make(map[string]*registryapi.NetworkServiceLabels, len(cfg.Services)),
Url: getPublicURL(listenOn),
Url: listenonurl.GetPublicURL(listenOn, logger),
ExpirationTime: expireTime,
}

Expand Down

0 comments on commit ade9039

Please sign in to comment.