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

fix(Traefik Proxy): missing IgnoreIngressRulesSpec check #5114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

linux2647
Copy link

Description

When setting the ingress-hostname-source annotation to annotation-only, ExternalDNS still inspects the IngressRoute spec for hostnames. This change adds a check for the IgnoreIngressRulesSpec configuration value and, if set to true, will skip inspecting the IngressRoute spec.

Checklist

  • Unit tests updated
  • End user documentation updated (not needed)

When setting the `ingress-hostname-source` annotation to
`annotation-only`, ExternalDNS still inspects the IngressRoute spec for
hostnames.  This commit adds a check for the `IgnoreIngressRulesSpec`
configuration value and, if set to true, will skip inspecting the
IngressRoute spec.
Copy link

linux-foundation-easycla bot commented Feb 21, 2025

CLA Signed


The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign raffo for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Feb 21, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @linux2647!

It looks like this is your first PR to kubernetes-sigs/external-dns 🎉. 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-sigs/external-dns 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 the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 21, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @linux2647. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 21, 2025
@ivankatliarchuk
Copy link
Contributor

/ok-to-test

@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 Feb 22, 2025
@ivankatliarchuk
Copy link
Contributor

I have some concerns about this pull request. Could you please explain how you identified the underlying issue? Also, could you provide the Kubernetes manifests we need to reproduce and validate the issue?

@mloiseleur
Copy link
Contributor

mloiseleur commented Feb 23, 2025

@linux2647 Would you please complete documentation on Traefik proxy source with this possibility ?

@linux2647
Copy link
Author

I have some concerns about this pull request. Could you please explain how you identified the underlying issue? Also, could you provide the Kubernetes manifests we need to reproduce and validate the issue?

Yeah. I have a few apps that are independently deployed, but share a common hostname. I want to have the shared hostname to be managed by a Traefik IngressRoute independent of any of the apps hosted on it. That way, any ExternalDNS configuration on an app's IngressRoute doesn't clobber the shared hostname. Something like:

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: test-app
  annotations:
    external-dns.alpha.kubernetes.io/hostname: test-app.prod.example.com
    external-dns.alpha.kubernetes.io/ingress-hostname-source: annotation-only
spec:
  entryPoints:
    - websecure
  routes:
    - match: (Host(`shared-app.prod.example.com`) && PathPrefix(`/test-app`)) || Host(`test-app.prod.example.com`)
      kind: Rule
      services:
        - kind: Service
          name: hello-kubernetes-svc

What I want is for test-app to only manage DNS for test-app.prod.example.com. However, it's also trying to manage DNS for shared-app.prod.example.com because ExternalDNS is inspecting both the annotations and the spec, and it isn't respecting the ingress-hostname-source annotation when it's set to annotation-only.

@linux2647
Copy link
Author

Would you please complete documentation on Traefik proxy source with this possibility ?

@mloiseleur I can, but this is covered by ExternalDNS's documentation on annotations, so it doesn't feel like something that's Traefik specific. To me, it feels like a bug that needs fixing.

@mloiseleur
Copy link
Contributor

ExternalDNS's documentation on annotations says:

Specifies where to get the domain for an Ingress resource.

It does not speak about IngressRoute (or even HTTPRoute). Or did I miss something ?

@mloiseleur
Copy link
Contributor

/retitle fix(Traefik Proxy): missing IgnoreIngressRulesSpec check

@k8s-ci-robot k8s-ci-robot changed the title Fix missing IgnoreIngressRulesSpec check for Traefik proxy fix(Traefik Proxy): missing IgnoreIngressRulesSpec check Feb 25, 2025
Comment on lines +685 to +696
for _, route := range ingressRoute.Spec.Routes {
match := route.Match

for _, hostEntry := range traefikHostExtractor.FindAllString(match, -1) {
for _, host := range traefikValueProcessor.FindAllString(hostEntry, -1) {
host = strings.TrimPrefix(host, "`")
host = strings.TrimSuffix(host, "`")
for _, hostEntry := range traefikHostExtractor.FindAllString(match, -1) {
for _, host := range traefikValueProcessor.FindAllString(hostEntry, -1) {
host = strings.TrimPrefix(host, "`")
host = strings.TrimSuffix(host, "`")

// Checking for host = * is required, as Host(`*`) can be set
if host != "*" && host != "" {
endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...)
// Checking for host = * is required, as Host(`*`) can be set
if host != "*" && host != "" {
endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...)
}
Copy link
Contributor

@ivankatliarchuk ivankatliarchuk Feb 25, 2025

Choose a reason for hiding this comment

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

this looks edentical to lines 723-735. Could we have a private method for that as well?

Most likely not part of this change, but I leave it to you to decide, if what I'll open a pull request.

There are triple nested looping

The time complexity of the selected code is O(n * m * k), where:

  • n is the number of routes in ingressRoute.Spec.Routes.
  • m is the number of matches found by traefikHostExtractor.FindAllString.
  • k is the number of hosts found by traefikValueProcessor.FindAllString.
    This is because the code iterates over each route, then for each route, it iterates over each match found, and for each match, it iterates over each host found.

it would be desirable to have something like that

var hosts []string
for _, route := range ingressRoute.Spec.Routes {
	match := route.Match
	h := traefikHostExtractor.FindAllString(match, -1)
	hosts = append(hosts, h...)
}

var processedHosts []string
for _, entry := range hosts {
	pHosts := traefikValueProcessor.FindAllString(entry, -1)
	processedHosts = append(processedHosts, pHosts...)
}
for _, host := range processedHosts {
	host = strings.Trim(host, "`")
	if host != "*" && host != "" {
		endpoints = append(endpoints, endpointsForHostname(host, targets, ttl, providerSpecific, setIdentifier, resource)...)
	}
}

aka time complexity of O(n + m + p) same as O(n) vs O(n * m * p)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants