Skip to content

Commit

Permalink
Merge pull request #3530 from manuelbuil/fixWindowsTest
Browse files Browse the repository at this point in the history
Take nodeIP into account to configure the calico networks
  • Loading branch information
manuelbuil authored Nov 24, 2022
2 parents 8ef30b1 + cbf9ed3 commit b7c5c86
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
37 changes: 35 additions & 2 deletions pkg/windows/calico.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -293,7 +304,6 @@ func (c *Calico) generateCalicoNetworks() error {
return err
}
}

return nil
}

Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions tests/e2e/mixedos/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b7c5c86

Please sign in to comment.