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: skip internal k3s ifaces for autodetection #66

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions internal/local/k3s/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"strings"

"github.com/rs/zerolog"
"golang.org/x/exp/slices"
"golang.org/x/mod/semver"

"github.com/weka/gohomecli/internal/local/bundle"
Expand Down Expand Up @@ -158,6 +159,13 @@ func setupNetwork(c *Config) (err error) {
return nil
}

var internalIfaces = []string{
"cni",
"veth",
"flannel",
"docker",
}

// getInterface checks if iface name is valid and running
func getInterface(iface string) (net.Interface, error) {
ifaces, err := net.Interfaces()
Expand All @@ -166,8 +174,13 @@ func getInterface(iface string) (net.Interface, error) {
}

for _, i := range ifaces {
// if it's loopback or not running - skip it
if i.Flags&net.FlagLoopback == net.FlagLoopback || i.Flags&net.FlagRunning != net.FlagRunning {
// skip internal k3s flannel ifaces
internal := slices.ContainsFunc(internalIfaces, func(s string) bool {
return strings.HasPrefix(i.Name, s)
})

// if it's internal flannel iface, loopback or not running - skip it
if internal || i.Flags&net.FlagLoopback == net.FlagLoopback || i.Flags&net.FlagRunning != net.FlagRunning {
logger.Debug().
Str("iface", i.Name).
Bool("loopback", i.Flags&net.FlagLoopback == net.FlagLoopback).
Expand Down Expand Up @@ -222,7 +235,7 @@ func upsertIfaceAddrHost(iface net.Interface, ifaceAddr *string, hostname *strin
}

if !addrFound {
return fmt.Errorf("IP address %q is valid", *ifaceAddr)
return fmt.Errorf("IP address %q is not valid", *ifaceAddr)
}

if *hostname == "" {
Expand Down
Loading