Skip to content

Commit

Permalink
Merge pull request #9166 from priyawadhwa/revert-static-ip
Browse files Browse the repository at this point in the history
Revert static IP for docker
  • Loading branch information
sharifelgamal authored Sep 2, 2020
2 parents dab20a2 + 22b40e2 commit 3c86db0
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 71 deletions.
8 changes: 0 additions & 8 deletions pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ func (d *Driver) Create() error {
APIServerPort: d.NodeConfig.APIServerPort,
}

defaultNetwork := d.MachineName
if err := oci.CreateNetwork(defaultNetwork, oci.DefaultIPRange, oci.DefaultGateway); err != nil {
glog.Warningf("unable to create docker network; node ip may not be stable: %v", err)
} else {
params.Network = defaultNetwork
params.IP = oci.DefaultIP
}

// control plane specific options
params.PortMappings = append(params.PortMappings, oci.PortMapping{
ListenAddress: oci.DefaultBindIPV4,
Expand Down
45 changes: 0 additions & 45 deletions pkg/drivers/kic/oci/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ func profileInContainers(profile string, containers []string) bool {
// gets the ip from user's host docker
func dockerGatewayIP(profile string) (net.IP, error) {
var bridgeID string
// check if using custom network first
if networkExists(profile) {
ip := net.ParseIP(DefaultGateway)
return ip, nil
}
rr, err := runCmd(exec.Command(Docker, "network", "ls", "--filter", "name=bridge", "--format", "{{.ID}}"))
if err != nil {
return nil, errors.Wrapf(err, "get network bridge")
Expand Down Expand Up @@ -195,43 +190,3 @@ func dockerContainerIP(name string) (string, string, error) {

return ips[0], ips[1], nil
}

// CreateNetwork creates a network
func CreateNetwork(name, ipRange, gateway string) error {
// check if the network already exists
if networkExists(name) {
return nil
}

subnet := fmt.Sprintf("--subnet=%s", ipRange)
_, err := runCmd(exec.Command(Docker, "network", "create", "--driver=bridge", subnet, "--gateway", gateway, name))
if err != nil {
return errors.Wrapf(err, "error creating network")
}

return nil
}

// removeNetwork removes a network
func removeNetwork(name string) error {
if !networkExists(name) {
return nil
}
_, err := runCmd(exec.Command(Docker, "network", "remove", name))
return err
}

func networkExists(name string) bool {
rr, err := runCmd(exec.Command(Docker, "network", "ls", "--format", "{{.Name}}"))
if err != nil {
glog.Warningf("error listing networks: %v", err)
return false
}
networks := strings.Split(rr.Output(), "\n")
for _, n := range networks {
if strings.Trim(n, "\n") == name {
return true
}
}
return false
}
12 changes: 2 additions & 10 deletions pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func DeleteContainersByLabel(ociBin string, label string) []error {
}

if _, err := runCmd(exec.Command(ociBin, "rm", "-f", "-v", c)); err != nil {
deleteErrs = append(deleteErrs, errors.Wrapf(err, "delete container %s", c))
deleteErrs = append(deleteErrs, errors.Wrapf(err, "delete container %s: output %s", c, err))
}

}
return deleteErrs
}
Expand All @@ -88,9 +89,6 @@ func DeleteContainer(ociBin string, name string) error {
if _, err := runCmd(exec.Command(ociBin, "rm", "-f", "-v", name)); err != nil {
return errors.Wrapf(err, "delete %s", name)
}
if err := removeNetwork(name); err != nil {
return errors.Wrap(err, "removing network")
}
return nil
}

Expand Down Expand Up @@ -153,12 +151,6 @@ func CreateContainerNode(p CreateParams) error {
runArgs = append(runArgs, "--volume", fmt.Sprintf("%s:/var:exec", p.Name))
}
if p.OCIBinary == Docker {
// on linux, we can provide a static IP for docker
if runtime.GOOS == "linux" && p.Network != "" && p.IP != "" {
runArgs = append(runArgs, "--network", p.Network)
runArgs = append(runArgs, "--ip", p.IP)
}

runArgs = append(runArgs, "--volume", fmt.Sprintf("%s:/var", p.Name))
// ignore apparmore github actions docker: https://github.com/kubernetes/minikube/issues/7624
runArgs = append(runArgs, "--security-opt", "apparmor=unconfined")
Expand Down
8 changes: 0 additions & 8 deletions pkg/drivers/kic/oci/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ const (
nodeRoleLabelKey = "role.minikube.sigs.k8s.io"
// CreatedByLabelKey is applied to any container/volume that is created by minikube created_by.minikube.sigs.k8s.io=true
CreatedByLabelKey = "created_by.minikube.sigs.k8s.io"
// DefaultGateway is the default gateway for the docker network created by the kic driver on linux
DefaultGateway = "192.168.39.1"
// DefaultIPRange is the default IP range for the docker network created by the kic driver on linux
DefaultIPRange = "192.168.39.0/24"
// DefaultIP is the default IP for the docker network created by the kic driver on linux
DefaultIP = "192.168.39.2"
)

// CreateParams are parameters needed to create a container
Expand All @@ -61,8 +55,6 @@ 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
Expand Down

0 comments on commit 3c86db0

Please sign in to comment.