From cbf9ed3308cee6042359615a38417a45459e15e6 Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Wed, 9 Nov 2022 18:05:10 +0100 Subject: [PATCH] Use nodeIP to decide the overlay network NIC in windows Signed-off-by: Manuel Buil --- pkg/windows/calico.go | 37 +++++++++++++++++++++++++++++++++-- tests/e2e/mixedos/Vagrantfile | 2 ++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/pkg/windows/calico.go b/pkg/windows/calico.go index 4cd1822817..6ec2636781 100644 --- a/pkg/windows/calico.go +++ b/pkg/windows/calico.go @@ -277,12 +277,23 @@ func (c *Calico) Start(ctx context.Context) error { return nil } +// generateCalicoNetworks creates the overlay networks for internode networking func (c *Calico) generateCalicoNetworks() error { if err := deleteAllNetworksOnNodeRestart(); err != nil { return err } - mgmt, err := createHnsNetwork(c.CNICfg.Mode, os.Getenv("VXLAN_ADAPTER")) + vxlanAdapter := os.Getenv("VXLAN_ADAPTER") + + if vxlanAdapter == "" && c.CNICfg.IP != "" { + iFace, err := findInterface(c.CNICfg.IP) + if err != nil { + return err + } + vxlanAdapter = iFace + } + + mgmt, err := createHnsNetwork(c.CNICfg.Mode, vxlanAdapter) if err != nil { return err } @@ -293,7 +304,6 @@ func (c *Calico) generateCalicoNetworks() error { return err } } - return nil } @@ -606,3 +616,26 @@ func generateGeneralCalicoEnvs(config *CalicoConfig) []string { fmt.Sprintf("VXLAN_VNI=%s", config.Felix.Vxlanvni), } } + +// findInterface returns the name of the interface that contains the passed ip +func findInterface(ip string) (string, error) { + iFaces, err := net.Interfaces() + if err != nil { + return "", err + } + + for _, iFace := range iFaces { + addrs, err := iFace.Addrs() + if err != nil { + return "", err + } + logrus.Debugf("evaluating if the interface: %s with addresses %v, contains ip: %s", iFace.Name, addrs, ip) + for _, addr := range addrs { + if strings.Contains(addr.String(), ip) { + return iFace.Name, nil + } + } + } + + return "", fmt.Errorf("no interface has the ip: %s", ip) +} diff --git a/tests/e2e/mixedos/Vagrantfile b/tests/e2e/mixedos/Vagrantfile index 9970cf5912..0336988f14 100644 --- a/tests/e2e/mixedos/Vagrantfile +++ b/tests/e2e/mixedos/Vagrantfile @@ -77,6 +77,7 @@ def provision(vm, role, role_num, node_num) rke2.config = <<~YAML write-kubeconfig-mode: '0644' node-external-ip: #{node_ip} + node-ip: #{node_ip} server: https://#{NETWORK_PREFIX}.100:9345 token: vagrant-rke2 YAML @@ -103,6 +104,7 @@ def provision(vm, role, role_num, node_num) # rke2.skip_start = true rke2.config = <<~YAML node-external-ip: #{node_ip} + node-ip: #{node_ip} server: https://#{NETWORK_PREFIX}.100:9345 token: vagrant-rke2 YAML