Skip to content

Commit

Permalink
fix 503 error caused by outdated endpooints
Browse files Browse the repository at this point in the history
Signed-off-by: Huabing Zhao <[email protected]>
  • Loading branch information
zhaohuabing committed Nov 21, 2024
1 parent 2def6a4 commit cf4271c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,24 @@ func (r *gatewayAPIReconciler) processBackendRefs(ctx context.Context, gwcResour
} else {
for _, endpointSlice := range endpointSliceList.Items {
key := utils.NamespacedName(&endpointSlice).String()
r.log.Info("added EndpointSlice to resource tree",
"namespace", endpointSlice.Namespace,
"name", endpointSlice.Name)

Check warning on line 459 in internal/provider/kubernetes/controller.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/controller.go#L457-L459

Added lines #L457 - L459 were not covered by tests
if !resourceMappings.allAssociatedEndpointSlices.Has(key) {
resourceMappings.allAssociatedEndpointSlices.Insert(key)
r.log.Info("added EndpointSlice to resource tree",
"namespace", endpointSlice.Namespace,
"name", endpointSlice.Name)
gwcResource.EndpointSlices = append(gwcResource.EndpointSlices, &endpointSlice)
} else {
// Update the EndpointSlice in the resourceTree if it already exists
// This is necessary because the EndpointSlice may have been updated
updated := gwcResource.EndpointSlices
for i, es := range gwcResource.EndpointSlices {
if es.Name == endpointSlice.Name && es.Namespace == endpointSlice.Namespace {
updated = append(updated[:i], updated[i+1:]...)
updated = append(updated, &endpointSlice)
break

Check warning on line 471 in internal/provider/kubernetes/controller.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/controller.go#L463-L471

Added lines #L463 - L471 were not covered by tests
}
}
gwcResource.EndpointSlices = updated

Check warning on line 474 in internal/provider/kubernetes/controller.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/controller.go#L474

Added line #L474 was not covered by tests
}
}
}
Expand Down

0 comments on commit cf4271c

Please sign in to comment.