mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2025-11-21 13:01:16 +01:00
update alpine image to 3.14 for latest iptables-restore command
with --wait option, and use wait where its available
This commit is contained in:
parent
468670bebb
commit
751981c318
@ -1,5 +1,5 @@
|
|||||||
ARG ARCH=
|
ARG ARCH=
|
||||||
FROM ${ARCH}alpine:3.12
|
FROM ${ARCH}alpine:3.14
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
iptables \
|
iptables \
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SaveInto calls `iptables-save` for given table and stores result in a given buffer.
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
args := []string{"iptables-restore", "-T", table}
|
var args []string
|
||||||
|
args = []string{"iptables-restore", "--help"}
|
||||||
cmd := exec.Cmd{
|
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,
|
Path: path,
|
||||||
Args: args,
|
Args: args,
|
||||||
Stdin: bytes.NewBuffer(data),
|
Stdin: bytes.NewBuffer(data),
|
||||||
}
|
}
|
||||||
b, err := cmd.CombinedOutput()
|
cmdOutput, err = cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%v (%s)", err, b)
|
return fmt.Errorf("%v (%s)", err, cmdOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user