-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enivironment variables for port-driver, cidr, mtu, and disable-host-loopback settings. Since rootless is still experimental, I don't think they deserve full CLI flag status. Signed-off-by: Brad Davidson <[email protected]>
- Loading branch information
Showing
2 changed files
with
126 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package rootless | ||
|
||
import ( | ||
"io" | ||
"path" | ||
|
||
"github.com/rootless-containers/rootlesskit/pkg/port" | ||
portbuiltin "github.com/rootless-containers/rootlesskit/pkg/port/builtin" | ||
portslirp4netns "github.com/rootless-containers/rootlesskit/pkg/port/slirp4netns" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type portDriver interface { | ||
NewParentDriver() (port.ParentDriver, error) | ||
NewChildDriver() port.ChildDriver | ||
LogWriter() io.Writer | ||
SetStateDir(string) | ||
APISocketPath() string | ||
} | ||
|
||
type builtinDriver struct { | ||
logWriter io.Writer | ||
stateDir string | ||
} | ||
|
||
func (b *builtinDriver) NewParentDriver() (port.ParentDriver, error) { | ||
return portbuiltin.NewParentDriver(b.logWriter, b.stateDir) | ||
} | ||
|
||
func (b *builtinDriver) NewChildDriver() port.ChildDriver { | ||
return portbuiltin.NewChildDriver(b.logWriter) | ||
} | ||
|
||
func (b *builtinDriver) LogWriter() io.Writer { | ||
return b.logWriter | ||
} | ||
|
||
func (b *builtinDriver) SetStateDir(stateDir string) { | ||
b.stateDir = stateDir | ||
} | ||
|
||
func (b *builtinDriver) APISocketPath() string { | ||
return "" | ||
} | ||
|
||
type slirp4netnsDriver struct { | ||
logWriter io.Writer | ||
stateDir string | ||
} | ||
|
||
func (s *slirp4netnsDriver) NewParentDriver() (port.ParentDriver, error) { | ||
return portslirp4netns.NewParentDriver(s.logWriter, s.APISocketPath()) | ||
} | ||
|
||
func (s *slirp4netnsDriver) NewChildDriver() port.ChildDriver { | ||
return portslirp4netns.NewChildDriver() | ||
} | ||
|
||
func (s *slirp4netnsDriver) LogWriter() io.Writer { | ||
return s.logWriter | ||
} | ||
|
||
func (s *slirp4netnsDriver) SetStateDir(stateDir string) { | ||
s.stateDir = stateDir | ||
} | ||
|
||
func (s *slirp4netnsDriver) APISocketPath() string { | ||
if s.stateDir != "" { | ||
return path.Join(s.stateDir, ".s4nn.sock") | ||
} | ||
return "" | ||
} | ||
|
||
func getDriver(driverName string, logWriter io.Writer) portDriver { | ||
if driverName == "slirp4netns" { | ||
return &slirp4netnsDriver{logWriter: logWriter} | ||
} | ||
|
||
if driverName != "" && driverName != "builtin" { | ||
logrus.Warnf("Unsupported port driver %s, using default builtin", driverName) | ||
} | ||
|
||
return &builtinDriver{logWriter: logWriter} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters