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

Host resolving to multiple A records is constantly reordered #83

Open
tenstad opened this issue Oct 24, 2024 · 1 comment
Open

Host resolving to multiple A records is constantly reordered #83

tenstad opened this issue Oct 24, 2024 · 1 comment

Comments

@tenstad
Copy link

tenstad commented Oct 24, 2024

e, _, err := c.Exchange(m, "["+ns[0]+"]:53")
if err != nil {
log.Error(err, "unable to resolve "+f)
continue
}
if len(e.Answer) == 0 {
log.V(1).Info("could not find A record for " + f)
}
for _, ans := range e.Answer {
if t, ok := ans.(*dns.A); ok {
// Adding a peer per answer
peers = append(peers, networking.NetworkPolicyPeer{
IPBlock: &networking.IPBlock{CIDR: t.A.String() + "/32"}})
// We want the next sync for the FQDNNetworkPolicy to happen
// just after the TTL of the DNS record has expired.
// Because a single FQDNNetworkPolicy may have different DNS
// records with different TTLs, we pick the lowest one
// and resynchronise after that.
if ans.Header().Ttl < nextSync {
nextSync = ans.Header().Ttl
}
}
}

The list should maybe be sorted, to avoid updating the resource on every reconcile?

egress:
    - ports:
        - protocol: TCP
          port: 443
      to:
        - ipBlock:
            cidr: 8.8.8.16/32
        - ipBlock:
            cidr: 8.8.8.15/32
        - ipBlock:
            cidr: 8.8.8.11/32
        - ipBlock:
            cidr: 8.8.8.10/32
        - ipBlock:
            cidr: 8.8.8.9/32
        - ipBlock:
            cidr: 8.8.8.13/32
        - ipBlock:
            cidr: 8.8.8.14/32
        - ipBlock:
            cidr: 8.8.8.17/32
        - ipBlock:
            cidr: 8.8.8.8/32
@tenstad
Copy link
Author

tenstad commented Oct 24, 2024

Would a simple https://pkg.go.dev/sort#Slice work?

sort.Slice(e.Answer, func(i, j int) bool { return e.Answer[i].String() < e.Answer[j].String() })

or after the frule.To loop:

sort.Slice(peers, func(i, j int) bool { return peers[i].IPBlock.CIDR < peers[j].IPBlock.CIDR })

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

No branches or pull requests

1 participant