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

Linux configurer crashes when resolving IP has 255.255.255.255 netmask #296

Closed
andrelaszlo opened this issue Jan 13, 2022 · 0 comments · Fixed by #297
Closed

Linux configurer crashes when resolving IP has 255.255.255.255 netmask #296

andrelaszlo opened this issue Jan 13, 2022 · 0 comments · Fixed by #297

Comments

@andrelaszlo
Copy link
Contributor

andrelaszlo commented Jan 13, 2022

iproute2 outputs just the ip without subnet when the netmask is 255.255.255.255

This causes an issue in the Linux configurer (running with --debug):

INFO[0001] ==> Running phase: Gather host facts 
DEBU[0001] [local] localhost: executing `uname -m`      
DEBU[0001] [local] localhost: x86_64                    
DEBU[0001] [local] localhost: executing `hostname 2> /dev/null` 
DEBU[0001] [local] localhost: myhostname                  
INFO[0001] [local] localhost: using myhostname as hostname 
DEBU[0001] [local] localhost: executing `PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH; (ip route list scope global | grep -E "\b(172|10|192\.168)\.") || (ip route list | grep -m1 default)` 
DEBU[0001] [local] localhost: default via 12.34.56.1 dev enp2s0 proto static 
INFO[0001] [local] localhost: discovered enp2s0 as private interface 
DEBU[0001] [local] localhost: executing `PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH ip -o addr show dev enp2s0 scope global` 
DEBU[0001] [local] localhost: 2: enp2s0    inet 12.34.56.78 peer 12.34.56.1/32 scope global enp2s0\       valid_lft forever preferred_lft forever 
DEBU[0001] [local] localhost: 2: enp2s0    inet6 [redacted]/64 scope global \       valid_lft forever preferred_lft forever 
panic: runtime error: slice bounds out of range [:-1]

goroutine 31 [running]:
github.com/k0sproject/k0sctl/configurer.Linux.PrivateAddress({{0xc0001f3c00, 0xbfc340}}, {0xd31b20, 0xc0000c6000}, {0xc000628340, 0x6}, {0xc20f1f, 0x9})
	/path/to/project/k0sctl/configurer/linux.go:178 +0x308
github.com/k0sproject/k0sctl/phase.(*GatherFacts).investigateHost(0xc0000b0b40, 0xc0000c6000)
	/path/to/project/k0sctl/phase/gather_facts.go:65 +0x4c3
github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster.Hosts.ParallelEach.func1(0xc0000c6000)
	/path/to/project/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/hosts.go:115 +0xcb
created by github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster.Hosts.ParallelEach
	/path/to/project/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/hosts.go:114 +0x25a

(Some values changed for privacy reasons.)

If I am reading this correctly, the issue is that the CIDR notation is omitted and the IP field simply doesn't have a slash.

Suggested fix: check that strings.Index(items[3], "/") is nonnegative, otherwise use the field as-is.
Better fix might be to parse ips json output instead. Seems like it's been around since 2017 or so.

Affected version(s): verified in 0.12.0 and 0.12.1

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 a pull request may close this issue.

1 participant