Skip to content

Commit

Permalink
fix(*): moved utils to other pkg
Browse files Browse the repository at this point in the history
Signed-off-by: Łukasz Dziedziak <lukidzi@gmail.com>
  • Loading branch information
lukidzi committed Aug 12, 2022
1 parent 04ba990 commit 61329d7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/kuma-dp/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"github.com/kumahq/kuma/pkg/core/resources/model/rest"
"github.com/kumahq/kuma/pkg/core/runtime/component"
core_xds "github.com/kumahq/kuma/pkg/core/xds"
"github.com/kumahq/kuma/pkg/util/net"
"github.com/kumahq/kuma/pkg/util/proto"
kuma_version "github.com/kumahq/kuma/pkg/version"
"github.com/kumahq/kuma/pkg/xds/bootstrap/types"
xds_generator "github.com/kumahq/kuma/pkg/xds/generator"
)

var runLog = dataplaneLog.WithName("run")
Expand Down Expand Up @@ -300,7 +300,7 @@ func getApplicationsToScrape(kumaSidecarConfiguration *types.KumaSidecarConfigur
Name: item.Name,
Path: item.Path,
Port: item.Port,
IsIPv6: xds_generator.IsAddressIPv6(item.Address),
IsIPv6: net.IsAddressIPv6(item.Address),
QueryModifier: metrics.RemoveQueryParameters,
})
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/util/net/ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ func ToV6(ip string) string {
}
return ip
}

func IsAddressIPv6(address string) bool {
if address == "" {
return false
}

ip := net.ParseIP(address)
if ip == nil {
return false
}

return ip.To4() == nil
}
9 changes: 9 additions & 0 deletions pkg/util/net/ips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ var _ = DescribeTable("ToV6",
Entry("v4 adds prefix", "240.0.0.0", "::ffff:f000:0"),
Entry("v4 adds prefix", "240.0.255.0", "::ffff:f000:ff00"),
)

var _ = DescribeTable("IsIPv6",
func(given string, expected bool) {
Expect(net.IsAddressIPv6(given)).To(Equal(expected))
},
Entry("127.0.0.1 should not be IPv6 ", "127.0.0.1", false),
Entry("should be IPv6", "2001:0db8:0000:0000:0000:ff00:0042:8329", true),
Entry("::6", "::6", true),
)
3 changes: 2 additions & 1 deletion pkg/xds/generator/inbound_proxy_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/kumahq/kuma/pkg/core/validators"
core_xds "github.com/kumahq/kuma/pkg/core/xds"
defaults_mesh "github.com/kumahq/kuma/pkg/defaults/mesh"
"github.com/kumahq/kuma/pkg/util/net"
xds_context "github.com/kumahq/kuma/pkg/xds/context"
envoy_common "github.com/kumahq/kuma/pkg/xds/envoy"
envoy_clusters "github.com/kumahq/kuma/pkg/xds/envoy/clusters"
Expand Down Expand Up @@ -43,7 +44,7 @@ func (g InboundProxyGenerator) Generate(ctx xds_context.Context, proxy *core_xds
// localhost traffic is routed dirrectly to the application, in case of other interface we are going to set source address to
// 127.0.0.6 to avoid redirections and thanks to first iptables rule just return fast
if endpoint.WorkloadIP != core_mesh.IPv4Loopback.String() || endpoint.WorkloadIP != core_mesh.IPv6Loopback.String() {
switch IsAddressIPv6(endpoint.WorkloadIP) {
switch net.IsAddressIPv6(endpoint.WorkloadIP) {
case true:
clusterBuilder.Configure(envoy_clusters.UpstreamBindConfig(inPassThroughIPv6, 0))
case false:
Expand Down
16 changes: 0 additions & 16 deletions pkg/xds/generator/utils.go

This file was deleted.

0 comments on commit 61329d7

Please sign in to comment.