Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/iptables/alternatives.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s symlinkSelector) UseMode(ctx context.Context, mode Mode) error {
_ = os.RemoveAll(cmdPath)

if err := os.Symlink(xtablesForModePath, cmdPath); err != nil {
return fmt.Errorf("creating %s symlink for mode %s: %v", cmd, modeStr, err)
return fmt.Errorf("creating %s symlink for mode %s: %w", cmd, modeStr, err)
}
}

Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ import (
"context"
"errors"
"fmt"
"io/fs"
"os"
"os/exec"
"path"

"github.com/kubernetes-sigs/iptables-wrappers/internal/iptables"
)
Expand All @@ -67,10 +69,17 @@ func main() {

selector := iptables.BuildAlternativeSelector(sbinPath)
if err := selector.UseMode(ctx, mode); err != nil {
fmt.Fprintf(os.Stderr, "Unable to redirect iptables binaries. (Are you running in an unprivileged pod?): %s\n", err)
// Ignore redirection error if target already exists. This may happen when
// multiple iptables-wrappers are racing each other or the filesystem is
// mounted read-only.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the target already exists and the filesystem is read-only then why was iptables-wrapper present at all?

Leave the comment about racing but the part about read-only doesn't seem like it makes sense to me.

if !errors.Is(err, fs.ErrExist) {
fmt.Fprintf(os.Stderr, "Unable to redirect iptables binaries. (Are you running in an unprivileged pod?): %s\n", err)
}

// fake it, though this will probably also fail if they aren't root
binaryPath = iptables.XtablesPath(sbinPath, mode)
args = os.Args
args[0] = path.Base(args[0])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What problem are you seeing exactly?

xtables already handles this:

	const char *cmd = basename(*argv);

}

cmdIPTables := exec.CommandContext(ctx, binaryPath, args...)
Expand Down