Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logic for deleting Services from ProviderResources #536

Closed
chauhanshubham opened this issue Oct 10, 2022 · 2 comments · Fixed by #549
Closed

Fix logic for deleting Services from ProviderResources #536

chauhanshubham opened this issue Oct 10, 2022 · 2 comments · Fixed by #549
Assignees
Labels
kind/bug Something isn't working
Milestone

Comments

@chauhanshubham
Copy link
Member

Description
The current logic attempts to Delete Services from the ProviderResources map when no Routes are found on the cluster, for a given namespace.

r.resources.Services.Delete(request.NamespacedName)

Snippet

// Delete the Namespace and Service from the resource maps if no other
// routes exist in the namespace.
routeList = &gwapiv1b1.HTTPRouteList{}
if err := r.client.List(ctx, routeList, &client.ListOptions{Namespace: request.Namespace}); err != nil {
	return reconcile.Result{}, fmt.Errorf("error listing httproutes")
}
if len(routeList.Items) == 0 {
	r.resources.Namespaces.Delete(request.Namespace)
	log.Info("deleted namespace from resource map")
	r.resources.Services.Delete(request.NamespacedName)
	log.Info("deleted service from resource map")
}

This tries deleting a Service with namespace/name that matches the HTTPRoute which came in to be Reconciled. This will not be the case most of the times.
We must delete the Services which were referred to by the HTTPRoute that has been now deleted.

@chauhanshubham chauhanshubham added the kind/bug Something isn't working label Oct 10, 2022
@danehans danehans added this to the 0.2.0 milestone Oct 11, 2022
@danehans
Copy link
Contributor

xref #539

@chauhanshubham
Copy link
Member Author

chauhanshubham commented Oct 12, 2022

Does having a separate cache for these mappings make sense? Something like

type ProviderCache struct {
   lock
   routeToServicesMappings map[string][]string
   serviceToRoutesMappings map[string][]string // *not having this still helps
}

Or we'll probably have to iterate through the ProviderResource cache multiple times
once to find out which services were referred by the deleted route
and second time to find whether the services are referred by other routes currently present.
^ both the steps must be performed for every kind of route in the ProviderResources

chauhanshubham added a commit to chauhanshubham/gateway that referenced this issue Oct 12, 2022
This commit fetches the services that were referenced by the route
which has now been deleted, and removes those objects from the
resource map. In order to facilitate this, the commit introduces
a provider cache for kubernetes that stores mappings between
kubernetes objects - for now it stores the map between
[tls/http]route -> backend service references.
So that once the [tls/http]route is deleted we have the services that
it referenced.
Fixes: envoyproxy#536

Signed-off-by: Shubham Chauhan <shubham@tetrate.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants