Skip to content

Commit 1366ee3

Browse files
committed
lb: Add selectorless config flag
For kubevirt virtualmachines without pod networking with just multus secondary networks the generated endpointslices from the service selector are of no use since they are point to the virt-launcher pod that do not point to any VM. This change add a flag to the lb config so users can skip the lb service selector generation and create their own endpointslices pointing to the secondary network IPs. Signed-off-by: Enrique Llorente <[email protected]>
1 parent 3626606 commit 1366ee3

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

pkg/provider/cloud.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ type LoadBalancerConfig struct {
5858

5959
// CreationPollTimeout determines how many seconds to wait for the load balancer creation
6060
CreationPollTimeout *int `yaml:"creationPollTimeout,omitempty"`
61+
62+
// Selectorless delegate endpointslices creation on third party by
63+
// skipping service selector creation
64+
Selectorless *bool `yaml:"selectorless,omitempty"`
6165
}
6266

6367
type InstancesV2Config struct {

pkg/provider/loadbalancer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,13 @@ func (lb *loadbalancer) createLoadBalancerService(ctx context.Context, lbName st
198198
},
199199
Spec: corev1.ServiceSpec{
200200
Ports: ports,
201-
Selector: vmiLabels,
202201
Type: corev1.ServiceTypeLoadBalancer,
203202
ExternalTrafficPolicy: service.Spec.ExternalTrafficPolicy,
204203
},
205204
}
205+
if lb.config.Selectorless == nil || !*lb.config.Selectorless {
206+
lbService.Spec.Selector = vmiLabels
207+
}
206208
if len(service.Spec.ExternalIPs) > 0 {
207209
lbService.Spec.ExternalIPs = service.Spec.ExternalIPs
208210
}

pkg/provider/loadbalancer_test.go

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ var _ = Describe("LoadBalancer", func() {
245245
loadBalancerIP string
246246
)
247247

248-
BeforeAll(func() {
248+
BeforeEach(func() {
249249
ctrl, ctx = gomock.WithContext(context.Background(), GinkgoT())
250250
c = mockclient.NewMockClient(ctrl)
251251
lb = &loadbalancer{
@@ -402,6 +402,68 @@ var _ = Describe("LoadBalancer", func() {
402402

403403
})
404404

405+
It("Should create new Service without selector if selectorless flag is true", func() {
406+
checkSvcExistErr := notFoundErr
407+
getCount := 1
408+
port := 30001
409+
infraServiceExist := generateInfraService(
410+
tenantService,
411+
[]corev1.ServicePort{
412+
{Name: "port1", Protocol: corev1.ProtocolTCP, Port: 80, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: int32(port)}},
413+
},
414+
)
415+
infraServiceExist.Status = corev1.ServiceStatus{
416+
LoadBalancer: corev1.LoadBalancerStatus{
417+
Ingress: []corev1.LoadBalancerIngress{
418+
{
419+
IP: loadBalancerIP,
420+
},
421+
},
422+
},
423+
}
424+
425+
c.EXPECT().
426+
Get(ctx, client.ObjectKey{Name: "af6ebf1722bb111e9b210d663bd873d9", Namespace: "test"}, gomock.AssignableToTypeOf(&corev1.Service{})).
427+
Return(checkSvcExistErr)
428+
429+
infraService1 := generateInfraService(
430+
tenantService,
431+
[]corev1.ServicePort{
432+
{Name: "port1", Protocol: corev1.ProtocolTCP, Port: 80, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: 30001}},
433+
},
434+
)
435+
infraService1.Spec.Selector = nil
436+
437+
c.EXPECT().Create(ctx, infraService1)
438+
439+
for i := 0; i < getCount; i++ {
440+
infraService2 := infraService1.DeepCopy()
441+
if i == getCount-1 {
442+
infraService2.Status = corev1.ServiceStatus{
443+
LoadBalancer: corev1.LoadBalancerStatus{
444+
Ingress: []corev1.LoadBalancerIngress{
445+
{
446+
IP: loadBalancerIP,
447+
},
448+
},
449+
},
450+
}
451+
}
452+
c.EXPECT().Get(
453+
ctx,
454+
client.ObjectKey{Name: "af6ebf1722bb111e9b210d663bd873d9", Namespace: "test"},
455+
gomock.AssignableToTypeOf(&corev1.Service{}),
456+
).Do(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) {
457+
infraService2.DeepCopyInto(obj.(*corev1.Service))
458+
})
459+
}
460+
lb.config.Selectorless = pointer.Bool(true)
461+
lbStatus, err := lb.EnsureLoadBalancer(ctx, clusterName, tenantService, nodes)
462+
Expect(err).To(BeNil())
463+
Expect(len(lbStatus.Ingress)).Should(Equal(1))
464+
Expect(lbStatus.Ingress[0].IP).Should(Equal(loadBalancerIP))
465+
466+
})
405467
It("Should return an error if service already exist", func() {
406468
expectedError := errors.New("Test error - check if service already exist")
407469
port := 30001

0 commit comments

Comments
 (0)