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

feat(trait): add support for multiple ingress paths #5996

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cfitzw
Copy link
Contributor

@cfitzw cfitzw commented Dec 13, 2024

Related to issue #5981.

  • Allow multiple paths to be set within an ingress.
  • Implement a workaround to allow backward compatibility for ingress.path.
  • Determine if the IngressTrait should be migrated towards adopting K8s API IngressSpec hierarchy.
    Can be reviewed again at a later point in time/in a separate PR.

Example usage:

build/_output/bin/kamel-amd64 run test/src/multi-path.yml -o yaml --trait ingress.paths="/api/v1/multi" --trait ingress.paths="/api/v1/path" > test/base/multi-path.yml

... generates:

apiVersion: camel.apache.org/v1
kind: Integration
metadata:
  annotations:
    camel.apache.org/operator.id: camel-k
  creationTimestamp: null
  name: multi-path
spec:
  flows:
  - from:
      steps:
      - set-header:
          name: Content-Type
          simple: application/json
      - set-body:
          constant: '{"welcome": "multi"}'
      uri: rest:get:/api/v1/multi
  - from:
      steps:
      - set-header:
          name: Content-Type
          simple: application/json
      - set-body:
          constant: '{"welcome": "path"}'
      uri: rest:get:/api/v1/path
  traits:
    ingress:
      paths: 
        - /api/v1/multi
        - /api/v1/path
status: {}

Output of ingress (kubectl get ingress multi-path -o yaml):

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  creationTimestamp: "2024-12-13T15:21:34Z"
  generation: 1
  labels:
    camel.apache.org/generation: "1"
    camel.apache.org/integration: multi-path
  name: multi-path
  namespace: default
  ownerReferences:
  - apiVersion: camel.apache.org/v1
    blockOwnerDeletion: true
    controller: true
    kind: Integration
    name: multi-path
    uid: eb44c65f-3dca-49e5-a368-1ba8946fc3ee
  resourceVersion: "97865"
  uid: bc5651de-87a5-40d7-be30-9375c98dfb61
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - backend:
          service:
            name: multi-path
            port:
              name: http
        path: /api/v1/multi
        pathType: Prefix
      - backend:
          service:
            name: multi-path
            port:
              name: http
        path: /api/v1/path
        pathType: Prefix
status:
  loadBalancer:
    ingress:
    - ip: 192.168.49.2

Curl Output:

curl 192.168.49.2/api/v1/multi
{"welcome": "multi"}

curl 192.168.49.2/api/v1/path
{"welcome": "path"}

@cfitzw cfitzw changed the title ingress improvements feat(trait): ingress improvements Dec 13, 2024
Copy link
Contributor

✔️ Unit test coverage report - coverage increased from 47.2% to 47.3% (+0.1%)

Copy link
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

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

Nice stuff, thanks! As mentioned in the issue, to avoid breaking compatibility you can keep the path logic and additionally include a paths with the logic you're willing to implement.

@cfitzw cfitzw force-pushed the feat-ingress-improvements branch from 23532bd to 8d2f4f5 Compare December 16, 2024 17:13
@cfitzw
Copy link
Contributor Author

cfitzw commented Dec 16, 2024

@squakez - I've now added paths and kept path with deprecated notices. The code will now continue to support the existing path convention.

I could use some assistance on implementing some sort of error handling so that if both path and paths traits exist, that an error is thrown. Right now I have it coded to take only the path and ignore paths when this scenario exists.
I've now just added another small commit (+test) to allow both the path and paths fields to be able to co-exist.

@cfitzw cfitzw changed the title feat(trait): ingress improvements feat(trait): add support for multiple ingress paths Dec 16, 2024
@cfitzw cfitzw marked this pull request as ready for review December 16, 2024 18:03
Copy link
Contributor

⚠️ Unit test coverage report - coverage decreased from 47.6% to 47.3% (-0.3%)

Copy link
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

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

Nice work, thanks! If you can give another shot and add a deprecation warning notice in the Integration condition it would be great.

@squakez
Copy link
Contributor

squakez commented Dec 18, 2024

I forgot to add a link to some example you can use for the warning notice:

condition := t.adaptDeprecatedFields()

@cfitzw
Copy link
Contributor Author

cfitzw commented Dec 18, 2024

Excellent - thank you for the example. I'll work to get this added in the coming days.

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

Successfully merging this pull request may close these issues.

2 participants