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

Allow configuring Ingress rules #28813

Merged
merged 1 commit into from
Oct 26, 2022
Merged

Allow configuring Ingress rules #28813

merged 1 commit into from
Oct 26, 2022

Conversation

Sgitario
Copy link
Contributor

These changes also ensures that not duplicated ingress rules are generated.

Adding Ingress rules

To customize the default host and path properties of the generated Ingress resources, you need to apply the following configuration:

quarkus.kubernetes.ingress.expose=true
# To change the Ingress host. By default, it's empty.
quarkus.kubernetes.ingress.host=prod.svc.url
# To change the Ingress path of the generated Ingress rule. By default, it's "/".
quarkus.kubernetes.ports.http.path=/prod

This would generate the following Ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/name: kubernetes-with-ingress
    app.kubernetes.io/version: 0.1-SNAPSHOT
  name: kubernetes-with-ingress
spec:
  rules:
    - host: prod.svc.url
      http:
        paths:
          - backend:
              service:
                name: kubernetes-with-ingress
                port:
                  name: http
            path: /prod
            pathType: Prefix

Additionally, you can also add new Ingress rules by adding the following configuration:

# Example to add a new rule
quarkus.kubernetes.ingress.rules.1.host=dev.svc.url
quarkus.kubernetes.ingress.rules.1.path=/dev
quarkus.kubernetes.ingress.rules.1.path-type=ImplementationSpecific
# by default, path type is Prefix

# Exmple to add a new rule that use another service binding
quarkus.kubernetes.ingress.rules.2.host=alt.svc.url
quarkus.kubernetes.ingress.rules.2.path=/ea
quarkus.kubernetes.ingress.rules.2.service-name=updated-service
quarkus.kubernetes.ingress.rules.2.service-port-name=tcpurl

This would generate the following Ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/name: kubernetes-with-ingress
    app.kubernetes.io/version: 0.1-SNAPSHOT
  name: kubernetes-with-ingress
spec:
  rules:
    - host: prod.svc.url
      http:
        paths:
          - backend:
              service:
                name: kubernetes-with-ingress
                port:
                  name: http
            path: /prod
            pathType: Prefix
    - host: dev.svc.url
      http:
        paths:
          - backend:
              service:
                name: kubernetes-with-ingress
                port:
                  name: http
            path: /dev
            pathType: ImplementationSpecific
    - host: alt.svc.url
      http:
        paths:
          - backend:
              service:
                name: updated-service
                port:
                  name: tcpurl
            path: /ea
            pathType: Prefix

Fix #28812 Fix #26747

These changes also ensures that not duplicated ingress rules are generated.

#### Adding Ingress rules

To customize the default `host` and `path` properties of the generated Ingress resources, you need to apply the following configuration:

```
quarkus.kubernetes.ingress.expose=true
# To change the Ingress host. By default, it's empty.
quarkus.kubernetes.ingress.host=prod.svc.url
# To change the Ingress path of the generated Ingress rule. By default, it's "/".
quarkus.kubernetes.ports.http.path=/prod
```

This would generate the following Ingress resource:

```yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/name: kubernetes-with-ingress
    app.kubernetes.io/version: 0.1-SNAPSHOT
  name: kubernetes-with-ingress
spec:
  rules:
    - host: prod.svc.url
      http:
        paths:
          - backend:
              service:
                name: kubernetes-with-ingress
                port:
                  name: http
            path: /prod
            pathType: Prefix
```

Additionally, you can also add new Ingress rules by adding the following configuration:

```
# Example to add a new rule
quarkus.kubernetes.ingress.rules.1.host=dev.svc.url
quarkus.kubernetes.ingress.rules.1.path=/dev
quarkus.kubernetes.ingress.rules.1.path-type=ImplementationSpecific
# by default, path type is Prefix

# Exmple to add a new rule that use another service binding
quarkus.kubernetes.ingress.rules.2.host=alt.svc.url
quarkus.kubernetes.ingress.rules.2.path=/ea
quarkus.kubernetes.ingress.rules.2.service-name=updated-service
quarkus.kubernetes.ingress.rules.2.service-port-name=tcpurl
```

This would generate the following Ingress resource:

```yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app.kubernetes.io/name: kubernetes-with-ingress
    app.kubernetes.io/version: 0.1-SNAPSHOT
  name: kubernetes-with-ingress
spec:
  rules:
    - host: prod.svc.url
      http:
        paths:
          - backend:
              service:
                name: kubernetes-with-ingress
                port:
                  name: http
            path: /prod
            pathType: Prefix
    - host: dev.svc.url
      http:
        paths:
          - backend:
              service:
                name: kubernetes-with-ingress
                port:
                  name: http
            path: /dev
            pathType: ImplementationSpecific
    - host: alt.svc.url
      http:
        paths:
          - backend:
              service:
                name: updated-service
                port:
                  name: tcpurl
            path: /ea
            pathType: Prefix
```

Fix quarkusio#28812
Fix quarkusio#26747
@Sgitario
Copy link
Contributor Author

cc @ThoSap @geoand
@gsmet this pull request fixes the regression issue: #28812

@geoand geoand requested a review from iocanel October 25, 2022 12:19
@geoand
Copy link
Contributor

geoand commented Oct 26, 2022

@iocanel can you review this?

Thanks

Copy link
Contributor

@iocanel iocanel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@geoand geoand merged commit 477e090 into quarkusio:main Oct 26, 2022
@quarkus-bot quarkus-bot bot added this to the 2.15 - main milestone Oct 26, 2022
@Sgitario Sgitario deleted the 26747 branch October 26, 2022 13:54
@gsmet gsmet modified the milestones: 2.15 - main, 2.14.0.Final Oct 28, 2022
@gsmet gsmet modified the milestones: 2.14.0.Final, 2.13.4.Final Oct 31, 2022
@gsmet gsmet modified the milestones: 2.13.4.Final, 2.14.0.Final Oct 31, 2022
@gsmet
Copy link
Member

gsmet commented Oct 31, 2022

@Sgitario I tried to backport this one to 2.13 but I get:

[ERROR] /data/home/gsmet/git/quarkus/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/ChangeIngressRuleDecorator.java:[5,37] cannot find symbol
[ERROR]   symbol:   class IngressRule
[ERROR]   location: package io.dekorate.kubernetes.config

so my guess is that the Dekorate version we have in 2.13 doesn't support this.

I put the backport label back for now, please remove it if this is confirmed.

@Sgitario
Copy link
Contributor Author

Sgitario commented Nov 2, 2022

Indeed, this is only for 2.14 as it depends on the latest Dekorate version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generated Ingress resource has duplicate paths elements Kubernetes Ingress path should be configurable
4 participants