Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --docker-ports flag in order to expose custom ports when running with docker VM driver #645

Merged
merged 2 commits into from
Nov 17, 2020
Merged
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
15 changes: 14 additions & 1 deletion cmd/kyma/provision/minikube/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
bootstrapper string = "kubeadm"
vmDriverHyperkit string = "hyperkit"
vmDriverHyperv string = "hyperv"
vmDriverDocker string = "docker"
vmDriverNone string = "none"
vmDriverVirtualBox string = "virtualbox"
sleep = 10 * time.Second
Expand All @@ -37,7 +38,7 @@ var (
vmDriverHyperkit,
vmDriverVirtualBox,
"kvm2",
"docker",
vmDriverDocker,
"none",
}
ErrMinikubeRunning = errors.New("Minikube already running")
Expand Down Expand Up @@ -66,6 +67,7 @@ func NewCmd(o *Options) *cobra.Command {

cmd.Flags().StringVar(&o.VMDriver, "vm-driver", defaultVMDriver, "Specifies the VM driver. Possible values: "+strings.Join(drivers, ","))
cmd.Flags().StringVar(&o.HypervVirtualSwitch, "hypervVirtualSwitch", "", "Specifies the Hyper-V switch version if you choose Hyper-V as the driver.")
cmd.Flags().StringSliceVar(&o.DockerPorts, "docker-ports", []string{}, "List of ports that should be exposed if you choose Docker as the driver.")
cmd.Flags().StringVar(&o.DiskSize, "disk-size", "30g", "Specifies the disk size used for installation.")
cmd.Flags().StringVar(&o.Memory, "memory", "8192", "Specifies RAM reserved for installation.")
cmd.Flags().StringVar(&o.CPUS, "cpus", "4", "Specifies the number of CPUs used for installation.")
Expand Down Expand Up @@ -182,6 +184,11 @@ func (c *command) checkRequirements(s step.Step) error {
return fmt.Errorf("Specified VMDriver '%s' requires the --hypervVirtualSwitch option", vmDriverHyperv)
}

if len(c.opts.DockerPorts) > 0 && c.opts.VMDriver != vmDriverDocker {
s.Failure()
return fmt.Errorf("docker-ports flag is applicable only for VMDriver '%s'", vmDriverDocker)
}

versionWarning, err := minikube.CheckVersion(c.opts.Verbose, c.opts.Timeout)
if err != nil {
s.Failure()
Expand Down Expand Up @@ -243,6 +250,12 @@ func (c *command) startMinikube() error {
startCmd = append(startCmd, "--hyperv-virtual-switch="+c.opts.HypervVirtualSwitch)
}

if c.opts.VMDriver == vmDriverDocker && len(c.opts.DockerPorts) > 0 {
for _, port := range c.opts.DockerPorts {
startCmd = append(startCmd, "--ports="+port)
}
}

startCmd, err := osSpecificRun(c, startCmd)
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions cmd/kyma/provision/minikube/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ func TestCheckRequirements(t *testing.T) {
VMDriver: "hyperv",
},
},
{
name: "--docker-ports require VM Driver docker",
shouldFail: true,
expectedErr: "docker-ports flag is applicable only for VMDriver 'docker'",
op: Options{
VMDriver: "hyperkit",
DockerPorts: []string{"8080:8081"},
},
},
}
var step step.Factory
s := step.NewStep("checking requirements")
Expand Down
1 change: 1 addition & 0 deletions cmd/kyma/provision/minikube/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Options struct {
Memory string
CPUS string
HypervVirtualSwitch string
DockerPorts []string
Profile string
UseVPNKitSock bool
Timeout time.Duration
Expand Down
1 change: 1 addition & 0 deletions docs/gen-docs/kyma_provision_minikube.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ kyma provision minikube [flags]
```bash
--cpus string Specifies the number of CPUs used for installation. (default "4")
--disk-size string Specifies the disk size used for installation. (default "30g")
--docker-ports strings List of ports that should be exposed if you choose Docker as the driver.
--hypervVirtualSwitch string Specifies the Hyper-V switch version if you choose Hyper-V as the driver.
-k, --kube-version string Kubernetes version of the cluster. (default "1.16.15")
--memory string Specifies RAM reserved for installation. (default "8192")
Expand Down