mirror of
https://github.com/moby/moby.git
synced 2026-08-04 15:11:00 +00:00
libnetwork: refactor rule management to use Ensure method for Append and Insert operations
Signed-off-by: Andrey Epifanov <aepifanov@mirantis.com>
This commit is contained in:
committed by
Cory Snider
parent
19a8083866
commit
262c32565b
@@ -467,22 +467,25 @@ func (r Rule) WithChain(chain string) Rule {
|
||||
return wc
|
||||
}
|
||||
|
||||
// Append appends the rule to the end of the chain. If the rule already exists anywhere in the
|
||||
// ensure appends/insert the rule to the end of the chain. If the rule already exists anywhere in the
|
||||
// chain, this is a no-op.
|
||||
func (r Rule) Append() error {
|
||||
func (r Rule) ensure(op Action) error {
|
||||
if r.Exists() {
|
||||
return nil
|
||||
}
|
||||
return r.exec(Append)
|
||||
return r.exec(op)
|
||||
}
|
||||
|
||||
// Append appends the rule to the end of the chain. If the rule already exists anywhere in the
|
||||
// chain, this is a no-op.
|
||||
func (r Rule) Append() error {
|
||||
return r.ensure(Append)
|
||||
}
|
||||
|
||||
// Insert inserts the rule at the head of the chain. If the rule already exists anywhere in the
|
||||
// chain, this is a no-op.
|
||||
func (r Rule) Insert() error {
|
||||
if r.Exists() {
|
||||
return nil
|
||||
}
|
||||
return r.exec(Insert)
|
||||
return r.ensure(Insert)
|
||||
}
|
||||
|
||||
// Delete deletes the rule from the kernel. If the rule does not exist, this is a no-op.
|
||||
|
||||
Reference in New Issue
Block a user