Skip to content

Commit

Permalink
fix: remove old HTTPRoute's parents' statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo committed Jan 23, 2024
1 parent 939bd85 commit 908cbbc
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion internal/controllers/gateway/httproute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,33 @@ var httprouteParentKind = "Gateway"
// considered "attached" to a given HTTPRoute and ensures that the status
// for the HTTPRoute is updated appropriately.
func (r *HTTPRouteReconciler) ensureGatewayReferenceStatusAdded(ctx context.Context, httproute *gatewayapi.HTTPRoute, gateways ...supportedGatewayWithCondition) (bool, error) {
// map the existing parentStatues to avoid duplications
// Map the existing parentStatues to avoid duplications.
parentStatuses := getParentStatuses(httproute, httproute.Status.Parents)

parentRefKey := func(parentRef gatewayapi.ParentReference) string {
namespace := httproute.Namespace
if parentRef.Namespace != nil {
namespace = string(*parentRef.Namespace)
}
sectionName := ""
if parentRef.SectionName != nil {
sectionName = string(*parentRef.SectionName)
}
return fmt.Sprintf("%s/%s/%s", namespace, parentRef.Name, sectionName)
}

// Discard parent statuses that are not found in the current parentRefs.
currentParentRefs := httproute.Spec.ParentRefs
currentParentRefsMap := lo.SliceToMap(currentParentRefs, func(ref gatewayapi.ParentReference) (string, struct{}) {
return parentRefKey(ref), struct{}{}
})
for _, parentStatus := range parentStatuses {
key := parentRefKey(parentStatus.ParentRef)
if _, ok := currentParentRefsMap[key]; !ok {
delete(parentStatuses, key)
}
}

// overlay the parent ref statuses for all new gateway references
statusChangesWereMade := false
for _, gateway := range gateways {
Expand Down

0 comments on commit 908cbbc

Please sign in to comment.