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

If the IP is on the lo device already don't fail #205

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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: 6 additions & 13 deletions pkg/loadbalancer/address_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@ import (
"os/exec"
)

func AddIPToLocalInterface(ip string) error {
func AddIPToLocalInterface(ip string) (string, error) {
// TODO: IPv6
err := exec.Command("ifconfig", "lo0", "alias", ip, "netmask", "255.255.255.255").Run()
if err != nil {
return err
}
return nil
output, err := exec.Command("ifconfig", "lo0", "alias", ip, "netmask", "255.255.255.255").CombinedOutput()
return string(output), err
}

func RemoveIPFromLocalInterface(ip string) error {
func RemoveIPFromLocalInterface(ip string) (string, error) {
// delete the IP address
err := exec.Command("ifconfig", "lo0", "-alias", ip).Run()
if err != nil {
return err
}
return nil

output, err := exec.Command("ifconfig", "lo0", "-alias", ip).CombinedOutput()
return string(output), err
}
22 changes: 9 additions & 13 deletions pkg/loadbalancer/address_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

package loadbalancer

import "os/exec"
import (
"os/exec"
)

func AddIPToLocalInterface(ip string) error {
err := exec.Command("ip", "addr", "add", ip, "dev", "lo").Run()
if err != nil {
return err
}
return nil
func AddIPToLocalInterface(ip string) (string, error) {
output, err := exec.Command("ip", "addr", "add", ip, "dev", "lo").CombinedOutput()
return string(output), err
}

func RemoveIPFromLocalInterface(ip string) error {
err := exec.Command("ip", "addr", "del", ip, "dev", "lo").Run()
if err != nil {
return err
}
return nil
func RemoveIPFromLocalInterface(ip string) (string, error) {
output, err := exec.Command("ip", "addr", "del", ip, "dev", "lo").CombinedOutput()
return string(output), err
}
18 changes: 6 additions & 12 deletions pkg/loadbalancer/address_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ import (
"os/exec"
)

func AddIPToLocalInterface(ip string) error {
err := exec.Command("netsh", "interface", "ip", "add", "address", "loopback", ip, "255.255.255.255").Run()
if err != nil {
return err
}
return nil
func AddIPToLocalInterface(ip string) (string, error) {
output, err := exec.Command("netsh", "interface", "ip", "add", "address", "loopback", ip, "255.255.255.255").CombinedOutput()
return string(output), err
}

func RemoveIPFromLocalInterface(ip string) error {
err := exec.Command("netsh", "interface", "ip", "delete", "address", "loopback", ip, "255.255.255.255").Run()
if err != nil {
return err
}
return nil
func RemoveIPFromLocalInterface(ip string) (string, error) {
output, err := exec.Command("netsh", "interface", "ip", "delete", "address", "loopback", ip, "255.255.255.255").CombinedOutput()
return string(output), err
}
2 changes: 1 addition & 1 deletion pkg/loadbalancer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (s *Server) EnsureLoadBalancer(ctx context.Context, clusterName string, ser
klog.V(2).Infof("updating loadbalancer tunnels on userspace")
err = s.tunnelManager.setupTunnels(loadBalancerName(clusterName, service))
if err != nil {
return nil, err
klog.V(2).ErrorS(err, "error setting up tunnels")
aojea marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/loadbalancer/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ func (t *tunnelManager) setupTunnels(containerName string) error {
}

klog.V(0).Infof("setting IPv4 address %s associated to container %s", ipv4, containerName)
err = AddIPToLocalInterface(ipv4)
output, err := AddIPToLocalInterface(ipv4)
if err != nil {
return err
return fmt.Errorf("error adding IP to local interface: %w - %s", err, output)
}

// create tunnel from the ip:svcport to the localhost:portmap
Expand Down Expand Up @@ -83,9 +83,9 @@ func (t *tunnelManager) removeTunnels(containerName string) error {
}

klog.V(0).Infof("Removing IPv4 address %s associated to local interface", tunnelIP)
err := RemoveIPFromLocalInterface(tunnelIP)
output, err := RemoveIPFromLocalInterface(tunnelIP)
if err != nil {
return err
return fmt.Errorf("error removing IP from local interface: %w - %s", err, output)
}
return nil
}
Expand Down
Loading