@@ -23,8 +23,10 @@ import (
2323 "time"
2424
2525 corev1 "k8s.io/api/core/v1"
26+ apierrs "k8s.io/apimachinery/pkg/api/errors"
2627 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728 "k8s.io/apimachinery/pkg/runtime"
29+ "k8s.io/apimachinery/pkg/runtime/schema"
2830 "k8s.io/apimachinery/pkg/types"
2931 clientgotesting "k8s.io/client-go/testing"
3032 "k8s.io/utils/ptr"
@@ -196,6 +198,86 @@ func TestReconcile(t *testing.T) {
196198 httpRoute (t , ing (withBasicSpec , withGatewayAPIclass ), httpRouteReady ),
197199 }, servicesAndEndpoints ... ),
198200 // no extra update
201+ }, {
202+ Name : "prune stale HTTPRoute when rule removed" ,
203+ Key : "ns/name" ,
204+ Objects : append ([]runtime.Object {
205+ ing (withBasicSpec , withGatewayAPIclass , withFinalizer , makeItReady ),
206+ httpRoute (t , ing (withBasicSpec , withGatewayAPIclass ), httpRouteReady ),
207+ HTTPRoute {
208+ Name : "stale.example.com" ,
209+ Namespace : "ns" ,
210+ Hostname : "stale.example.com" ,
211+ }.Build (),
212+ }, servicesAndEndpoints ... ),
213+ WantDeletes : []clientgotesting.DeleteActionImpl {
214+ clientgotesting .NewDeleteAction (
215+ schema.GroupVersionResource {
216+ Group : "gateway.networking.k8s.io" ,
217+ Version : "v1" ,
218+ Resource : "httproutes" ,
219+ },
220+ "ns" ,
221+ "stale.example.com" ,
222+ ),
223+ },
224+ }, {
225+ Name : "prune skips non-owned HTTPRoute" ,
226+ Key : "ns/name" ,
227+ Objects : append (func () []runtime.Object {
228+ route := HTTPRoute {
229+ Name : "stale.example.com" ,
230+ Namespace : "ns" ,
231+ Hostname : "stale.example.com" ,
232+ }.Build ()
233+ // Remove controller ownership and the ingress label so this HTTPRoute
234+ // is neither controlled by nor labeled for this Ingress. It should
235+ // therefore be ignored by the prune logic.
236+ route .OwnerReferences = nil
237+ delete (route .Labels , networking .IngressLabelKey )
238+ return []runtime.Object {
239+ ing (withBasicSpec , withGatewayAPIclass , withFinalizer , makeItReady ),
240+ httpRoute (t , ing (withBasicSpec , withGatewayAPIclass ), httpRouteReady ),
241+ route ,
242+ }
243+ }(), servicesAndEndpoints ... ),
244+ // No deletes expected
245+ WantDeletes : []clientgotesting.DeleteActionImpl {},
246+ }, {
247+ Name : "prune delete NotFound tolerated" ,
248+ Key : "ns/name" ,
249+ WithReactors : []clientgotesting.ReactionFunc {
250+ func (a clientgotesting.Action ) (bool , runtime.Object , error ) {
251+ if a .GetVerb () == "delete" && a .GetResource ().Resource == "httproutes" {
252+ name := a .(clientgotesting.DeleteActionImpl ).Name
253+ return true , nil , apierrs .NewNotFound (
254+ schema.GroupResource {Group : "gateway.networking.k8s.io" , Resource : "httproutes" },
255+ name ,
256+ )
257+ }
258+ return false , nil , nil
259+ },
260+ },
261+ Objects : append ([]runtime.Object {
262+ ing (withBasicSpec , withGatewayAPIclass , withFinalizer , makeItReady ),
263+ httpRoute (t , ing (withBasicSpec , withGatewayAPIclass ), httpRouteReady ),
264+ HTTPRoute {
265+ Name : "stale.example.com" ,
266+ Namespace : "ns" ,
267+ Hostname : "stale.example.com" ,
268+ }.Build (),
269+ }, servicesAndEndpoints ... ),
270+ WantDeletes : []clientgotesting.DeleteActionImpl {
271+ clientgotesting .NewDeleteAction (
272+ schema.GroupVersionResource {
273+ Group : "gateway.networking.k8s.io" ,
274+ Version : "v1" ,
275+ Resource : "httproutes" ,
276+ },
277+ "ns" ,
278+ "stale.example.com" ,
279+ ),
280+ },
199281 }}
200282
201283 table .Test (t , MakeFactory (func (ctx context.Context , listers * Listers , cmw configmap.Watcher ) controller.Reconciler {
0 commit comments