Skip to content

Commit

Permalink
chore: fix ipFamily always nil
Browse files Browse the repository at this point in the history
Signed-off-by: Juwon Hwang (Kevin) <[email protected]>
  • Loading branch information
juwon8891 committed Nov 26, 2024
1 parent 6a1fd8a commit e029e70
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
3 changes: 0 additions & 3 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
EscapedSlashesAction: ir.UnescapeAndRedirect,
},
}
if ipFamily := getIPFamily(gateway.envoyProxy); ipFamily != nil {
irListener.CoreListenerDetails.IPFamily = ipFamily
}
if listener.Hostname != nil {
irListener.Hostnames = append(irListener.Hostnames, string(*listener.Hostname))
} else {
Expand Down
18 changes: 10 additions & 8 deletions internal/xds/translator/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"sort"
"time"

"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/utils/protocov"
clusterv3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
endpointv3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
Expand All @@ -27,10 +29,6 @@ import (
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/wrapperspb"
"k8s.io/utils/ptr"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/utils/protocov"
)

const (
Expand All @@ -57,7 +55,7 @@ type xdsClusterArgs struct {
backendConnection *ir.BackendConnection
dns *ir.DNS
useClientProtocol bool
ipFamily *egv1a1.IPFamily
ipFamily *ir.IPFamily
}

type EndpointType int
Expand Down Expand Up @@ -87,11 +85,11 @@ func buildXdsCluster(args *xdsClusterArgs) *clusterv3.Cluster {
dnsLookupFamily := clusterv3.Cluster_AUTO
if args.ipFamily != nil {
switch *args.ipFamily {
case egv1a1.IPv4:
case ir.IPv4:

Check warning on line 88 in internal/xds/translator/cluster.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/cluster.go#L88

Added line #L88 was not covered by tests
dnsLookupFamily = clusterv3.Cluster_V4_ONLY
case egv1a1.IPv6:
case ir.IPv6:

Check warning on line 90 in internal/xds/translator/cluster.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/cluster.go#L90

Added line #L90 was not covered by tests
dnsLookupFamily = clusterv3.Cluster_V6_ONLY
case egv1a1.DualStack:
case ir.Dualstack:
dnsLookupFamily = clusterv3.Cluster_ALL
}
}
Expand Down Expand Up @@ -698,6 +696,7 @@ type ExtraArgs struct {
metrics *ir.Metrics
http1Settings *ir.HTTP1Settings
http2Settings *ir.HTTP2Settings
ipFamily *ir.IPFamily
}

type clusterArgs interface {
Expand All @@ -716,6 +715,7 @@ func (route *UDPRouteTranslator) asClusterArgs(extra *ExtraArgs) *xdsClusterArgs
endpointType: buildEndpointType(route.Destination.Settings),
metrics: extra.metrics,
dns: route.DNS,
ipFamily: extra.ipFamily,
}
}

Expand All @@ -737,6 +737,7 @@ func (route *TCPRouteTranslator) asClusterArgs(extra *ExtraArgs) *xdsClusterArgs
metrics: extra.metrics,
backendConnection: route.BackendConnection,
dns: route.DNS,
ipFamily: extra.ipFamily,
}
}

Expand All @@ -754,6 +755,7 @@ func (httpRoute *HTTPRouteTranslator) asClusterArgs(extra *ExtraArgs) *xdsCluste
http1Settings: extra.http1Settings,
http2Settings: extra.http2Settings,
useClientProtocol: ptr.Deref(httpRoute.UseClientProtocol, false),
ipFamily: extra.ipFamily,
}

// Populate traffic features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: ALL
edsClusterConfig:
edsConfig:
ads: {}
Expand Down
11 changes: 9 additions & 2 deletions internal/xds/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ func (t *Translator) addRouteToRouteConfig(
ea := &ExtraArgs{
metrics: metrics,
http1Settings: httpListener.HTTP1,
ipFamily: httpListener.IPFamily,
}

if httpRoute.Traffic != nil && httpRoute.Traffic.HTTP2 != nil {
Expand Down Expand Up @@ -597,7 +598,10 @@ func (t *Translator) processTCPListenerXdsTranslation(
patchProxyProtocolFilter(xdsListener, tcpListener.EnableProxyProtocol)

for _, route := range tcpListener.Routes {
if err := processXdsCluster(tCtx, &TCPRouteTranslator{route}, &ExtraArgs{metrics: metrics}); err != nil {
if err := processXdsCluster(tCtx, &TCPRouteTranslator{route}, &ExtraArgs{
metrics: metrics,
ipFamily: tcpListener.IPFamily,
}); err != nil {
errs = errors.Join(errs, err)
}
if route.TLS != nil && route.TLS.Terminate != nil {
Expand Down Expand Up @@ -684,7 +688,10 @@ func processUDPListenerXdsTranslation(
}

// 1:1 between IR UDPRoute and xDS Cluster
if err := processXdsCluster(tCtx, &UDPRouteTranslator{route}, &ExtraArgs{metrics: metrics}); err != nil {
if err := processXdsCluster(tCtx, &UDPRouteTranslator{route}, &ExtraArgs{
metrics: metrics,
ipFamily: udpListener.IPFamily,
}); err != nil {
errs = errors.Join(errs, err)
}
}
Expand Down

0 comments on commit e029e70

Please sign in to comment.