提交 c2175abc 编写于 作者: J Jose Donizetti

Add static ip to kic/docker

上级 56642282
......@@ -251,6 +251,13 @@ func deletePossibleKicLeftOver(cname string, driverName string) {
glog.Warningf("error deleting volumes (might be okay).\nTo see the list of volumes run: 'docker volume ls'\n:%v", errs)
}
// TODO: move to oci.DeleteContainer?
defaultNetwork := fmt.Sprintf("%s-network", cname)
err = oci.RemoveNetwork(defaultNetwork)
if err != nil {
glog.Warningf("error deleting network. :%v", errs)
}
if bin == oci.Podman {
// podman prune does not support --filter
return
......
......@@ -67,6 +67,15 @@ func NewDriver(c Config) *Driver {
// Create a host using the driver's config
func (d *Driver) Create() error {
defaultNetwork := fmt.Sprintf("%s-network", d.MachineName)
defaultIPRange := "192.168.39.0/24"
err := oci.CreateNetwork(defaultNetwork, defaultIPRange)
if err != nil {
// use k8s network? fail?
return err
}
params := oci.CreateParams{
Name: d.NodeConfig.MachineName,
Image: d.NodeConfig.ImageDigest,
......@@ -78,6 +87,8 @@ func (d *Driver) Create() error {
ExtraArgs: []string{"--expose", fmt.Sprintf("%d", d.NodeConfig.APIServerPort)},
OCIBinary: d.NodeConfig.OCIBinary,
APIServerPort: d.NodeConfig.APIServerPort,
Network: defaultNetwork,
IP: "192.168.39.2",
}
// control plane specific options
......
......@@ -162,3 +162,30 @@ func dockerContainerIP(name string) (string, string, error) {
return ips[0], ips[1], nil
}
// CreateNetwork creates a network
func CreateNetwork(name, ipRange string) error {
// TODO: validate if exist?
// TODO: subnet conflict
// TODO: configure gateway explictly
subnet := fmt.Sprintf("--subnet=%s", ipRange)
_, err := runCmd(exec.Command(Docker, "network", "create", "--driver=bridge", subnet, name))
if err != nil {
return errors.Wrapf(err, "error creating network")
}
return nil
}
// RemoveNetwork removes a network
func RemoveNetwork(name string) error {
// TODO: check if exist?
_, err := runCmd(exec.Command(Docker, "network", "remove", name))
if err != nil {
return errors.Wrapf(err, "error removing network")
}
return nil
}
......@@ -142,6 +142,13 @@ func CreateContainerNode(p CreateParams) error {
"--label", p.NodeLabel,
}
// network
if p.OCIBinary == Docker && runtime.GOOS == "linux" { // for now only docker on linux
runArgs = append(runArgs, "--network", p.Network)
runArgs = append(runArgs, "--ip", p.IP)
}
// volume
if p.OCIBinary == Podman { // enable execing in /var
// podman mounts var/lib with no-exec by default https://github.com/containers/libpod/issues/5103
runArgs = append(runArgs, "--volume", fmt.Sprintf("%s:/var:exec", p.Name))
......
......@@ -48,6 +48,8 @@ type CreateParams struct {
Envs map[string]string // environment variables to pass to the container
ExtraArgs []string // a list of any extra option to pass to oci binary during creation time, for example --expose 8080...
OCIBinary string // docker or podman
Network string // network used by the container
IP string // container ip address
}
// createOpt is an option for Create
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册