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 Dec 3, 2024
1 parent 4e2385f commit e9425ef
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 17 deletions.
65 changes: 65 additions & 0 deletions internal/gatewayapi/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
)

func TestValidateGRPCFilterRef(t *testing.T) {
Expand Down Expand Up @@ -551,3 +552,67 @@ func TestIsRefToGateway(t *testing.T) {
})
}
}

func TestGetServiceIPFamily(t *testing.T) {
testCases := []struct {
name string
service *corev1.Service
expected *egv1a1.IPFamily
}{
{
name: "nil service",
service: nil,
expected: nil,
},
{
name: "require dual stack",
service: &corev1.Service{
Spec: corev1.ServiceSpec{
IPFamilyPolicy: ptr.To(corev1.IPFamilyPolicyRequireDualStack),
},
},
expected: ptr.To(egv1a1.DualStack),
},
{
name: "multiple ip families",
service: &corev1.Service{
Spec: corev1.ServiceSpec{
IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol, corev1.IPv6Protocol},
},
},
expected: ptr.To(egv1a1.DualStack),
},
{
name: "ipv4 only",
service: &corev1.Service{
Spec: corev1.ServiceSpec{
IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol},
},
},
expected: ptr.To(egv1a1.IPv4),
},
{
name: "ipv6 only",
service: &corev1.Service{
Spec: corev1.ServiceSpec{
IPFamilies: []corev1.IPFamily{corev1.IPv6Protocol},
},
},
expected: ptr.To(egv1a1.IPv6),
},
{
name: "no ip family specified",
service: &corev1.Service{
Spec: corev1.ServiceSpec{},
},
expected: nil,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := getServiceIPFamily(tc.service)
require.Equal(t, tc.expected, result)
})
}
}
18 changes: 2 additions & 16 deletions internal/xds/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,7 @@ func (t *Translator) addRouteToRouteConfig(
ea := &ExtraArgs{
metrics: metrics,
http1Settings: httpListener.HTTP1,
ipFamily: httpRoute.Destination.Settings[0].IPFamily,
}

if len(httpRoute.Destination.Settings) > 1 {
ea.ipFamily = determineIPFamily(httpRoute.Destination.Settings)
ipFamily: determineIPFamily(httpRoute.Destination.Settings),
}

if httpRoute.Traffic != nil && httpRoute.Traffic.HTTP2 != nil {
Expand All @@ -485,17 +481,7 @@ func (t *Translator) addRouteToRouteConfig(
}

if httpRoute.Mirrors != nil {

Check failure on line 483 in internal/xds/translator/translator.go

View workflow job for this annotation

GitHub Actions / lint

SA9003: empty branch (staticcheck)
for _, mirrorDest := range httpRoute.Mirrors {
if err = addXdsCluster(tCtx, &xdsClusterArgs{
name: mirrorDest.Name,
settings: mirrorDest.Settings,
tSocket: nil,
endpointType: EndpointTypeStatic,
metrics: metrics,
}); err != nil {
errs = errors.Join(errs, err)
}
}
// TODO: implement mirrors
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/xds/translator/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/envoyproxy/gateway/internal/ir"
)

func Test_determineIPFamily(t *testing.T) {
func TestDetermineIPFamily(t *testing.T) {
tests := []struct {
name string
settings []*ir.DestinationSetting
Expand Down

0 comments on commit e9425ef

Please sign in to comment.