@@ -161,6 +161,7 @@ func TestBuildNginxResourceObjects(t *testing.T) {
161
161
validateMeta (svc )
162
162
g .Expect (svc .Spec .Type ).To (Equal (defaultServiceType ))
163
163
g .Expect (svc .Spec .ExternalTrafficPolicy ).To (Equal (defaultServicePolicy ))
164
+ g .Expect (* svc .Spec .IPFamilyPolicy ).To (Equal (corev1 .IPFamilyPolicyPreferDualStack ))
164
165
165
166
// service ports is sorted in ascending order by port number when we make the nginx object
166
167
g .Expect (svc .Spec .Ports ).To (Equal ([]corev1.ServicePort {
@@ -260,6 +261,7 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) {
260
261
261
262
resourceName := "gw-nginx"
262
263
nProxyCfg := & graph.EffectiveNginxProxy {
264
+ IPFamily : helpers .GetPointer (ngfAPIv1alpha2 .IPv4 ),
263
265
Logging : & ngfAPIv1alpha2.NginxLogging {
264
266
ErrorLevel : helpers .GetPointer (ngfAPIv1alpha2 .NginxLogLevelDebug ),
265
267
AgentLevel : helpers .GetPointer (ngfAPIv1alpha2 .AgentLogLevelDebug ),
@@ -321,6 +323,8 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) {
321
323
g .Expect (svc .Spec .LoadBalancerIP ).To (Equal ("1.2.3.4" ))
322
324
g .Expect (* svc .Spec .LoadBalancerClass ).To (Equal ("myLoadBalancerClass" ))
323
325
g .Expect (svc .Spec .LoadBalancerSourceRanges ).To (Equal ([]string {"5.6.7.8" }))
326
+ g .Expect (* svc .Spec .IPFamilyPolicy ).To (Equal (corev1 .IPFamilyPolicySingleStack ))
327
+ g .Expect (svc .Spec .IPFamilies ).To (Equal ([]corev1.IPFamily {corev1 .IPv4Protocol }))
324
328
325
329
depObj := objects [5 ]
326
330
dep , ok := depObj .(* appsv1.Deployment )
@@ -961,3 +965,40 @@ func TestBuildNginxResourceObjectsForDeletion_OpenShift(t *testing.T) {
961
965
g .Expect (ok ).To (BeTrue ())
962
966
validateMeta (roleBinding , deploymentNSName .Name )
963
967
}
968
+
969
+ func TestSetIPFamily (t * testing.T ) {
970
+ t .Parallel ()
971
+ g := NewWithT (t )
972
+
973
+ newSvc := func () * corev1.Service {
974
+ return & corev1.Service {
975
+ Spec : corev1.ServiceSpec {},
976
+ }
977
+ }
978
+
979
+ // nProxyCfg is nil, should not set anything
980
+ svc := newSvc ()
981
+ setIPFamily (nil , svc )
982
+ g .Expect (svc .Spec .IPFamilyPolicy ).To (BeNil ())
983
+ g .Expect (svc .Spec .IPFamilies ).To (BeNil ())
984
+
985
+ // nProxyCfg.IPFamily is nil, should not set anything
986
+ svc = newSvc ()
987
+ setIPFamily (& graph.EffectiveNginxProxy {}, svc )
988
+ g .Expect (svc .Spec .IPFamilyPolicy ).To (BeNil ())
989
+ g .Expect (svc .Spec .IPFamilies ).To (BeNil ())
990
+
991
+ // nProxyCfg.IPFamily is IPv4, should set SingleStack and IPFamilies to IPv4
992
+ svc = newSvc ()
993
+ ipFamily := ngfAPIv1alpha2 .IPv4
994
+ setIPFamily (& graph.EffectiveNginxProxy {IPFamily : & ipFamily }, svc )
995
+ g .Expect (svc .Spec .IPFamilyPolicy ).To (Equal (helpers .GetPointer (corev1 .IPFamilyPolicySingleStack )))
996
+ g .Expect (svc .Spec .IPFamilies ).To (Equal ([]corev1.IPFamily {corev1 .IPv4Protocol }))
997
+
998
+ // nProxyCfg.IPFamily is IPv6, should set SingleStack and IPFamilies to IPv6
999
+ svc = newSvc ()
1000
+ ipFamily = ngfAPIv1alpha2 .IPv6
1001
+ setIPFamily (& graph.EffectiveNginxProxy {IPFamily : & ipFamily }, svc )
1002
+ g .Expect (svc .Spec .IPFamilyPolicy ).To (Equal (helpers .GetPointer (corev1 .IPFamilyPolicySingleStack )))
1003
+ g .Expect (svc .Spec .IPFamilies ).To (Equal ([]corev1.IPFamily {corev1 .IPv6Protocol }))
1004
+ }
0 commit comments