Skip to content

Commit 9c70350

Browse files
authored
fix: Set default ipfamilies to ipv4 if the field is empty (#9112)
1 parent a482dc9 commit 9c70350

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

pkg/provider/azure_utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ func getIPFamiliesEnabled(svc *v1.Service) (v4Enabled bool, v6Enabled bool) {
303303
v6Enabled = true
304304
}
305305
}
306+
if !v4Enabled && !v6Enabled {
307+
v4Enabled = true
308+
}
306309
return
307310
}
308311

pkg/provider/azure_utils_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,14 @@ func TestGetIPFamiliesEnabled(t *testing.T) {
559559
true,
560560
false,
561561
},
562+
{
563+
"IPv6",
564+
&v1.Service{
565+
Spec: v1.ServiceSpec{IPFamilies: []v1.IPFamily{v1.IPv6Protocol}},
566+
},
567+
false,
568+
true,
569+
},
562570
{
563571
"DualStack",
564572
&v1.Service{
@@ -567,6 +575,54 @@ func TestGetIPFamiliesEnabled(t *testing.T) {
567575
true,
568576
true,
569577
},
578+
{
579+
"DualStack IPv6 first",
580+
&v1.Service{
581+
Spec: v1.ServiceSpec{IPFamilies: []v1.IPFamily{v1.IPv6Protocol, v1.IPv4Protocol}},
582+
},
583+
true,
584+
true,
585+
},
586+
{
587+
"Empty IPFamilies - defaults to IPv4",
588+
&v1.Service{
589+
Spec: v1.ServiceSpec{IPFamilies: []v1.IPFamily{}},
590+
},
591+
true,
592+
false,
593+
},
594+
{
595+
"No IPFamilies field - defaults to IPv4",
596+
&v1.Service{
597+
Spec: v1.ServiceSpec{},
598+
},
599+
true,
600+
false,
601+
},
602+
{
603+
"Multiple IPv4 entries",
604+
&v1.Service{
605+
Spec: v1.ServiceSpec{IPFamilies: []v1.IPFamily{v1.IPv4Protocol, v1.IPv4Protocol}},
606+
},
607+
true,
608+
false,
609+
},
610+
{
611+
"Multiple IPv6 entries",
612+
&v1.Service{
613+
Spec: v1.ServiceSpec{IPFamilies: []v1.IPFamily{v1.IPv6Protocol, v1.IPv6Protocol}},
614+
},
615+
false,
616+
true,
617+
},
618+
{
619+
"Mixed multiple entries",
620+
&v1.Service{
621+
Spec: v1.ServiceSpec{IPFamilies: []v1.IPFamily{v1.IPv4Protocol, v1.IPv6Protocol, v1.IPv4Protocol}},
622+
},
623+
true,
624+
true,
625+
},
570626
}
571627
for _, tc := range testcases {
572628
t.Run(tc.desc, func(t *testing.T) {

0 commit comments

Comments
 (0)