Skip to content

Commit

Permalink
feat: use endpoint slice to check vip status
Browse files Browse the repository at this point in the history
Signed-off-by: wangxye <[email protected]>
  • Loading branch information
wangxye committed Aug 7, 2024
1 parent cabf02c commit 54ee33e
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strings"

corev1 "k8s.io/api/core/v1"
discoveryv1 "k8s.io/api/discovery/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -519,25 +520,25 @@ func (r *ReconcileVipLoadBalancer) getVipServiceStatus(ctx context.Context, pool
// Get the reference endpoint
listSelector := &client.ListOptions{
LabelSelector: labels.SelectorFromSet(map[string]string{
network.LabelServiceName: poolService.Labels[network.LabelServiceName],
discoveryv1.LabelServiceName: poolService.Labels[network.LabelServiceName],
}),
Namespace: poolService.Namespace,
}

endpointSlice := &corev1.EndpointsList{}
if err := r.List(ctx, endpointSlice, listSelector); err != nil {
endpointSlices := &discoveryv1.EndpointSliceList{}
if err := r.List(ctx, endpointSlices, listSelector); err != nil {
klog.Errorf(Format("Failed to get Endpoints from PoolService %s/%s: %v", poolService.Namespace, poolService.Name, err))
return ServiceVIPUnknown
}

if len(endpointSlice.Items) == 0 {
if len(endpointSlices.Items) == 0 {
klog.Errorf(Format("get Endpoints from PoolService %s/%s is empty", poolService.Namespace, poolService.Name))
return ServiceVIPUnknown
}

ready := 0
target := len(endpointSlice.Items)/2 + 1
for _, ep := range endpointSlice.Items {
target := len(endpointSlices.Items)/2 + 1
for _, ep := range endpointSlices.Items {
if ep.Annotations == nil {
continue
}
Expand Down

0 comments on commit 54ee33e

Please sign in to comment.