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 27, 2024
1 parent 29b5eaa commit f620e41
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
10 changes: 5 additions & 5 deletions internal/gatewayapi/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,20 +610,20 @@ func setIfNil[T any](target **T, value *T) {
}
}

// getIPFamily returns the IPFamily configuration from EnvoyProxy
func getIPFamily(envoyProxy *egv1a1.EnvoyProxy) *ir.IPFamily {
if envoyProxy == nil || envoyProxy.Spec.IPFamily == nil {
return nil
}
var result ir.IPFamily

switch *envoyProxy.Spec.IPFamily {
case egv1a1.IPv4:
result = ir.IPv4
return ptr.To(ir.IPv4)

Check warning on line 621 in internal/gatewayapi/helpers.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/helpers.go#L621

Added line #L621 was not covered by tests
case egv1a1.IPv6:
result = ir.IPv6
return ptr.To(ir.IPv6)

Check warning on line 623 in internal/gatewayapi/helpers.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/helpers.go#L623

Added line #L623 was not covered by tests
case egv1a1.DualStack:
result = ir.Dualstack
return ptr.To(ir.Dualstack)

Check warning on line 625 in internal/gatewayapi/helpers.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/helpers.go#L625

Added line #L625 was not covered by tests
default:
return nil
}
return &result
}
4 changes: 4 additions & 0 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,11 @@ func (t *Translator) processDestination(backendRefContext BackendRefContext,
Protocol: protocol,
Endpoints: endpoints,
AddressType: addrType,
IPFamily: getIPFamily(envoyProxy),
}
case resource.KindService:
ds = t.processServiceDestinationSetting(backendRef.BackendObjectReference, backendNamespace, protocol, resources, envoyProxy)
ds.IPFamily = getIPFamily(envoyProxy)

ds.TLS = t.applyBackendTLSSetting(
backendRef.BackendObjectReference,
Expand All @@ -1282,6 +1284,7 @@ func (t *Translator) processDestination(backendRefContext BackendRefContext,
ds.Filters = t.processDestinationFilters(routeType, backendRefContext, parentRef, route, resources)
case egv1a1.KindBackend:
ds = t.processBackendDestinationSetting(backendRef.BackendObjectReference, backendNamespace, resources)
ds.IPFamily = getIPFamily(envoyProxy)

ds.TLS = t.applyBackendTLSSetting(
backendRef.BackendObjectReference,
Expand Down Expand Up @@ -1379,6 +1382,7 @@ func (t *Translator) processServiceDestinationSetting(
Protocol: protocol,
Endpoints: endpoints,
AddressType: addrType,
IPFamily: getIPFamily(envoyProxy),
}
}

Expand Down
8 changes: 5 additions & 3 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -1308,9 +1308,11 @@ type DestinationSetting struct {
Endpoints []*DestinationEndpoint `json:"endpoints,omitempty" yaml:"endpoints,omitempty"`
// AddressTypeState specifies the state of DestinationEndpoint address type.
AddressType *DestinationAddressType `json:"addressType,omitempty" yaml:"addressType,omitempty"`

TLS *TLSUpstreamConfig `json:"tls,omitempty" yaml:"tls,omitempty"`
Filters *DestinationFilters `json:"filters,omitempty" yaml:"filters,omitempty"`
// IPFamily specifies the IP family (IPv4 or IPv6) to use for this destination's endpoints.
// This is derived from the backend service and endpoint slice information.
IPFamily *IPFamily `json:"ipFamily,omitempty" yaml:"ipFamily,omitempty"`
TLS *TLSUpstreamConfig `json:"tls,omitempty" yaml:"tls,omitempty"`
Filters *DestinationFilters `json:"filters,omitempty" yaml:"filters,omitempty"`
}

// Validate the fields within the RouteDestination structure
Expand Down
5 changes: 5 additions & 0 deletions internal/ir/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions internal/xds/translator/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"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"
)
Expand Down Expand Up @@ -57,7 +56,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 +86,11 @@ func buildXdsCluster(args *xdsClusterArgs) *clusterv3.Cluster {
dnsLookupFamily := clusterv3.Cluster_V4_PREFERRED
if args.ipFamily != nil {
switch *args.ipFamily {
case egv1a1.IPv4:
case ir.IPv4:

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

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/cluster.go#L89

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

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

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/cluster.go#L91

Added line #L91 was not covered by tests
dnsLookupFamily = clusterv3.Cluster_V6_ONLY
case egv1a1.DualStack:
case ir.Dualstack:

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

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/cluster.go#L93

Added line #L93 was not covered by tests
dnsLookupFamily = clusterv3.Cluster_ALL
}
}
Expand Down Expand Up @@ -698,6 +697,7 @@ type ExtraArgs struct {
metrics *ir.Metrics
http1Settings *ir.HTTP1Settings
http2Settings *ir.HTTP2Settings
ipFamily *ir.IPFamily
}

type clusterArgs interface {
Expand All @@ -716,6 +716,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 +738,7 @@ func (route *TCPRouteTranslator) asClusterArgs(extra *ExtraArgs) *xdsClusterArgs
metrics: extra.metrics,
backendConnection: route.BackendConnection,
dns: route.DNS,
ipFamily: extra.ipFamily,
}
}

Expand All @@ -754,6 +756,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
4 changes: 4 additions & 0 deletions internal/xds/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ func (t *Translator) addRouteToRouteConfig(
http1Settings: httpListener.HTTP1,
}

if len(httpRoute.Destination.Settings) > 0 {
ea.ipFamily = httpRoute.Destination.Settings[0].IPFamily
}

if httpRoute.Traffic != nil && httpRoute.Traffic.HTTP2 != nil {
ea.http2Settings = httpRoute.Traffic.HTTP2
}
Expand Down

0 comments on commit f620e41

Please sign in to comment.