MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / GetEndpointSliceByServiceName

Function GetEndpointSliceByServiceName

tests/utils/endpoints.go:42–67  ·  view source on GitHub ↗

GetEndpointSliceByServiceName returns the EndpointSlice for a given service name in a given namespace

(
	ctx context.Context,
	crudClient client.Client,
	namespace, serviceName string,
)

Source from the content-addressed store, hash-verified

40
41// GetEndpointSliceByServiceName returns the EndpointSlice for a given service name in a given namespace
42func GetEndpointSliceByServiceName(
43 ctx context.Context,
44 crudClient client.Client,
45 namespace, serviceName string,
46) (*discoveryv1.EndpointSlice, error) {
47 endpointSliceList := &discoveryv1.EndpointSliceList{}
48
49 if err := crudClient.List(
50 ctx,
51 endpointSliceList,
52 client.InNamespace(namespace),
53 client.MatchingLabels{"kubernetes.io/service-name": serviceName},
54 ); err != nil {
55 return nil, err
56 }
57
58 if len(endpointSliceList.Items) == 0 {
59 return nil, fmt.Errorf("no endpointslice found for service %s in namespace %s", serviceName, namespace)
60 }
61
62 if len(endpointSliceList.Items) > 1 {
63 return nil, fmt.Errorf("multiple endpointslice found for service %s in namespace %s", serviceName, namespace)
64 }
65
66 return &endpointSliceList.Items[0], nil
67}

Callers 1

assertFastSwitchoverFunction · 0.92

Calls 1

ListMethod · 0.45

Tested by 1

assertFastSwitchoverFunction · 0.74