Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/builder/controller_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (b *Builder) BuildControllerService(controller *slinkyv1alpha1.Controller)
Selector: labels.NewBuilder().
WithControllerSelectorLabels(controller).
Build(),
Headless: controller.Spec.Service.ServiceSpecWrapper.ServiceSpec.ClusterIP == corev1.ClusterIPNone,
}

opts.Metadata.Labels = structutils.MergeMaps(opts.Metadata.Labels, labels.NewBuilder().WithControllerLabels(controller).Build())
Expand Down
32 changes: 32 additions & 0 deletions internal/builder/controller_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ func TestBuilder_BuildControllerService(t *testing.T) {
},
},
},
{
name: "headless service",
fields: fields{
client: fake.NewFakeClient(),
},
args: args{
controller: &slinkyv1alpha1.Controller{
ObjectMeta: metav1.ObjectMeta{
Name: "slurm",
},
Spec: slinkyv1alpha1.ControllerSpec{
Service: slinkyv1alpha1.ServiceSpec{
ServiceSpecWrapper: slinkyv1alpha1.ServiceSpecWrapper{
ServiceSpec: corev1.ServiceSpec{
ClusterIP: corev1.ClusterIPNone,
},
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -69,6 +91,16 @@ func TestBuilder_BuildControllerService(t *testing.T) {
got2.Spec.Template.Spec.Containers[0].Ports[0].Name,
got2.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort)
}

// Test headless service configuration
if tt.name == "headless service" {
if got.Spec.ClusterIP != corev1.ClusterIPNone {
t.Errorf("Expected headless service (ClusterIP=None), got ClusterIP=%v", got.Spec.ClusterIP)
}
if !got.Spec.PublishNotReadyAddresses {
t.Errorf("Expected PublishNotReadyAddresses=true for headless service, got %v", got.Spec.PublishNotReadyAddresses)
}
}
Comment on lines 100 to 110
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fragile methodology to express the test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the fragile tests

})
}
}