-
Notifications
You must be signed in to change notification settings - Fork 10
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
add tooling to convert endpoints to a tree and back #266
Conversation
6c0b590
to
c0ff598
Compare
c0ff598
to
6aa9fd4
Compare
@maksymvavilov I think we should check for nils more aggressively and add some nil tests also as there are a lot of pointers and derefrencing pointers to get the value in here so could easilly end up with a panic |
6aa9fd4
to
35ca587
Compare
safeguarded all public calls from nil pointers |
35ca587
to
3272389
Compare
n.Children = append(n.Children[:i], n.Children[i+1:]...) | ||
|
||
// we removed child, but need to clean up data sets | ||
for j, dataset := range n.DataSets { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this looks fine but I am a bit confused as to why the data set isn't just attached to the node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have more datasets than nodes. For example, we can have 3 klb.testdomain.com
records that target two (eu.klb.testdomain.com
and us.klb.testdomain.com
) and by having 3 datasets we know to create 3 enpoints of klb.tesdomain.com
.
We could "push" datasets to the child (this will solve the need to search on removal) but we will end up with an intricate logic for converting them to endpoints: for each node, we will need to check each child for the number of datasets. And it doesn't look right to store in a child the data you need to convert the parent into the endpoint 🤔
here is what i mean:
endpoints := []externaldns.Endpoint{}
for _, child := range node.Children {
ToEndpoints(child, endpoints)
for _, dataSet := child.Datasets {
endpoints = append(endpoints, externaldnsEnpoints{
DNSName: node.Name
Targets: dataSet.Targets
.....
}
}
}
or something similar. Will have a Node that has dataset for it's parent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eh perhaps it is something we can do beyond this initial impl would rather get this in for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was suggested to use topology-like approach 🤔 we will definitely revisit it
internal/common/tree.go
Outdated
// we removed child, but need to clean up data sets | ||
for j, dataset := range n.DataSets { | ||
index := slices.Index(dataset.Targets, deleteNode.Name) | ||
if index > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the index is 0? should this be >=0 ? looks like index
will return -1 if not present
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. Thanks. Fixed
3272389
to
193fcdb
Compare
internal/common/tree.go
Outdated
} | ||
|
||
// no children means this is pointing to an IP or a host outside of the DNS Record | ||
if len(node.Children) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder would it read a little better if this check was done in a function name something like isFinalDNSEntry(node *DNSTreeNode)bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added isALeafNode()
func
ToEndpoints(child, endpoints) | ||
} | ||
|
||
if node.DataSets == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its not clear what node.DataSets being nil means here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a "prevent panic is the tree was created manually and with a mistake"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some minor things to consider but generally looks good
Signed-off-by: Maskym Vavilov <mvavilov@redhat.com>
193fcdb
to
294b24e
Compare
add tooling to convert endpoints to a tree and back