From f356ebf97d8d9d5489ef0b7a130102337f7e27c7 Mon Sep 17 00:00:00 2001 From: "Juwon Hwang (Kevin)" Date: Fri, 29 Nov 2024 16:14:46 +0900 Subject: [PATCH] chore: fix ipFamily always nil Signed-off-by: Juwon Hwang (Kevin) --- internal/xds/translator/utils.go | 23 ++++----- internal/xds/translator/utils_test.go | 55 +++++++++++----------- test/e2e/testdata/httproute-dualstack.yaml | 2 +- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/internal/xds/translator/utils.go b/internal/xds/translator/utils.go index a897bb19b7f..c2659bd3b8f 100644 --- a/internal/xds/translator/utils.go +++ b/internal/xds/translator/utils.go @@ -6,12 +6,6 @@ package translator import ( - "log" - - egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" - "github.com/envoyproxy/gateway/internal/ir" - "k8s.io/utils/ptr" - "errors" "fmt" "net/netip" @@ -23,7 +17,10 @@ import ( routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3" hcmv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3" "google.golang.org/protobuf/types/known/anypb" + "k8s.io/utils/ptr" + egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" + "github.com/envoyproxy/gateway/internal/ir" "github.com/envoyproxy/gateway/internal/xds/types" ) @@ -221,16 +218,16 @@ func determineIPFamily(settings []*ir.DestinationSetting) *egv1a1.IPFamily { } } - if hasDualStack { + switch { + case hasDualStack: return ptr.To(egv1a1.DualStack) - } else if hasIPv4 && hasIPv6 { + case hasIPv4 && hasIPv6: return ptr.To(egv1a1.DualStack) - } else if hasIPv4 { + case hasIPv4: return ptr.To(egv1a1.IPv4) - } else if hasIPv6 { - log.Printf("Using IPv6") + case hasIPv6: return ptr.To(egv1a1.IPv6) + default: + return nil } - - return nil } diff --git a/internal/xds/translator/utils_test.go b/internal/xds/translator/utils_test.go index 0017a64f891..89b3a34aedf 100644 --- a/internal/xds/translator/utils_test.go +++ b/internal/xds/translator/utils_test.go @@ -8,17 +8,18 @@ package translator import ( "testing" - "github.com/envoyproxy/gateway/api/v1alpha1" - "github.com/envoyproxy/gateway/internal/ir" "github.com/stretchr/testify/assert" "k8s.io/utils/ptr" + + egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" + "github.com/envoyproxy/gateway/internal/ir" ) func Test_determineIPFamily(t *testing.T) { tests := []struct { name string settings []*ir.DestinationSetting - want *v1alpha1.IPFamily + want *egv1a1.IPFamily }{ { name: "nil settings should return nil", @@ -33,72 +34,72 @@ func Test_determineIPFamily(t *testing.T) { { name: "single IPv4 setting", settings: []*ir.DestinationSetting{ - {IPFamily: ptr.To(v1alpha1.IPv4)}, + {IPFamily: ptr.To(egv1a1.IPv4)}, }, - want: ptr.To(v1alpha1.IPv4), + want: ptr.To(egv1a1.IPv4), }, { name: "single IPv6 setting", settings: []*ir.DestinationSetting{ - {IPFamily: ptr.To(v1alpha1.IPv6)}, + {IPFamily: ptr.To(egv1a1.IPv6)}, }, - want: ptr.To(v1alpha1.IPv6), + want: ptr.To(egv1a1.IPv6), }, { name: "single DualStack setting", settings: []*ir.DestinationSetting{ - {IPFamily: ptr.To(v1alpha1.DualStack)}, + {IPFamily: ptr.To(egv1a1.DualStack)}, }, - want: ptr.To(v1alpha1.DualStack), + want: ptr.To(egv1a1.DualStack), }, { name: "mixed IPv4 and IPv6 should return DualStack", settings: []*ir.DestinationSetting{ - {IPFamily: ptr.To(v1alpha1.IPv4)}, - {IPFamily: ptr.To(v1alpha1.IPv6)}, + {IPFamily: ptr.To(egv1a1.IPv4)}, + {IPFamily: ptr.To(egv1a1.IPv6)}, }, - want: ptr.To(v1alpha1.DualStack), + want: ptr.To(egv1a1.DualStack), }, { name: "DualStack with IPv4 should return DualStack", settings: []*ir.DestinationSetting{ - {IPFamily: ptr.To(v1alpha1.DualStack)}, - {IPFamily: ptr.To(v1alpha1.IPv4)}, + {IPFamily: ptr.To(egv1a1.DualStack)}, + {IPFamily: ptr.To(egv1a1.IPv4)}, }, - want: ptr.To(v1alpha1.DualStack), + want: ptr.To(egv1a1.DualStack), }, { name: "DualStack with IPv6 should return DualStack", settings: []*ir.DestinationSetting{ - {IPFamily: ptr.To(v1alpha1.DualStack)}, - {IPFamily: ptr.To(v1alpha1.IPv6)}, + {IPFamily: ptr.To(egv1a1.DualStack)}, + {IPFamily: ptr.To(egv1a1.IPv6)}, }, - want: ptr.To(v1alpha1.DualStack), + want: ptr.To(egv1a1.DualStack), }, { name: "mixed with nil IPFamily should be ignored", settings: []*ir.DestinationSetting{ - {IPFamily: ptr.To(v1alpha1.IPv4)}, + {IPFamily: ptr.To(egv1a1.IPv4)}, {IPFamily: nil}, - {IPFamily: ptr.To(v1alpha1.IPv6)}, + {IPFamily: ptr.To(egv1a1.IPv6)}, }, - want: ptr.To(v1alpha1.DualStack), + want: ptr.To(egv1a1.DualStack), }, { name: "multiple IPv4 settings should return IPv4", settings: []*ir.DestinationSetting{ - {IPFamily: ptr.To(v1alpha1.IPv4)}, - {IPFamily: ptr.To(v1alpha1.IPv4)}, + {IPFamily: ptr.To(egv1a1.IPv4)}, + {IPFamily: ptr.To(egv1a1.IPv4)}, }, - want: ptr.To(v1alpha1.IPv4), + want: ptr.To(egv1a1.IPv4), }, { name: "multiple IPv6 settings should return IPv6", settings: []*ir.DestinationSetting{ - {IPFamily: ptr.To(v1alpha1.IPv6)}, - {IPFamily: ptr.To(v1alpha1.IPv6)}, + {IPFamily: ptr.To(egv1a1.IPv6)}, + {IPFamily: ptr.To(egv1a1.IPv6)}, }, - want: ptr.To(v1alpha1.IPv6), + want: ptr.To(egv1a1.IPv6), }, } diff --git a/test/e2e/testdata/httproute-dualstack.yaml b/test/e2e/testdata/httproute-dualstack.yaml index d6ca9ed0b4d..97a79c78ac3 100644 --- a/test/e2e/testdata/httproute-dualstack.yaml +++ b/test/e2e/testdata/httproute-dualstack.yaml @@ -150,4 +150,4 @@ metadata: name: envoy-gateway namespace: gateway-conformance-infra spec: - controllerName: gateway.envoyproxy.io/gatewayclass-controller \ No newline at end of file + controllerName: gateway.envoyproxy.io/gatewayclass-controller