From 751981c31818f8eaf4dc21dc1977daabc099c047 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Mon, 28 Jun 2021 02:53:41 +0530 Subject: [PATCH] update alpine image to 3.14 for latest iptables-restore command with --wait option, and use wait where its available --- Dockerfile | 2 +- pkg/utils/iptables.go | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1e8d1482..9c43d5e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ARG ARCH= -FROM ${ARCH}alpine:3.12 +FROM ${ARCH}alpine:3.14 RUN apk add --no-cache \ iptables \ diff --git a/pkg/utils/iptables.go b/pkg/utils/iptables.go index 3919f432..8fb5c879 100644 --- a/pkg/utils/iptables.go +++ b/pkg/utils/iptables.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "os/exec" + "strings" ) // SaveInto calls `iptables-save` for given table and stores result in a given buffer. @@ -32,15 +33,30 @@ func Restore(table string, data []byte) error { if err != nil { return err } - args := []string{"iptables-restore", "-T", table} + var args []string + args = []string{"iptables-restore", "--help"} cmd := exec.Cmd{ + Path: path, + Args: args, + } + cmdOutput, err := cmd.CombinedOutput() + if err != nil { + return fmt.Errorf("%v (%s)", err, cmdOutput) + } + if strings.Contains(string(cmdOutput), "wait") { + args = []string{"iptables-restore", "--wait", "-T", table} + } else { + args = []string{"iptables-restore", "-T", table} + } + + cmd = exec.Cmd{ Path: path, Args: args, Stdin: bytes.NewBuffer(data), } - b, err := cmd.CombinedOutput() + cmdOutput, err = cmd.CombinedOutput() if err != nil { - return fmt.Errorf("%v (%s)", err, b) + return fmt.Errorf("%v (%s)", err, cmdOutput) } return nil