Skip to content

Commit da3d1f3

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

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

charts/k8s-gateway/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ apiVersion: v2
22
name: k8s-gateway
33
description: A fork of the k8s_gateway CoreDNS plugin to allow TXT records
44
type: application
5-
version: 3.0.0
6-
appVersion: 0.5.0
5+
version: 3.1.0
6+
appVersion: 0.6.0
77
maintainers:
88
- email: guillaume@pinax.network
99
name: Guillaume

charts/k8s-gateway/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
image:
22
registry: ghcr.io
33
repository: pinax-network/k8s_gateway
4-
tag: v0.5.0
4+
tag: v0.6.0
55
pullPolicy: IfNotPresent
66

77
# Delegated domain

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)