@@ -208,3 +208,215 @@ func (suite *UseBackendSuite) UseBackendFixture() (eventChan chan k8ssync.SyncDa
208208 <- controllerHasWorked
209209 return eventChan
210210}
211+
212+ func (suite * UseBackendSuite ) NonWildcardHostFixture () (eventChan chan k8ssync.SyncDataEvent ) {
213+ var osArgs utils.OSArgs
214+ os .Args = []string {os .Args [0 ], "-e" , "-t" , "--config-dir=" + suite .test .TempDir }
215+ parser := flags .NewParser (& osArgs , flags .IgnoreUnknown )
216+ _ , errParsing := parser .Parse () //nolint:ifshort
217+ if errParsing != nil {
218+ suite .T ().Fatal (errParsing )
219+ }
220+
221+ s := store .NewK8sStore (osArgs )
222+
223+ haproxyEnv := env.Env {
224+ CfgDir : suite .test .TempDir ,
225+ Proxies : env.Proxies {
226+ FrontHTTP : "http" ,
227+ FrontHTTPS : "https" ,
228+ FrontSSL : "ssl" ,
229+ BackSSL : "ssl-backend" ,
230+ },
231+ }
232+
233+ eventChan = make (chan k8ssync.SyncDataEvent , watch .DefaultChanSize * 6 )
234+ controller := c .NewBuilder ().
235+ WithHaproxyCfgFile ([]byte (haproxyConfig )).
236+ WithEventChan (eventChan ).
237+ WithStore (s ).
238+ WithHaproxyEnv (haproxyEnv ).
239+ WithUpdateStatusManager (& updateStatusManager {}).
240+ WithArgs (osArgs ).Build ()
241+
242+ go controller .Start ()
243+
244+ // Now sending store events for test setup
245+ ns := store.Namespace {Name : "ns" , Status : store .ADDED }
246+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .NAMESPACE , Namespace : ns .Name , Data : & ns }
247+
248+ endpoints := & store.Endpoints {
249+ SliceName : "api-service" ,
250+ Service : "api-service" ,
251+ Namespace : ns .Name ,
252+ Ports : map [string ]* store.PortEndpoints {
253+ "https" : {
254+ Port : int64 (3001 ),
255+ Addresses : map [string ]struct {}{"10.244.0.11" : {}},
256+ },
257+ },
258+ Status : store .ADDED ,
259+ }
260+
261+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .ENDPOINTS , Namespace : endpoints .Namespace , Data : endpoints }
262+
263+ service := & store.Service {
264+ Name : "api-service" ,
265+ Namespace : ns .Name ,
266+ Annotations : map [string ]string {"route-acl" : "path_reg path-in-bug-repro$" },
267+ Ports : []store.ServicePort {
268+ {
269+ Name : "https" ,
270+ Protocol : "TCP" ,
271+ Port : 8443 ,
272+ Status : store .ADDED ,
273+ },
274+ },
275+ Status : store .ADDED ,
276+ }
277+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .SERVICE , Namespace : service .Namespace , Data : service }
278+
279+ ingressClass := & store.IngressClass {
280+ Name : "haproxy" ,
281+ Controller : "haproxy.org/ingress-controller" ,
282+ Status : store .ADDED ,
283+ }
284+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .INGRESS_CLASS , Data : ingressClass }
285+
286+ prefixPathType := networkingv1 .PathTypePrefix
287+ ingress := & store.Ingress {
288+ IngressCore : store.IngressCore {
289+ APIVersion : store .NETWORKINGV1 ,
290+ Name : "api-ingress" ,
291+ Namespace : ns .Name ,
292+ Class : "haproxy" ,
293+ Rules : map [string ]* store.IngressRule {
294+ "api.example.local" : {
295+ Host : "api.example.local" , // Explicitly set the Host field
296+ Paths : map [string ]* store.IngressPath {
297+ string (prefixPathType ) + "-/" : {
298+ Path : "/" ,
299+ PathTypeMatch : string (prefixPathType ),
300+ SvcNamespace : service .Namespace ,
301+ SvcPortString : "https" ,
302+ SvcName : service .Name ,
303+ },
304+ },
305+ },
306+ },
307+ },
308+ Status : store .ADDED ,
309+ }
310+
311+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .INGRESS , Namespace : ingress .Namespace , Data : ingress }
312+ controllerHasWorked := make (chan struct {})
313+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .COMMAND , EventProcessed : controllerHasWorked }
314+ <- controllerHasWorked
315+ return eventChan
316+ }
317+
318+ func (suite * UseBackendSuite ) WildcardHostFixture () (eventChan chan k8ssync.SyncDataEvent ) {
319+ var osArgs utils.OSArgs
320+ os .Args = []string {os .Args [0 ], "-e" , "-t" , "--config-dir=" + suite .test .TempDir }
321+ parser := flags .NewParser (& osArgs , flags .IgnoreUnknown )
322+ _ , errParsing := parser .Parse () //nolint:ifshort
323+ if errParsing != nil {
324+ suite .T ().Fatal (errParsing )
325+ }
326+
327+ s := store .NewK8sStore (osArgs )
328+
329+ haproxyEnv := env.Env {
330+ CfgDir : suite .test .TempDir ,
331+ Proxies : env.Proxies {
332+ FrontHTTP : "http" ,
333+ FrontHTTPS : "https" ,
334+ FrontSSL : "ssl" ,
335+ BackSSL : "ssl-backend" ,
336+ },
337+ }
338+
339+ eventChan = make (chan k8ssync.SyncDataEvent , watch .DefaultChanSize * 6 )
340+ controller := c .NewBuilder ().
341+ WithHaproxyCfgFile ([]byte (haproxyConfig )).
342+ WithEventChan (eventChan ).
343+ WithStore (s ).
344+ WithHaproxyEnv (haproxyEnv ).
345+ WithUpdateStatusManager (& updateStatusManager {}).
346+ WithArgs (osArgs ).Build ()
347+
348+ go controller .Start ()
349+
350+ // Now sending store events for test setup
351+ ns := store.Namespace {Name : "ns" , Status : store .ADDED }
352+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .NAMESPACE , Namespace : ns .Name , Data : & ns }
353+
354+ endpoints := & store.Endpoints {
355+ SliceName : "wildcard-service" ,
356+ Service : "wildcard-service" ,
357+ Namespace : ns .Name ,
358+ Ports : map [string ]* store.PortEndpoints {
359+ "https" : {
360+ Port : int64 (3001 ),
361+ Addresses : map [string ]struct {}{"10.244.0.10" : {}},
362+ },
363+ },
364+ Status : store .ADDED ,
365+ }
366+
367+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .ENDPOINTS , Namespace : endpoints .Namespace , Data : endpoints }
368+
369+ service := & store.Service {
370+ Name : "wildcard-service" ,
371+ Namespace : ns .Name ,
372+ Annotations : map [string ]string {"route-acl" : "path_reg path-in-bug-repro$" },
373+ Ports : []store.ServicePort {
374+ {
375+ Name : "https" ,
376+ Protocol : "TCP" ,
377+ Port : 8443 ,
378+ Status : store .ADDED ,
379+ },
380+ },
381+ Status : store .ADDED ,
382+ }
383+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .SERVICE , Namespace : service .Namespace , Data : service }
384+
385+ ingressClass := & store.IngressClass {
386+ Name : "haproxy" ,
387+ Controller : "haproxy.org/ingress-controller" ,
388+ Status : store .ADDED ,
389+ }
390+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .INGRESS_CLASS , Data : ingressClass }
391+
392+ prefixPathType := networkingv1 .PathTypePrefix
393+ ingress := & store.Ingress {
394+ IngressCore : store.IngressCore {
395+ APIVersion : store .NETWORKINGV1 ,
396+ Name : "wildcard-ingress" ,
397+ Namespace : ns .Name ,
398+ Class : "haproxy" ,
399+ Rules : map [string ]* store.IngressRule {
400+ "*.example.local" : {
401+ Host : "*.example.local" , // Explicitly set the Host field
402+ Paths : map [string ]* store.IngressPath {
403+ string (prefixPathType ) + "-/" : {
404+ Path : "/" ,
405+ PathTypeMatch : string (prefixPathType ),
406+ SvcNamespace : service .Namespace ,
407+ SvcPortString : "https" ,
408+ SvcName : service .Name ,
409+ },
410+ },
411+ },
412+ },
413+ },
414+ Status : store .ADDED ,
415+ }
416+
417+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .INGRESS , Namespace : ingress .Namespace , Data : ingress }
418+ controllerHasWorked := make (chan struct {})
419+ eventChan <- k8ssync.SyncDataEvent {SyncType : k8ssync .COMMAND , EventProcessed : controllerHasWorked }
420+ <- controllerHasWorked
421+ return eventChan
422+ }
0 commit comments