@@ -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,83 @@ 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 owner so it is not controlled by this Ingress
234+ route .OwnerReferences = nil
235+ return []runtime.Object {
236+ ing (withBasicSpec , withGatewayAPIclass , withFinalizer , makeItReady ),
237+ httpRoute (t , ing (withBasicSpec , withGatewayAPIclass ), httpRouteReady ),
238+ route ,
239+ }
240+ }(), servicesAndEndpoints ... ),
241+ // No deletes expected
242+ WantDeletes : []clientgotesting.DeleteActionImpl {},
243+ }, {
244+ Name : "prune delete NotFound tolerated" ,
245+ Key : "ns/name" ,
246+ WithReactors : []clientgotesting.ReactionFunc {
247+ func (a clientgotesting.Action ) (bool , runtime.Object , error ) {
248+ if a .GetVerb () == "delete" && a .GetResource ().Resource == "httproutes" {
249+ name := a .(clientgotesting.DeleteActionImpl ).Name
250+ return true , nil , apierrs .NewNotFound (
251+ schema.GroupResource {Group : "gateway.networking.k8s.io" , Resource : "httproutes" },
252+ name ,
253+ )
254+ }
255+ return false , nil , nil
256+ },
257+ },
258+ Objects : append ([]runtime.Object {
259+ ing (withBasicSpec , withGatewayAPIclass , withFinalizer , makeItReady ),
260+ httpRoute (t , ing (withBasicSpec , withGatewayAPIclass ), httpRouteReady ),
261+ HTTPRoute {
262+ Name : "stale.example.com" ,
263+ Namespace : "ns" ,
264+ Hostname : "stale.example.com" ,
265+ }.Build (),
266+ }, servicesAndEndpoints ... ),
267+ WantDeletes : []clientgotesting.DeleteActionImpl {
268+ clientgotesting .NewDeleteAction (
269+ schema.GroupVersionResource {
270+ Group : "gateway.networking.k8s.io" ,
271+ Version : "v1" ,
272+ Resource : "httproutes" ,
273+ },
274+ "ns" ,
275+ "stale.example.com" ,
276+ ),
277+ },
199278 }}
200279
201280 table .Test (t , MakeFactory (func (ctx context.Context , listers * Listers , cmw configmap.Watcher ) controller.Reconciler {
0 commit comments