kubeshop / kusk-gen

Kusk Gen generates Ingress-controller configurations from your OpenAPI definition
https://kubeshop.github.io/kusk-gen
MIT License
173 stars 12 forks source link

Literal Rewrite flag for Ingress Nginx #188

Open kylehodgetts opened 2 years ago

kylehodgetts commented 2 years ago

Is your feature request related to a problem? Please describe. Currently ingress nginx only supports the ability to trim a path prefix before passing the request onto the service. It would be nice to be able to completely rewrite the entire base path with a literal value before passing the request onto the service

how it compares to trim prefix Currently:

openapi: 3.0.1
x-kusk:
  namespace: my-namespace
  service:
    name: webapp
    namespace: my-service-namespace
    port: 7000
  path:
    base: /my-app
    trim_prefix: /my-app
paths:
  /:
    get: {}
...

will result in

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  creationTimestamp: null
  name: webapp-ingress
  namespace: my-namespace
spec:
  ingressClassName: nginx
  rules:
    - http:
        paths:
          - backend:
              service:
                name: webapp
                port:
                  number: 7000
            path: /my-app(/|$)(.*)
            pathType: Prefix
status:
  loadBalancer: {}

Rewrite with literal should look like this as per the documentation https://kubernetes.github.io/ingress-nginx/examples/rewrite/#app-root:

openapi: 3.0.1
x-kusk:
  namespace: my-namespace
  service:
    name: webapp
    namespace: my-service-namespace
    port: 7000
  path:
    base: /my-app
    rewrite_base: /other-app-path
paths:
  /:
    get: {}
...

which should result in the following:

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /my-other-app-path
  creationTimestamp: null
  name: webapp-ingress
  namespace: my-namespace
spec:
  ingressClassName: nginx
  rules:
    - http:
        paths:
          - backend:
              service:
                name: webapp
                port:
                  number: 7000
            path: /my-app
            pathType: Prefix
status:
  loadBalancer: {}