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

Fix using miekg dns #3136

Merged
merged 7 commits into from
Apr 6, 2023

Conversation

christoph-zededa
Copy link
Contributor

@christoph-zededa christoph-zededa commented Apr 2, 2023

linuxkit-525400123456:~# eve enter pillar
(ns: pillar) linuxkit-525400123456:/# cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
104.16.132.229 cloudflare.com
104.16.133.229 cloudflare.com

)

see also #3096 and #3125

@christoph-zededa christoph-zededa changed the title Fix using miekg dns [WIP] Fix using miekg dns Apr 2, 2023
@christoph-zededa christoph-zededa force-pushed the fix_using_miekg_dns branch 2 times, most recently from 323661a to 2a3a81e Compare April 4, 2023 13:09
…pkg/pillar""

This reverts commit 34a3926.

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
This reverts commit 6a7b769.

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
This reverts commit 4569202.

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
Signed-off-by: Christoph Ostarek <christoph@zededa.com>
if the host cannot be resolved and empty array would be returned.
In the following line the first element would be dereferenced, but
that does not exist and so the process would panic

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
@christoph-zededa christoph-zededa changed the title [WIP] Fix using miekg dns Fix using miekg dns Apr 4, 2023
@christoph-zededa christoph-zededa marked this pull request as ready for review April 4, 2023 17:39
@christoph-zededa
Copy link
Contributor Author

christoph-zededa commented Apr 4, 2023

I am not sure if we should keep c6cbde5


if len(dnsResponses) == 0 {
newhosts = append(newhosts, etchosts...)
} else {
ttlSec = int(dnsResponses[0].TTL)
lookupIPaddr = dnsResponses[0].IP.String()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the old/current code only writing one IP address to the hosts file? Or does it write all?
You could make this loop over dnsResponses and Sprintf ine line for each if that is the behavior we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current master only writes one IP address to the hosts file; this branch writes all IP addresses to the hosts file.

I think this is the behavior we want; I saw that f.e. ping would choose the ip address that is reachable from the hosts file if there is more than one.

Comment on lines 123 to 125
lastDNSResponse := dnsResponses[len(dnsResponses)-1]
ipaddrCached = lastDNSResponse.IP.String()
ttlSec = getTTL(time.Duration(lastDNSResponse.TTL))
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICT old/current code picks the first. Any particular motivation for picking the last here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand the code like this:
https://github.com/lf-edge/eve/blob/master/pkg/pillar/cmd/nim/controllerdns.go#L124 is iterating over all the responses and everytime assigns/overwrites the lookupIPaddr in https://github.com/lf-edge/eve/blob/master/pkg/pillar/cmd/nim/controllerdns.go#L130. So after the loop lookupIPaddr holds the value from the last iteration.

Same with newhosts as it does not append the previous value of newshosts but instead overwrites it here https://github.com/lf-edge/eve/blob/master/pkg/pillar/cmd/nim/controllerdns.go#L137 .

Nevertheless I think now it is better to choose the first one; this way pillar respects the case that an administrator wants to decrease the load on one IP address.

Copy link
Contributor

@eriknordmark eriknordmark left a comment

Choose a reason for hiding this comment

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

Kick of tests in parallel with discussion

into writeHostsFile method

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
if as host has two ip addresses, both will be written
to /etc/hosts;

use `getent ahostsv4 <host>` to query them

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
Copy link
Contributor

@eriknordmark eriknordmark left a comment

Choose a reason for hiding this comment

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

Run eden again

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.

2 participants