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 default tll for record #173

Merged
merged 14 commits into from
Jan 21, 2025

Conversation

nobleess
Copy link
Contributor

No description provided.

@mircea-pavel-anton
Copy link
Collaborator

Hi, @nobleess, and thank you for your contribution!

I think the default TTL should somehow be configurable via env vars by the user. When you deploy the webhook to your cluster, there should be some configurable option to set it.
What do you think?

I'm currently on my phone so I haven't looked at the code much, but I'll try to get to it tomorrow.

@mr-borboto mr-borboto bot added size/S and removed size/M labels Jan 16, 2025
@nobleess nobleess force-pushed the feat/DefaultTTL branch 2 times, most recently from 25828b4 to 99e42b6 Compare January 16, 2025 19:43
@nobleess
Copy link
Contributor Author

@mircea-pavel-anton I agree with you. I watched how it was implemented in aws.go and tried to repeat solution here.

Copy link
Collaborator

@mircea-pavel-anton mircea-pavel-anton left a comment

Choose a reason for hiding this comment

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

Overall I think this is exactly what we need, just some nitpicks on the code structure 😅

internal/configuration/configuration.go Outdated Show resolved Hide resolved
internal/mikrotik/provider.go Outdated Show resolved Hide resolved
internal/dnsprovider/dnsprovider.go Outdated Show resolved Hide resolved
@mircea-pavel-anton mircea-pavel-anton changed the title add default tll for record feat: Add default tll for record Jan 16, 2025
@mircea-pavel-anton
Copy link
Collaborator

Also, some documentation change would also be nice for this. We can add a new section under ⚙️ Configuration Options called Default Values for RouterOS Records and document the env var there

@mr-borboto mr-borboto bot added size/M and removed size/S labels Jan 16, 2025
@mircea-pavel-anton
Copy link
Collaborator

also, CI is failing because of missing bot app credentials, but that is expected.

You can lint your go code using task go:lint and run the unit tests using task go:test. I think the tests will also have to be updated sadly

@mircea-pavel-anton
Copy link
Collaborator

I updated the workflows so they can run on forks as well and rebased this branch to get that update. All workflows seem to pass now

README.md Outdated Show resolved Hide resolved
example/values.yaml Outdated Show resolved Hide resolved
internal/mikrotik/provider_test.go Outdated Show resolved Hide resolved
internal/mikrotik/provider_test.go Outdated Show resolved Hide resolved
Comment on lines 173 to 213
for _, create := range changes.Create {
if !create.RecordTTL.IsConfigured() {
create.RecordTTL = endpoint.TTL(p.client.TTL)
newChanges.Create = append(newChanges.Create, create)
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I found a new issue here. The check and enforcement of the default ttl is currently only done on record creation. This means that external DNS will create the record with the default ttl correctly, but then at the next loop it will update it back to 0. We should probably do a similar check for updating records

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, when we are initializing newChanges a few lines up, we're setting newChanges.Create = changes.Create. This causes the entire list to be duplicated. We need to set:

	newChanges := &plan.Changes{
		Create:    []*endpoint.Endpoint{},
		Delete:    changes.Delete,
		UpdateOld: []*endpoint.Endpoint{},
		UpdateNew: []*endpoint.Endpoint{},
	}

Copy link
Collaborator

@mircea-pavel-anton mircea-pavel-anton left a comment

Choose a reason for hiding this comment

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

This all looks good. Now we just need to fix the issue of injecting the default TTL in updates as well.

Basically the behavior I am seeing right now is that when I create a new record it does get the default TTL set, but then on the next reconciliation loop, it gets set back to 0.

I am not entirely sure where/how to address this. Perhaps in isEndpointMatching? I'll see if I can think of something too

@mircea-pavel-anton
Copy link
Collaborator

I played around a bit with the issue on a different branch and I think I got a working proof of concept: https://github.com/mirceanton/external-dns-provider-mikrotik/tree/local-test

I haven't tested this extensively, but so far it seems to work. Feel free to adapt any of that code if you think it fits

The tests would also need to be updated. Let me know if you can/want to look into that 😁

@mircea-pavel-anton
Copy link
Collaborator

@nobleess that extra condition for the TTLs makes sure that we can also update to/from default ttl from/to other values.

For example, without it we would not be able to update from a TTL of 5s to default TTL and vice versa.

See here some example tests: https://github.com/mirceanton/external-dns-provider-mikrotik/blob/local-test/internal/mikrotik/provider_test.go#L605-L697

@mircea-pavel-anton
Copy link
Collaborator

@nobleess is this ready for review?

Copy link
Collaborator

@mircea-pavel-anton mircea-pavel-anton left a comment

Choose a reason for hiding this comment

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

looks good!

@mircea-pavel-anton mircea-pavel-anton merged commit 213a25d into mirceanton:main Jan 21, 2025
9 checks passed
@mr-borboto
Copy link
Contributor

mr-borboto bot commented Jan 21, 2025

🎉 This PR is included in version 1.3.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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.

2 participants