@@ -18,6 +18,7 @@ import (
1818
1919 "github.com/Azure/application-gateway-kubernetes-ingress/pkg/annotations"
2020 "github.com/Azure/application-gateway-kubernetes-ingress/pkg/appgw"
21+ "github.com/Azure/application-gateway-kubernetes-ingress/pkg/environment"
2122 "github.com/Azure/application-gateway-kubernetes-ingress/pkg/tests"
2223 "github.com/Azure/application-gateway-kubernetes-ingress/pkg/tests/fixtures"
2324)
@@ -202,4 +203,62 @@ var _ = Describe("prune function tests", func() {
202203 Expect (prunedIngresses ).To (ContainElement (ingressValid2 ))
203204 })
204205 })
206+
207+ Context ("ensure pruneProhibitedIngress prunes ingress" , func () {
208+ env := environment .GetFakeEnv ()
209+ env .EnableBrownfieldDeployment = true
210+ ingress := fixtures .GetIngressWithProhibitedTargetConflict ()
211+ cbCtx := & appgw.ConfigBuilderContext {
212+ IngressList : []* networking.Ingress {
213+ ingress ,
214+ },
215+ ServiceList : []* v1.Service {
216+ tests .NewServiceFixture (),
217+ },
218+ ProhibitedTargets : fixtures .GetAzureIngressProhibitedTargets (),
219+ DefaultAddressPoolID : to .StringPtr ("xx" ),
220+ DefaultHTTPSettingsID : to .StringPtr ("yy" ),
221+ EnvVariables : env ,
222+ }
223+ appGw := fixtures .GetAppGateway ()
224+
225+ validateOldIngress := func (oldIngress * networking.Ingress ) {
226+ // should have two rules
227+ Expect (len (oldIngress .Spec .Rules )).To (Equal (2 ))
228+
229+ // should have rule 1 with OldHost as host and no paths
230+ Expect (oldIngress .Spec .Rules [0 ].Host ).To (Equal (tests .OtherHost ))
231+ Expect (len (oldIngress .Spec .Rules [0 ].HTTP .Paths )).To (Equal (0 ))
232+
233+ // should have rule 2 with Host as host and 2 path rules: /foo /fox
234+ Expect (oldIngress .Spec .Rules [1 ].Host ).To (Equal (tests .Host ))
235+ Expect (len (oldIngress .Spec .Rules [1 ].HTTP .Paths )).To (Equal (2 ))
236+ Expect (oldIngress .Spec .Rules [1 ].HTTP .Paths [0 ].Path ).To (Equal (fixtures .PathFoo ))
237+ Expect (oldIngress .Spec .Rules [1 ].HTTP .Paths [1 ].Path ).To (Equal (fixtures .PathFox ))
238+ }
239+
240+ It ("removes the ingress rules without modifying the original ingress" , func () {
241+ Expect (len (cbCtx .IngressList )).To (Equal (1 ))
242+
243+ // Get pointer to the old ingress object
244+ oldIngress := cbCtx .IngressList [0 ]
245+
246+ // Validate that ingress follows the requirement
247+ validateOldIngress (oldIngress )
248+
249+ // Prune: test.OtherHost and /fox are prohibited
250+ _ = pruneProhibitedIngress (controller , & appGw , cbCtx , cbCtx .IngressList )
251+
252+ // Validate old ingress is the same as before
253+ validateOldIngress (oldIngress )
254+
255+ // Validate new ingress
256+ newIngress := cbCtx .IngressList [0 ]
257+
258+ Expect (len (newIngress .Spec .Rules )).To (Equal (1 ), "should have only 1 rule after pruning" )
259+ Expect (len (newIngress .Spec .Rules [0 ].HTTP .Paths )).To (Equal (1 ), "Rule should have only 1 path rule left" )
260+ Expect (oldIngress .Spec .Rules [1 ].Host ).To (Equal (tests .Host ), "Host for that path should be tests.Host" )
261+ Expect (oldIngress .Spec .Rules [1 ].HTTP .Paths [0 ].Path ).To (Equal (fixtures .PathFoo ), "Path should /foo; /fox should be removed" )
262+ })
263+ })
205264})
0 commit comments