Skip to content

Commit 5879269

Browse files
authored
Add network error when service endpoint statuses are unknown (vmware-tanzu#1124)
1 parent 57dd60d commit 5879269

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

pkg/nsx/services/inventory/build_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ func TestBuildService(t *testing.T) {
12671267
assert.Equal(t, NetworkStatusUnhealthy, containerApplication.NetworkStatus)
12681268

12691269
// Verify network errors
1270-
assert.Equal(t, 3, len(containerApplication.NetworkErrors))
1270+
assert.Equal(t, 4, len(containerApplication.NetworkErrors))
12711271

12721272
// Create a map of error messages for easier verification
12731273
errorMessages := make(map[string]bool)

pkg/nsx/services/inventory/builder.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ func (s *InventoryService) BuildService(service *corev1.Service) (retry bool) {
322322
return
323323
}
324324

325+
var networkErrors []common.NetworkError
326+
325327
// Get pods from the endpoint
326328
netStatus := NetworkStatusHealthy
327329
status := InventoryStatusUp
@@ -334,17 +336,22 @@ func (s *InventoryService) BuildService(service *corev1.Service) (retry bool) {
334336
status = InventoryStatusUp
335337
} else if hasAddr {
336338
status = InventoryStatusUnknown
339+
networkErrors = append(networkErrors, common.NetworkError{
340+
ErrorMessage: "Service endpoint status is unknown",
341+
})
337342
} else if hasSelector {
338343
// Only mark as down if service has selector but no endpoints
339344
status = InventoryStatusDown
340345
netStatus = NetworkStatusUnhealthy
346+
networkErrors = append(networkErrors, common.NetworkError{
347+
ErrorMessage: "Failed to get endpoints for Service",
348+
})
341349
} else {
342350
// Service without a selector is valid even without endpoints
343351
status = InventoryStatusUp
344352
}
345353

346354
// Get network errors from service annotations
347-
var networkErrors []common.NetworkError
348355
if status != InventoryStatusUp {
349356
// Check for NCP errors in service annotations
350357
for key, value := range service.Annotations {

pkg/nsx/services/inventory/retrieval.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func GetPodIDsFromEndpoint(ctx context.Context, c client.Client, name string, na
1414
podIDs = []string{}
1515
hasAddr = false
1616

17-
// Get the endpoints object corresponding to the service
17+
// Get the endpoint object corresponding to the service
1818
endpoint := &v1.Endpoints{}
1919
err := c.Get(ctx, types.NamespacedName{
2020
Name: name,
@@ -30,7 +30,7 @@ func GetPodIDsFromEndpoint(ctx context.Context, c client.Client, name string, na
3030
for _, subset := range endpoint.Subsets {
3131
for _, address := range subset.Addresses {
3232
hasAddr = true
33-
if address.TargetRef != nil && address.TargetRef.Kind == "Pod" {
33+
if address.TargetRef != nil && (address.TargetRef.Kind == "Pod" || address.TargetRef.Kind == "VirtualMachine") {
3434
podIDs = append(podIDs, string(address.TargetRef.UID))
3535
}
3636
}
@@ -73,7 +73,7 @@ func GetServicesUIDByPodUID(ctx context.Context, c client.Client, podUID types.U
7373

7474
var serviceUIDs []string
7575
for _, svc := range serviceList.Items {
76-
// Get the endpoints object associated with the service
76+
// Get the endpoint object associated with the service
7777
endpoints := &v1.Endpoints{}
7878
err := c.Get(ctx, types.NamespacedName{Name: svc.Name, Namespace: namespace}, endpoints)
7979
if err != nil {

0 commit comments

Comments
 (0)