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

Consistent behaviour of Egress with and without ExternalIPPool #6661

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
31 changes: 30 additions & 1 deletion pkg/controller/egress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (
"encoding/json"
"fmt"
"net"
"os/exec"
"reflect"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -241,6 +243,20 @@ func (c *EgressController) setIPAllocation(egressName string, ip net.IP, poolNam
}
}

func pingEgressIP(egressIP string) (bool, error) {
cmd := exec.Command("ping", "-c", "3", "-w", "5", egressIP)
output, err := cmd.CombinedOutput()

if err != nil {
return false, fmt.Errorf("ping command failed: %v. output: %s", err, string(output))
}

if strings.Contains(string(output), "3 packets transmitted, 3 received") {
return true, nil
}
return false, nil
}

KMAnju-2021 marked this conversation as resolved.
Show resolved Hide resolved
// syncEgressIP is responsible for releasing stale EgressIP and allocating new EgressIP for an Egress if applicable.
func (c *EgressController) syncEgressIP(egress *egressv1beta1.Egress) (net.IP, *egressv1beta1.Egress, error) {
prevIP, prevIPPool, exists := c.getIPAllocation(egress.Name)
Expand All @@ -257,7 +273,20 @@ func (c *EgressController) syncEgressIP(egress *egressv1beta1.Egress) (net.IP, *

// Skip allocating EgressIP if ExternalIPPool is not specified and return whatever user specifies.
if egress.Spec.ExternalIPPool == "" {
return net.ParseIP(egress.Spec.EgressIP), egress, nil

if egress.Spec.EgressIP != "" {
reachable, err := pingEgressIP(egress.Spec.EgressIP)
if reachable && err == nil {
return net.ParseIP(egress.Spec.EgressIP), egress, nil
} else {
if updatedEgress, err := c.updateEgressIP(egress, ""); err != nil {
return nil, egress, err
} else {
egress = updatedEgress
}
KMAnju-2021 marked this conversation as resolved.
Show resolved Hide resolved
}
}
return nil, egress, fmt.Errorf("EgressIP %s not configured on any interface", egress.Spec.EgressIP)
}

if !c.externalIPAllocator.IPPoolExists(egress.Spec.ExternalIPPool) {
Expand Down
Loading