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

Chart: Add alias IngressClass resources. #10614

Closed

Conversation

slimm609
Copy link

@slimm609 slimm609 commented Nov 3, 2023

Add support for multiple ingress class names on a single controller

What this PR does / why we need it:

This allows supporting multiple ingress class names in a behind a single controller. The use case is that in production, there are multiple different ingress classes like internal and external. However, in limited development environments there is no "internal" vs "external" so this allows using a single controller for resource usage reductions and still provides the "look" of multiple ingress classes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • CVE Report (Scanner found CVE and adding report)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation only

How Has This Been Tested?

This was tested with nginx 1.9.3. The controller supports it but the helm chart did not.

ingress-ext-controller-86f58fdc98-vw6xk controller I1103 19:49:48.687926       7 store.go:440] "Found valid IngressClass" ingress="test/test-service1" ingressclass="nginx-ext"

ingress-ext-controller-86f58fdc98-vw6xk controller I1103 19:49:48.687398       7 store.go:440] "Found valid IngressClass" ingress="test/test-service2" ingressclass="nginx-int"

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added unit and/or e2e tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 3, 2023
Copy link

netlify bot commented Nov 3, 2023

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit 43fc43e
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/655238ccc84b7c0008aa1ee2

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Nov 3, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @slimm609!

It looks like this is your first PR to kubernetes/ingress-nginx 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/ingress-nginx has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Nov 3, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @slimm609. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-priority size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 3, 2023
@k8s-ci-robot k8s-ci-robot added the area/helm Issues or PRs related to helm charts label Nov 3, 2023
@slimm609
Copy link
Author

slimm609 commented Nov 3, 2023

cc: @rikatz

Copy link
Member

@Gacko Gacko left a comment

Choose a reason for hiding this comment

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

inb4: I'm just a regular contributor, so please don't get me wrong, I'm just asking questions which came into my mind when reading your PR and added some chances for improvement.

I basically like the idea of having multiple IngressClasses configured with one chart! What I'm not understanding is the need for the tplvalues.render template.

As far as I understand this complex bit of code, it's mostly used for templating some value - the commonLabels in this particular case - in a specific context defined by scope. Right now we are not making use of this and there are way easier approaches to do so.

What's wrong about just making ingressClassResource an array and iterate over it? Yes, it's breaking, but it's simple, clean and keeps the possibility of configuring IngressClasses separately, especially their parameters. Of course the controllerValue could not be part of the array then.

charts/ingress-nginx/templates/_helpers.tpl Outdated Show resolved Hide resolved
charts/ingress-nginx/templates/_params.tpl Outdated Show resolved Hide resolved
@slimm609 slimm609 force-pushed the support_multiple_ingress_names branch from 6c456df to ac09ec8 Compare November 6, 2023 14:18
@slimm609
Copy link
Author

slimm609 commented Nov 6, 2023

inb4: I'm just a regular contributor, so please don't get me wrong, I'm just asking questions which came into my mind when reading your PR and added some chances for improvement.

I basically like the idea of having multiple IngressClasses configured with one chart! What I'm not understanding is the need for the tplvalues.render template.

As far as I understand this complex bit of code, it's mostly used for templating some value - the commonLabels in this particular case - in a specific context defined by scope. Right now we are not making use of this and there are way easier approaches to do so.

What's wrong about just making ingressClassResource an array and iterate over it? Yes, it's breaking, but it's simple, clean and keeps the possibility of configuring IngressClasses separately, especially their parameters. Of course the controllerValue could not be part of the array then.

I was able to rework to avoid the template issue.

Switching to an array is a breaking change which I was trying to avoid as this likely won't be a common use-case. Contour supports the same thing in a similar way as well

@slimm609 slimm609 force-pushed the support_multiple_ingress_names branch from 7f802f2 to 47365b0 Compare November 6, 2023 14:59
@Gacko
Copy link
Member

Gacko commented Nov 6, 2023

Yes, sure, using an array would be breaking and I think the way you're implementing it right now is the best compromise.

Maybe this can be converted to an array in a later major release.

For now you could also just add a controller.extraIngressClassResources object array or just a controller.ingressClassResource.extraNames string array to prevent the string splitting and have the feature in a rather strictly typed schema.

WDYT?

@slimm609 slimm609 force-pushed the support_multiple_ingress_names branch 2 times, most recently from 7b9d1e9 to 5185d3e Compare November 6, 2023 18:25
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 6, 2023
@slimm609
Copy link
Author

slimm609 commented Nov 6, 2023

OK. Updated to use the values from extraNames. This also makes the "default" flag still explicit

---
# Source: ingress-nginx/templates/controller-ingressclass.yaml
# We don't support namespaced ingressClass yet
# So a ClusterRole and a ClusterRoleBinding is required
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
  labels:
    helm.sh/chart: ingress-nginx-4.8.3
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: test
    app.kubernetes.io/version: "1.9.4"
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: nginx
spec:
  controller: k8s.io/ingress-nginx
---
# Source: ingress-nginx/templates/controller-ingressclass.yaml
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
  labels:
    helm.sh/chart: ingress-nginx-4.8.3
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: test
    app.kubernetes.io/version: "1.9.4"
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: nginx-external
spec:
  controller: k8s.io/ingress-nginx
---
# Source: ingress-nginx/templates/controller-ingressclass.yaml
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
  labels:
    helm.sh/chart: ingress-nginx-4.8.3
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: test
    app.kubernetes.io/version: "1.9.4"
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: test2
spec:
  controller: k8s.io/ingress-nginx
---

@slimm609 slimm609 force-pushed the support_multiple_ingress_names branch 2 times, most recently from 592df29 to cdff263 Compare November 6, 2023 18:29
@slimm609
Copy link
Author

slimm609 commented Nov 7, 2023

@tao12345666333 this should be ready to go now

@rikatz
Copy link
Contributor

rikatz commented Nov 7, 2023

/ok-to-test

@Gacko as you've been also helping on this review, is this fine for you?

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 7, 2023
Signed-off-by: slimm609 <dbrian@vmware.com>
@slimm609 slimm609 force-pushed the support_multiple_ingress_names branch from cdff263 to 2383f63 Compare November 13, 2023 14:53
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 13, 2023
- change to support extraNames instead of splitting string

Signed-off-by: slimm609 <dbrian@vmware.com>
@slimm609 slimm609 force-pushed the support_multiple_ingress_names branch from 2383f63 to 43fc43e Compare November 13, 2023 14:55
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 13, 2023
@slimm609
Copy link
Author

also please add a test case for that

@cpanato Do you have a reference of where there is a test case for the existing ingressClass?

@Gacko
Copy link
Member

Gacko commented Nov 24, 2023

/assign

@Gacko
Copy link
Member

Gacko commented Nov 29, 2023

Regarding the tests: Have a look into this directory. This manifest could be a good starting point.

I know we already changed the name of the property once. But what do you think about aliases instead of extraNames? This is just a suggestion, I'm fine with both of them.

Regarding the new IngressClass manifest: Could we either name it controller-ingressclass-aliases.yaml or controller-extra-ingressclasses.yaml (mind the dash) instead of controller-extraingressclass.yaml then?

@@ -0,0 +1,18 @@
{{- if and (.Values.controller.ingressClassResource.enabled) (.Values.controller.ingressClassResource.extraNames) -}}
Copy link
Member

@Gacko Gacko Dec 5, 2023

Choose a reason for hiding this comment

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

Suggested change
{{- if and (.Values.controller.ingressClassResource.enabled) (.Values.controller.ingressClassResource.extraNames) -}}
{{- if and .Values.controller.ingressClassResource.enabled .Values.controller.ingressClassResource.aliases -}}

Copy link
Member

@Gacko Gacko left a comment

Choose a reason for hiding this comment

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

Left a last bunch of suggestions. If you agree on naming the new variable aliases, please also rename the controller-extraingressclass.yaml to controller-ingressclass-aliases.yaml. That would be nice! Apart from that we should be ready to merge. 🙂

Comment on lines +127 to +128
# -- Additional ingressClass names
extraNames: []
Copy link
Member

@Gacko Gacko Dec 13, 2023

Choose a reason for hiding this comment

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

Suggested change
# -- Additional ingressClass names
extraNames: []
# -- Aliases for the ingressClass
aliases: []

@@ -331,6 +331,7 @@ As of version `1.26.0` of this chart, by simply not providing any clusterIP valu
| controller.ingressClassResource.controllerValue | string | `"k8s.io/ingress-nginx"` | Controller-value of the controller that is processing this ingressClass |
| controller.ingressClassResource.default | bool | `false` | Is this the default ingressClass for the cluster |
| controller.ingressClassResource.enabled | bool | `true` | Is this ingressClass enabled or not |
| controller.ingressClassResource.extraNames | list | `[]` | Additional ingressClass names |
Copy link
Member

@Gacko Gacko Dec 13, 2023

Choose a reason for hiding this comment

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

Suggested change
| controller.ingressClassResource.extraNames | list | `[]` | Additional ingressClass names |
| controller.ingressClassResource.aliases | list | `[]` | Aliases for the ingressClass |

You probably need to re-run helm-docs here.

@@ -0,0 +1,18 @@
{{- if and (.Values.controller.ingressClassResource.enabled) (.Values.controller.ingressClassResource.extraNames) -}}
{{- range $v := .Values.controller.ingressClassResource.extraNames }}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{{- range $v := .Values.controller.ingressClassResource.extraNames }}
{{- range $v := .Values.controller.ingressClassResource.aliases }}

@Gacko
Copy link
Member

Gacko commented Dec 13, 2023

/kind feature
/priority backlog
/triage accepted
/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Dec 13, 2023
@k8s-ci-robot k8s-ci-robot changed the title feat: add support for multiple ingress class names Chart: Add IngressClass aliases. Feb 1, 2024
@Gacko
Copy link
Member

Gacko commented Feb 1, 2024

/retitle Chart: Add alias IngressClass resources.

@k8s-ci-robot k8s-ci-robot changed the title Chart: Add IngressClass aliases. Chart: Add alias IngressClass resources. Feb 1, 2024
@Gacko
Copy link
Member

Gacko commented Mar 12, 2024

Closing this in favor of #11109.

/close

@k8s-ci-robot
Copy link
Contributor

@Gacko: Closed this PR.

In response to this:

Closing this in favor of #11109.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/helm Issues or PRs related to helm charts cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/feature Categorizes issue or PR as related to a new feature. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants