Skip to content

Commit

Permalink
Add method DestroyIPSet in pkg/agent/util/ipset (antrea-io#5663)
Browse files Browse the repository at this point in the history
Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
  • Loading branch information
hongliangl authored Nov 8, 2023
1 parent 82627e3 commit 799548c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/agent/util/ipset/ipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var memberPattern = regexp.MustCompile("(?m)^(.*\n)*Members:\n")
type Interface interface {
CreateIPSet(name string, setType SetType, isIPv6 bool) error

DestroyIPSet(name string) error

AddEntry(name string, entry string) error

DelEntry(name string, entry string) error
Expand All @@ -52,6 +54,17 @@ func NewClient() *Client {
return &Client{}
}

func (c *Client) DestroyIPSet(name string) error {
cmd := exec.Command("ipset", "destroy", name)
if err := cmd.Run(); 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 nil
}

// CreateIPSet creates a new set, it will ignore error when the set already exists.
func (c *Client) CreateIPSet(name string, setType SetType, isIPv6 bool) error {
var cmd *exec.Cmd
Expand Down
14 changes: 14 additions & 0 deletions pkg/agent/util/ipset/testing/mock_ipset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 799548c

Please sign in to comment.