Skip to content

Commit

Permalink
add wildcard ingress host indexing support
Browse files Browse the repository at this point in the history
  • Loading branch information
gcleroux committed Jan 20, 2025
1 parent 8a25e4d commit da3d1f3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
4 changes: 2 additions & 2 deletions charts/k8s-gateway/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: k8s-gateway
description: A fork of the k8s_gateway CoreDNS plugin to allow TXT records
type: application
version: 3.0.0
appVersion: 0.5.0
version: 3.1.0
appVersion: 0.6.0
maintainers:
- email: [email protected]
name: Guillaume
2 changes: 1 addition & 1 deletion charts/k8s-gateway/values.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
image:
registry: ghcr.io
repository: pinax-network/k8s_gateway
tag: v0.5.0
tag: v0.6.0
pullPolicy: IfNotPresent

# Delegated domain
Expand Down
21 changes: 20 additions & 1 deletion kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,27 @@ func lookupIngressIndex(ctrl cache.SharedIndexInformer) func([]string) []interfa
return func(indexKeys []string) (result []interface{}) {
var objs []interface{}
for _, key := range indexKeys {
obj, _ := ctrl.GetIndexer().ByIndex(ingressHostnameIndex, strings.ToLower(key))
key := strings.ToLower(key)
// Ingress is not responsible for _acme-challenge.* FQDN
if strings.HasPrefix(key, "_acme-challenge.") {
continue
}

obj, _ := ctrl.GetIndexer().ByIndex(ingressHostnameIndex, key)
objs = append(objs, obj...)

log.Debugf("No exact matches found for %s, looking for wildcard ingress host", key)
for len(objs) == 0 {
_, after, found := strings.Cut(key, ".")
if !found {
// No more wildcard recursion
break
}
key = after
log.Debugf("Looking for *.%s", key)
obj, _ := ctrl.GetIndexer().ByIndex(ingressHostnameIndex, "*."+key)
objs = append(objs, obj...)
}
}
log.Debugf("Found %d matching Ingress objects", len(objs))
for _, obj := range objs {
Expand Down
25 changes: 25 additions & 0 deletions test/dual-stack/ingress-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,31 @@ spec:
port:
number: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-myservice-wildcard
namespace: default
annotations:
cert-manager.io/cluster-issuer: letsencrypt-dns-01
spec:
ingressClassName: nginx
rules:
- host: "*.myservice.foo.org"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: backend
port:
number: 80
tls:
- hosts:
- "*.myservice.foo.org"
secretName: ingress-wildcard-cert
---
apiVersion: v1
kind: Service
metadata:
Expand Down

0 comments on commit da3d1f3

Please sign in to comment.