Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubernetes Ingress pathType should be configurable without an additonal quarkus.kubernetes.ingress.rules rule #43783

Open
ThoSap opened this issue Oct 9, 2024 · 3 comments
Labels
area/kubernetes kind/bug Something isn't working

Comments

@ThoSap
Copy link

ThoSap commented Oct 9, 2024

Describe the bug

@Sgitario @geoand @iocanel as a continuation of #26747 and with the Kubernetes NGINX Ingress versions >= 1.8.0 warning networking.k8s.io.ingress Creation Warning -> 299 - path /something(/|$)(.*) cannot be used with pathType Prefix when a rewrite is used, it is important that the pathType of the default generated ingress is configurable.

# One of Prefix (default), Exact or ImplementationSpecific
quarkus.kubernetes.ports.http.path-type

https://github.com/kubernetes/ingress-nginx/releases/tag/controller-v1.8.0
https://kubernetes.github.io/ingress-nginx/faq/#validation-of-path
kubernetes/ingress-nginx#11819
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#strict-validate-path-type
Image

I know the following example rewrite does not make sense to you as one could use quarkus.http.root-path, quarkus.http.non-application-root-path, and quarkus.rest.path, but I have a valid use case for a legacy application where I need this rewrite.
The warning will not appear by correctly setting the pathType to ImplementationSpecific using Kubernetes NGINX Ingress versions >= 1.8.0.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /api/$2
  name: my-api
  namespace: my-namespace
spec:
  ingressClassName: nginx
  rules:
    - host: app.example.com
      http:
        paths:
          - backend:
              service:
                name: my-api
                port:
                  number: 8080
            path: /something(/|$)(.*)
            pathType: ImplementationSpecific
  tls:
    - hosts:
        - app.example.com
      secretName: my-certificate

Expected behavior

The developer should be able to configure the default generated ingress pathType using the new configuration property quarkus.kubernetes.ports.http.path-type.

Actual behavior

Currently, it is not possible to configure the generated pathType for the default generated ingress.
It is only possible using an additional rule where one would need to create a dummy path for the default generated ingress rule, and then we need to duplicate configuration option values.

quarkus.kubernetes.ingress.expose=true
# To change the Ingress host. By default, it's empty.
quarkus.kubernetes.ingress.host=prod.svc.url
# Kuberntes NGINX Ingress rewrite annotation
quarkus.kubernetes.ingress.annotations."nginx.ingress.kubernetes.io/rewrite-target"=/api/$2
# To change the Ingress path of the generated Ingress rule. By default, it's "/".
# We must use a dummy here so we don't duplicate the path in the additional rule
quarkus.kubernetes.ports.http.path=/_dummy

quarkus.kubernetes.ingress.rules.1.host=prod.svc.url
quarkus.kubernetes.ingress.rules.1.path=/something(/|$)(.*)
quarkus.kubernetes.ingress.rules.1.path-type=ImplementationSpecific
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    app.kubernetes.io/version: 2.12.9
    app.quarkus.io/quarkus-version: 3.15.1
    app.quarkus.io/build-timestamp: 2024-10-09 - 12:26:48 +0000
    nginx.ingress.kubernetes.io/rewrite-target: /api/$2
  labels:
    app.kubernetes.io/name: my-api
    app.kubernetes.io/version: 2.12.9
    app.kubernetes.io/managed-by: quarkus
  name: my-api
  namespace: my-namespace
spec:
  rules:
    - host: app.example.com
      http:
        paths:
          - backend:
              service:
                name: my-api
                port:
                  name: http
            path: /something(/|$)(.*)
            pathType: ImplementationSpecific
          - backend:
              service:
                name: my-api
                port:
                  name: http
            path: /_dummy
            pathType: Prefix
  tls:
    - hosts:
        - app.example.com
      secretName: my-certificate

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

Java(TM) SE Runtime Environment Oracle GraalVM 21.0.4+8.1 (build 21.0.4+8-LTS-jvmci-23.1-b41)

Quarkus version or git rev

3.15.1

Build tool (ie. output of mvnw --version or gradlew --version)

8.10.2

Additional information

No response

@ThoSap ThoSap added the kind/bug Something isn't working label Oct 9, 2024
Copy link

quarkus-bot bot commented Oct 9, 2024

/cc @geoand (kubernetes), @iocanel (kubernetes), @radcortez (config)

@ThoSap ThoSap changed the title Kubernetes Ingress pathType should be configurable without an additonal quarkus.kubernetes.ingress.rules Role Kubernetes Ingress pathType should be configurable without an additonal quarkus.kubernetes.ingress.rules Rule Oct 9, 2024
@ThoSap ThoSap changed the title Kubernetes Ingress pathType should be configurable without an additonal quarkus.kubernetes.ingress.rules Rule Kubernetes Ingress pathType should be configurable without an additonal quarkus.kubernetes.ingress.rules rule Oct 9, 2024
@ThoSap
Copy link
Author

ThoSap commented Oct 9, 2024

We need the dummy rule as shown above in the actual behavior section, as updating the existing rule does not work when we set the additional rule with the same path and host but a different path-type value than Prefix.

See the integrations test (path-type was left out here):
https://github.com/quarkusio/quarkus/blob/3.15.1/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithIngressRulesTest.java#L81-L88
https://github.com/quarkusio/quarkus/blob/3.15.1/integration-tests/kubernetes/quarkus-standard-way/src/test/resources/kubernetes-with-ingress-rules.properties#L5-L7

This example

quarkus.kubernetes.ingress.expose=true
quarkus.kubernetes.ingress.host=prod.svc.url
quarkus.kubernetes.ingress.annotations."nginx.ingress.kubernetes.io/rewrite-target"=/api/$2
quarkus.kubernetes.ports.http.path=/something(/|$)(.*)

quarkus.kubernetes.ingress.rules.0.host=prod.svc.url
quarkus.kubernetes.ingress.rules.0.path=/something(/|$)(.*)
quarkus.kubernetes.ingress.rules.0.path-type=ImplementationSpecific

generates the following ingress with a duplicate path:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    app.kubernetes.io/version: 2.12.9
    app.quarkus.io/quarkus-version: 3.15.1
    app.quarkus.io/build-timestamp: 2024-10-09 - 12:58:17 +0000
    nginx.ingress.kubernetes.io/rewrite-target: /api/$2
  labels:
    app.kubernetes.io/name: my-api
    app.kubernetes.io/version: 2.12.9
    app.kubernetes.io/managed-by: quarkus
  name: my-api
  namespace: my-namespace
spec:
  rules:
    - host: app.example.com
      http:
        paths:
          - backend:
              service:
                name: my-api
                port:
                  name: http
            path: /something(/|$)(.*)
            pathType: ImplementationSpecific
          - backend:
              service:
                name: my-api
                port:
                  name: http
            path: /something(/|$)(.*)
            pathType: Prefix
  tls:
    - hosts:
        - app.example.com
      secretName: my-certificate

@geoand
Copy link
Contributor

geoand commented Oct 14, 2024

I'll leave this to @iocanel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubernetes kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants