@@ -12,10 +12,11 @@ import (
1212 coh "github.com/oracle/coherence-operator/api/v1"
1313 corev1 "k8s.io/api/core/v1"
1414 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+ "k8s.io/utils/ptr"
1516 "testing"
1617)
1718
18- func TestCreateWKAServiceForMinimalJonDeployment (t * testing.T ) {
19+ func TestCreateWKAServiceForMinimalJsonDeployment (t * testing.T ) {
1920 // Create the test deployment
2021 deployment := & coh.CoherenceJob {
2122 ObjectMeta : metav1.ObjectMeta {
@@ -315,6 +316,60 @@ func TestCreateWKAServiceForJobWithAdditionalAnnotations(t *testing.T) {
315316 assertWKAServiceForJob (t , deployment , expected )
316317}
317318
319+ func TestCreateJobWKAServiceWithIPFamily (t * testing.T ) {
320+ // Create the test deployment
321+ deployment := & coh.CoherenceJob {
322+ ObjectMeta : metav1.ObjectMeta {
323+ Namespace : "test-ns" ,
324+ Name : "test" ,
325+ },
326+ Spec : coh.CoherenceJobResourceSpec {
327+ CoherenceResourceSpec : coh.CoherenceResourceSpec {
328+ Coherence : & coh.CoherenceSpec {
329+ WKA : & coh.CoherenceWKASpec {
330+ IPFamily : ptr .To (corev1 .IPv4Protocol ),
331+ },
332+ },
333+ },
334+ Cluster : "test-cluster" ,
335+ },
336+ }
337+
338+ // create the expected WKA service
339+ labels := deployment .CreateCommonLabels ()
340+ labels [coh .LabelCoherenceCluster ] = "test-cluster"
341+ labels [coh .LabelComponent ] = coh .LabelComponentWKA
342+
343+ // The selector for the service (match all Pods with the same cluster label)
344+ selector := make (map [string ]string )
345+ selector [coh .LabelCoherenceCluster ] = "test-cluster"
346+ selector [coh .LabelComponent ] = coh .LabelComponentCoherencePod
347+ selector [coh .LabelCoherenceWKAMember ] = "true"
348+
349+ expected := & corev1.Service {
350+ ObjectMeta : metav1.ObjectMeta {
351+ Namespace : "test-ns" ,
352+ Name : "test-wka" ,
353+ Labels : labels ,
354+ Annotations : map [string ]string {
355+ "service.alpha.kubernetes.io/tolerate-unready-endpoints" : "true" ,
356+ },
357+ },
358+ Spec : corev1.ServiceSpec {
359+ ClusterIP : corev1 .ClusterIPNone ,
360+ // Pods must be part of the WKA service even if not ready
361+ PublishNotReadyAddresses : true ,
362+ Ports : getDefaultServicePorts (),
363+ Selector : selector ,
364+ IPFamilyPolicy : ptr .To (corev1 .IPFamilyPolicySingleStack ),
365+ IPFamilies : []corev1.IPFamily {corev1 .IPv4Protocol },
366+ },
367+ }
368+
369+ // assert that the Services are as expected
370+ assertWKAServiceForJob (t , deployment , expected )
371+ }
372+
318373func assertWKAServiceForJob (t * testing.T , deployment * coh.CoherenceJob , expected * corev1.Service ) {
319374 g := NewGomegaWithT (t )
320375
0 commit comments