Skip to content

Commit 7e34adf

Browse files
committed
use Ingress label to select HTTPRoutes for pruning
Signed-off-by: kahirokunn <[email protected]>
1 parent baa1027 commit 7e34adf

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

pkg/reconciler/ingress/fixtures_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func (r HTTPRoute) Build() *gatewayapi.HTTPRoute {
5757
networking.IngressClassAnnotationKey: gatewayAPIIngressClassName,
5858
},
5959
Labels: map[string]string{
60+
networking.IngressLabelKey: "name",
6061
networking.VisibilityLabelKey: "",
6162
},
6263
OwnerReferences: []metav1.OwnerReference{{

pkg/reconciler/ingress/ingress.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"knative.dev/net-gateway-api/pkg/reconciler/ingress/config"
3030
"knative.dev/net-gateway-api/pkg/reconciler/ingress/resources"
3131
"knative.dev/net-gateway-api/pkg/status"
32+
"knative.dev/networking/pkg/apis/networking"
3233
"knative.dev/networking/pkg/apis/networking/v1alpha1"
3334
ingressreconciler "knative.dev/networking/pkg/client/injection/reconciler/networking/v1alpha1/ingress"
3435
"knative.dev/networking/pkg/ingress"
@@ -131,15 +132,14 @@ func (c *Reconciler) reconcileIngress(ctx context.Context, ing *v1alpha1.Ingress
131132

132133
// Delete HTTPRoutes that don't exist in the current Spec (i.e., tags removed and no longer referenced)
133134
{
134-
existingRoutes, err := c.httprouteLister.HTTPRoutes(ing.Namespace).List(labels.Everything())
135+
selector := labels.SelectorFromSet(labels.Set{
136+
networking.IngressLabelKey: ing.Name,
137+
})
138+
existingRoutes, err := c.httprouteLister.HTTPRoutes(ing.Namespace).List(selector)
135139
if err != nil {
136140
return fmt.Errorf("failed to list HTTPRoutes: %w", err)
137141
}
138142
for _, r := range existingRoutes {
139-
// Don't touch routes not owned by this Ingress
140-
if !metav1.IsControlledBy(r, ing) {
141-
continue
142-
}
143143
// Not in the desired set = unnecessary
144144
if !desiredRouteNames.Has(r.Name) {
145145
if err := c.gwapiclient.GatewayV1().HTTPRoutes(r.Namespace).Delete(ctx, r.Name, metav1.DeleteOptions{}); err != nil && !apierrs.IsNotFound(err) {

pkg/reconciler/ingress/resources/httproute.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ func MakeHTTPRoute(
204204
Name: LongestHost(rule.Hosts),
205205
Namespace: ing.Namespace,
206206
Labels: kmeta.UnionMaps(ing.Labels, map[string]string{
207+
networking.IngressLabelKey: ing.Name,
207208
networking.VisibilityLabelKey: visibility,
208209
}),
209210
Annotations: kmeta.FilterMap(ing.GetAnnotations(), func(key string) bool {

0 commit comments

Comments
 (0)