Skip to content

Commit

Permalink
lb: Add selectorless config flag
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
qinqon committed Feb 6, 2024
1 parent 3626606 commit 1366ee3
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/provider/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ type LoadBalancerConfig struct {

// CreationPollTimeout determines how many seconds to wait for the load balancer creation
CreationPollTimeout *int `yaml:"creationPollTimeout,omitempty"`

// Selectorless delegate endpointslices creation on third party by
// skipping service selector creation
Selectorless *bool `yaml:"selectorless,omitempty"`
}

type InstancesV2Config struct {
Expand Down
4 changes: 3 additions & 1 deletion pkg/provider/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ func (lb *loadbalancer) createLoadBalancerService(ctx context.Context, lbName st
},
Spec: corev1.ServiceSpec{
Ports: ports,
Selector: vmiLabels,
Type: corev1.ServiceTypeLoadBalancer,
ExternalTrafficPolicy: service.Spec.ExternalTrafficPolicy,
},
}
if lb.config.Selectorless == nil || !*lb.config.Selectorless {
lbService.Spec.Selector = vmiLabels
}
if len(service.Spec.ExternalIPs) > 0 {
lbService.Spec.ExternalIPs = service.Spec.ExternalIPs
}
Expand Down
64 changes: 63 additions & 1 deletion pkg/provider/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ var _ = Describe("LoadBalancer", func() {
loadBalancerIP string
)

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

})

It("Should create new Service without selector if selectorless flag is true", func() {
checkSvcExistErr := notFoundErr
getCount := 1
port := 30001
infraServiceExist := generateInfraService(
tenantService,
[]corev1.ServicePort{
{Name: "port1", Protocol: corev1.ProtocolTCP, Port: 80, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: int32(port)}},
},
)
infraServiceExist.Status = corev1.ServiceStatus{
LoadBalancer: corev1.LoadBalancerStatus{
Ingress: []corev1.LoadBalancerIngress{
{
IP: loadBalancerIP,
},
},
},
}

c.EXPECT().
Get(ctx, client.ObjectKey{Name: "af6ebf1722bb111e9b210d663bd873d9", Namespace: "test"}, gomock.AssignableToTypeOf(&corev1.Service{})).
Return(checkSvcExistErr)

infraService1 := generateInfraService(
tenantService,
[]corev1.ServicePort{
{Name: "port1", Protocol: corev1.ProtocolTCP, Port: 80, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: 30001}},
},
)
infraService1.Spec.Selector = nil

c.EXPECT().Create(ctx, infraService1)

for i := 0; i < getCount; i++ {
infraService2 := infraService1.DeepCopy()
if i == getCount-1 {
infraService2.Status = corev1.ServiceStatus{
LoadBalancer: corev1.LoadBalancerStatus{
Ingress: []corev1.LoadBalancerIngress{
{
IP: loadBalancerIP,
},
},
},
}
}
c.EXPECT().Get(
ctx,
client.ObjectKey{Name: "af6ebf1722bb111e9b210d663bd873d9", Namespace: "test"},
gomock.AssignableToTypeOf(&corev1.Service{}),
).Do(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) {
infraService2.DeepCopyInto(obj.(*corev1.Service))
})
}
lb.config.Selectorless = pointer.Bool(true)
lbStatus, err := lb.EnsureLoadBalancer(ctx, clusterName, tenantService, nodes)
Expect(err).To(BeNil())
Expect(len(lbStatus.Ingress)).Should(Equal(1))
Expect(lbStatus.Ingress[0].IP).Should(Equal(loadBalancerIP))

})
It("Should return an error if service already exist", func() {
expectedError := errors.New("Test error - check if service already exist")
port := 30001
Expand Down

0 comments on commit 1366ee3

Please sign in to comment.