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

add tooling to convert endpoints to a tree and back #266

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

philbrookes
Copy link
Contributor

add tooling to convert endpoints to a tree and back

@maleck13
Copy link
Contributor

@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

@maksymvavilov
Copy link
Contributor

@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

safeguarded all public calls from nil pointers

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 {
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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

// 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 {
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

good catch. Thanks. Fixed

}

// no children means this is pointing to an IP or a host outside of the DNS Record
if len(node.Children) == 0 {
Copy link
Contributor

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

Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor

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"

Copy link
Contributor

@maleck13 maleck13 left a 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>
@maksymvavilov maksymvavilov added this pull request to the merge queue Oct 23, 2024
Merged via the queue into Kuadrant:main with commit 0ed8ff6 Oct 23, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants