Skip to content

Commit

Permalink
Move CalculateDiskSizeInMB to utils to use in kvm
Browse files Browse the repository at this point in the history
  • Loading branch information
r2d4 committed Aug 23, 2017
1 parent 8ef9d49 commit 819a81e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,6 @@ out/docker-machine-driver-kvm: $(KVM_DRIVER_FILES)
k8s.io/minikube/cmd/drivers/kvm
chmod +X $@

.PHONY: kvm-driver
install-kvm-driver: out/docker-machine-driver-kvm $(KVM_DRIVER_FILES)
.PHONY: install-kvm
install-kvm: out/docker-machine-driver-kvm
cp out/docker-machine-driver-kvm $(GOBIN)/docker-machine-driver-kvm
11 changes: 1 addition & 10 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"time"

"github.com/blang/semver"
units "github.com/docker/go-units"
"github.com/docker/machine/libmachine/host"
"github.com/golang/glog"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -93,7 +92,7 @@ func runStart(cmd *cobra.Command, args []string) {
defer api.Close()

diskSize := viper.GetString(humanReadableDiskSize)
diskSizeMB := calculateDiskSizeInMB(diskSize)
diskSizeMB := util.CalculateDiskSizeInMB(diskSize)

if diskSizeMB < constants.MinimumDiskSizeMB {
err := fmt.Errorf("Disk Size %dMB (%s) is too small, the minimum disk size is %dMB", diskSizeMB, diskSize, constants.MinimumDiskSizeMB)
Expand Down Expand Up @@ -312,14 +311,6 @@ func validateK8sVersion(version string) {
}
}

func calculateDiskSizeInMB(humanReadableDiskSize string) int {
diskSize, err := units.FromHumanSize(humanReadableDiskSize)
if err != nil {
glog.Errorf("Invalid disk size: %s", err)
}
return int(diskSize / units.MB)
}

func init() {
startCmd.Flags().Bool(keepContext, constants.DefaultKeepContext, "This will keep the existing kubectl context and will create a minikube context.")
startCmd.Flags().Bool(createMount, false, "This will start the mount daemon and automatically mount files into minikube")
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"time"

"github.com/blang/semver"
units "github.com/docker/go-units"
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/kubernetes_versions"
Expand All @@ -42,6 +44,14 @@ type RetriableError struct {

func (r RetriableError) Error() string { return "Temporary Error: " + r.Err.Error() }

func CalculateDiskSizeInMB(humanReadableDiskSize string) int {
diskSize, err := units.FromHumanSize(humanReadableDiskSize)
if err != nil {
glog.Errorf("Invalid disk size: %s", err)
}
return int(diskSize / units.MB)
}

// Until endlessly loops the provided function until a message is received on the done channel.
// The function will wait the duration provided in sleep between function calls. Errors will be sent on provider Writer.
func Until(fn func() error, w io.Writer, name string, sleep time.Duration, done <-chan struct{}) {
Expand Down

0 comments on commit 819a81e

Please sign in to comment.