Skip to content

Commit

Permalink
Log ipset command output on failure
Browse files Browse the repository at this point in the history
Signed-off-by: Quan Tian <[email protected]>
  • Loading branch information
tnqn committed Sep 30, 2024
1 parent a60f535 commit a8caaee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/agent/util/ipset/ipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func NewClient() *Client {

func (c *Client) DestroyIPSet(name string) error {
cmd := exec.Command("ipset", "destroy", name)
if err := cmd.Run(); err != nil {
if output, err := cmd.CombinedOutput(); err != nil {
if strings.Contains(err.Error(), "The set with the given name does not exist") {
return nil
}
return fmt.Errorf("error destroying ipset %s: %v", name, err)
return fmt.Errorf("error destroying ipset %s, err: %w, output: %s", name, err, output)
}
return nil
}
Expand All @@ -75,26 +75,26 @@ func (c *Client) CreateIPSet(name string, setType SetType, isIPv6 bool) error {
// #nosec G204 -- inputs are not controlled by users
cmd = exec.Command("ipset", "create", name, string(setType), "-exist")
}
if err := cmd.Run(); err != nil {
return fmt.Errorf("error creating ipset %s: %v", name, err)
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("error creating ipset %s, err: %w, output: %s", name, err, output)
}
return nil
}

// AddEntry adds a new entry to the set, it will ignore error when the entry already exists.
func (c *Client) AddEntry(name string, entry string) error {
cmd := exec.Command("ipset", "add", name, entry, "-exist")
if err := cmd.Run(); err != nil {
return fmt.Errorf("error adding entry %s to ipset %s: %v", entry, name, err)
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("error adding entry %s to ipset %s, err: %w, output: %s", entry, name, err, output)
}
return nil
}

// DelEntry deletes the entry from the set, it will ignore error when the entry doesn't exist.
func (c *Client) DelEntry(name string, entry string) error {
cmd := exec.Command("ipset", "del", name, entry, "-exist")
if err := cmd.Run(); err != nil {
return fmt.Errorf("error deleting entry %s from ipset %s: %v", entry, name, err)
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("error deleting entry %s from ipset %s, err: %w, output: %s", entry, name, err, output)
}
return nil
}
Expand All @@ -104,7 +104,7 @@ func (c *Client) ListEntries(name string) ([]string, error) {
cmd := exec.Command("ipset", "list", name)
output, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("error listing ipset %s: %v", name, err)
return nil, fmt.Errorf("error listing ipset %s, err: %w, output: %s", name, err, output)
}
memberStr := memberPattern.ReplaceAllString(string(output), "")
lines := strings.Split(memberStr, "\n")
Expand Down
1 change: 1 addition & 0 deletions test/e2e/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ func testProxyServiceLifeCycle(ipFamily *corev1.IPFamily, ingressIPs []string, d
// Client IP should always be preserved regardless of whether the traffic is externally or internally originated.
// Session affinity should take effect when it's enabled.
func TestProxyLoadBalancerModeDSR(t *testing.T) {
t.Fail()
skipIfFeatureDisabled(t, features.LoadBalancerModeDSR, true, false)
skipIfHasWindowsNodes(t)
skipIfNumNodesLessThan(t, 3)
Expand Down

0 comments on commit a8caaee

Please sign in to comment.