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: add new flags to allow migration of OwnerID #4823

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

troll-os
Copy link

@troll-os troll-os commented Oct 22, 2024

Description

This pull requests aims to complete the work initiated in these PR : #2466 and #3631

Most credits go to the creators of the initial work, as I mostly just rebased their work on the current state of master

Initial PR description:

When changing --txt-owner-id on an existing external-dns resource, it does not update the existing TXT records it owns, therefore losing ownership. Meaning that we have to manually delete the records in order to have external-dns take ownership again.
To solve this problem, I added the ability to update the original txt-owner by setting -- migrate-txt-owner to overwrite the old txt-owner. I have successfully modified thousands of pieces of data using this code, so far without any bugs

As for me I've successfully managed records without any issue using the newly added flags on the OVH provider
If anyone is willing to try these changes on other providers I'd be happy to troubleshoot their issues

Regarding the documentation I'm not sure either in which category these changes are relevant, so taking any recommendations on that

Note: this is my first contribution to such a project and first time using Go aswell, I've went through the contribution guidelines but if I missed something please let me know so that I can fix it

Fixes #2036

Checklist

  • Unit tests updated
  • End user documentation updated

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 22, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @troll-os!

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 Oct 22, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @troll-os. 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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 22, 2024
@troll-os troll-os changed the title Add new flags to allow migration of OwnerID feat: add new flags to allow migration of OwnerID Oct 22, 2024
@mloiseleur
Copy link
Contributor

Thanks @troll-os. It looks good.
Would you please add some documentation on it ?

@troll-os
Copy link
Author

@mloiseleur Sure !

Where do you think it would fit the best? TXT registry ?

provider/ovh/ovh.go Outdated Show resolved Hide resolved
@mloiseleur
Copy link
Contributor

With this PR, it works only with TXT registry, so yes.

@mloiseleur
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 Oct 28, 2024
@mloiseleur
Copy link
Contributor

/lgtm

/assign @Raffo

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 28, 2024
plan/plan.go Outdated Show resolved Hide resolved
controller/controller.go Outdated Show resolved Hide resolved
Comment on lines +259 to +262
if im.isMigrationEnabled {
filteredChanges.UpdateOld = append(filteredChanges.UpdateOld, endpoint.FilterEndpointsByOwnerID(im.oldOwnerID, changes.UpdateOld)...)
filteredChanges.Delete = append(filteredChanges.Delete, endpoint.FilterEndpointsByOwnerID(im.oldOwnerID, changes.Delete)...)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain the purpose of those lines?

Copy link
Author

Choose a reason for hiding this comment

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

We want to apply the changes which should include the deletion of the old entries in the registry, otherwise we're left we unmanaged and unwanted records

@Raffo
Copy link
Contributor

Raffo commented Oct 29, 2024

@troll-os answered to your comments. Could you please also provide a way to test this manually with manifests and kubectl commands? I would be eager to verify myself that the migration works and then keep an end to end test around.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 29, 2024
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@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 ask for approval from mloiseleur. For more information see the Kubernetes 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 size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 29, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 29, 2024
@troll-os
Copy link
Author

So I had to make a change for the OVH provider to ensure record targets are properly formatted, I ran another batch of test to migrate from the default owner and for some reason, records returned by the OVH API don't have their targets formatted like ExternalDNS expects

Meaning that we couldn't map the record ID and the deletion would fail

I don't know why this happens on a specific zones, the other zones covered seem fine... When I make direct calls to the OVH API the formatting is good...

I didn't forget your query for manifests to tests the changes @Raffo, I'll make them ASAP

@troll-os
Copy link
Author

So I did a little of homework and made this work with Gandi with a domain I own for personal use and minikube

Steps used to reproduce on another setup than my work dev and prod environments :

  1. make build on the branch of this PR (eventually push to a repo you own)
  2. Setup Minikube with Docker
  3. minikube enable addons ingress
  4. Use following manifests (update variables to ensure your tests cases):
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  annotations:
    external-dns.alpha.kubernetes.io/hostname: helloworld.whatever.tld
spec:
  selector:
    app: nginx
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx
spec:
  ingressClassName: nginx
  rules:
  - host: helloworld.whatever.tld
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
           name: nginx
           port:
             number: 80
apiVersion: apps/v1
kind: Deployment
metadata:
  name: external-dns
spec:
  replicas: 1
  selector:
    matchLabels:
      app: external-dns
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: external-dns
    spec:
      containers:
      - name: external-dns
        image: yourRegistry.com/external-dns:v-someBuildNumber  # <<<<<<<<<<<<
        args:
        - "--txt-prefix=%{record_type}-"
        - "--txt-cache-interval=15m"
        - "--log-level=info"
        - "--log-format=text"
        - "--txt-owner-id=old-owner"
        - "--policy=sync"
        - "--provider=youDecide" # <<<<<<<<<<<<<<<<
        - "--registry=txt"
        - "--interval=1m"
        - "--domain-filter=whatever.tld"
        - "--source=ingress"
        env:
        - name: whatever_env_var_provider_needs
          value: "hello"
  1. Check your records, the A and TXT should be there, owned by "old-owner"
  2. Apply following manifest to make migration :
apiVersion: apps/v1
kind: Deployment
metadata:
  name: external-dns
spec:
  replicas: 1
  selector:
    matchLabels:
      app: external-dns
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: external-dns
    spec:
      containers:
      - name: external-dns
        image: yourRegistry.com/external-dns:v-someBuildNumber  # <<<<<<<<<<<<
        args:
        - "--txt-prefix=%{record_type}-"
        - "--txt-cache-interval=15m"
        - "--log-level=info"
        - "--log-format=text"
        - "--txt-owner-id=new-owner"
        - "--from-txt-owner=old-owner"
        - "--migrate-txt-owner"
        - "--policy=sync"
        - "--provider=youDecide" # <<<<<<<<<<<<
        - "--registry=txt"
        - "--interval=1m"
        - "--domain-filter=whatever.tld"
        - "--source=ingress"
        env:
        - name: whatever_env_var_provider_needs
          value: "hello"
  1. Check TXT record again, everything should be up to date

@troll-os
Copy link
Author

Also I tried to follow the CoreDNS setup from the external-dns docs to have a non "external" provider dependent way to tests but didn't manage to make it work for some reason and I didn't want to spend too much time on it (probably a minikube issue) knowing that it worked with a classic provider

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.

update TXT records with new owner on changing --txt-owner-id
4 participants