Skip to content

Commit 7f1b637

Browse files
committed
add wildcard ingress host indexing support
1 parent 8a25e4d commit 7f1b637

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

kubernetes.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,27 @@ func lookupIngressIndex(ctrl cache.SharedIndexInformer) func([]string) []interfa
735735
return func(indexKeys []string) (result []interface{}) {
736736
var objs []interface{}
737737
for _, key := range indexKeys {
738-
obj, _ := ctrl.GetIndexer().ByIndex(ingressHostnameIndex, strings.ToLower(key))
738+
key := strings.ToLower(key)
739+
// Ingress is not responsible for _acme-challenge.* FQDN
740+
if strings.HasPrefix(key, "_acme-challenge.") {
741+
continue
742+
}
743+
744+
obj, _ := ctrl.GetIndexer().ByIndex(ingressHostnameIndex, key)
739745
objs = append(objs, obj...)
746+
747+
log.Debugf("No exact matches found for %s, looking for wildcard ingress host", key)
748+
for len(objs) == 0 {
749+
_, after, found := strings.Cut(key, ".")
750+
if !found {
751+
// No more wildcard recursion
752+
break
753+
}
754+
key = after
755+
log.Debugf("Looking for *.%s", key)
756+
obj, _ := ctrl.GetIndexer().ByIndex(ingressHostnameIndex, "*."+key)
757+
objs = append(objs, obj...)
758+
}
740759
}
741760
log.Debugf("Found %d matching Ingress objects", len(objs))
742761
for _, obj := range objs {

test/dual-stack/ingress-services.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ spec:
1818
port:
1919
number: 80
2020
---
21+
apiVersion: networking.k8s.io/v1
22+
kind: Ingress
23+
metadata:
24+
name: ingress-myservice-wildcard
25+
namespace: default
26+
annotations:
27+
cert-manager.io/cluster-issuer: letsencrypt-dns-01
28+
spec:
29+
ingressClassName: nginx
30+
rules:
31+
- host: "*.myservice.foo.org"
32+
http:
33+
paths:
34+
- path: /
35+
pathType: Prefix
36+
backend:
37+
service:
38+
name: backend
39+
port:
40+
number: 80
41+
tls:
42+
- hosts:
43+
- "*.myservice.foo.org"
44+
secretName: ingress-wildcard-cert
45+
---
2146
apiVersion: v1
2247
kind: Service
2348
metadata:

0 commit comments

Comments
 (0)