2

I'm creating Kubernetes Ingress resources for an nginx Ingress Controller. The paths that I'll be using have an ID that I need to extract into a variable that may be in a different location in the path. E.g.:

http://myservice/environment/<someenv>/room/<roomid>
http://myservice/join/<roomid>

If I use a non-named capture group in the regex then the first path roomid will be $2 and for the second it'll be $1. Ideally I would be able to use a named capture group to assign it to a specific variable that I can easily use but creating an Ingress with the following path with a named capture group results in an error

# ingresses.networking.k8s.io "nginx-consistent" was not valid:
# * spec.rules[0].http.paths[0].path: Invalid value: "/join/(?<roomid>.*)": must be a valid regex

Is there a supported way to use named capture groups?

The current configuration doesn't have much interesting in it. The following is a trimmed down config.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: {{.Release.Name}}-nginx-route-by-roomid
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/upstream-hash-by: "roomid-$roomid"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header ingress-handler nginx-route-by-roomid;
spec:
  rules:
    - http:
        paths:
          - backend:
              serviceName: {{ .Values.service.serviceName }}
              servicePort: {{ .Values.service.servicePort }}
            path: /api/v1/rooms/(?<roomid>[^/]*)
          - backend:
              serviceName: {{ .Values.service.serviceName }}
              servicePort: {{ .Values.service.servicePort }}
            path: /api/v1/players/([^/]*)/rooms/(?<roomid>[^/]*)
Ben Randall
  • 1,205
  • 10
  • 27

0 Answers0