Skip to content

Commit

Permalink
Change MemoryCapacity to StorageCapacity to be more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya Wadhwa committed Aug 21, 2020
1 parent 4fcffca commit 44b93f4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func nodeStatus(api libmachine.API, cc config.ClusterConfig, n config.Node) (*St
}

// Check storage
p, err := machine.MemoryCapacity(cr, "/var")
p, err := machine.StorageCapacity(cr, "/var")
if err != nil {
glog.Errorf("failed to get memory capacity of /var: %v", err)
st.Host = state.Error.String()
Expand Down
14 changes: 0 additions & 14 deletions cmd/minikube/cmd/test

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ const (
MinikubeActivePodmanEnv = "MINIKUBE_ACTIVE_PODMAN"
// MinikubeForceSystemdEnv is used to force systemd as cgroup manager for the container runtime
MinikubeForceSystemdEnv = "MINIKUBE_FORCE_SYSTEMD"
// TestMemoryCapacityEnv is used in integration tests for insufficient storage with 'minikube status'
TestMemoryCapacityEnv = "MINIKUBE_TEST_MEMORY_CAPACITY"
// TestStorageCapacityEnv is used in integration tests for insufficient storage with 'minikube status'
TestStorageCapacityEnv = "MINIKUBE_TEST_STORAGE_CAPACITY"
)

var (
Expand Down
8 changes: 4 additions & 4 deletions pkg/minikube/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func postStartValidations(h *host.Host, drvName string) {
glog.Warningf("error getting command runner: %v", err)
}
// make sure /var isn't full, otherwise warn
percentageFull, err := MemoryCapacity(r, "/var")
percentageFull, err := StorageCapacity(r, "/var")
if err != nil {
glog.Warningf("error getting percentage of /var that is free: %v", err)
}
Expand All @@ -231,9 +231,9 @@ func postStartValidations(h *host.Host, drvName string) {
}
}

// MemoryCapacity returns the capacity of dir in the VM/container
func MemoryCapacity(cr command.Runner, dir string) (int, error) {
if s := os.Getenv(constants.TestMemoryCapacityEnv); s != "" {
// StorageCapacity returns the capacity of dir in the VM/container as a percentage
func StorageCapacity(cr command.Runner, dir string) (int, error) {
if s := os.Getenv(constants.TestStorageCapacityEnv); s != "" {
return strconv.Atoi(s)
}
output, err := cr.RunCmd(exec.Command("sh", "-c", fmt.Sprintf("df -h %s | awk 'NR==2{print $5}'", dir)))
Expand Down
4 changes: 2 additions & 2 deletions test/integration/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestInsufficientStorage(t *testing.T) {
startArgs = append(startArgs, StartArgs()...)
c := exec.CommandContext(ctx, Target(), startArgs...)
// artificially set /var to 100% capacity
c.Env = append(os.Environ(), fmt.Sprintf("%s=100", constants.TestMemoryCapacityEnv))
c.Env = append(os.Environ(), fmt.Sprintf("%s=100", constants.TestStorageCapacityEnv))

rr, err := Run(t, c)
if err == nil {
Expand All @@ -69,7 +69,7 @@ func runStatusCmd(ctx context.Context, t *testing.T, profile string) []byte {
// make sure minikube status shows insufficient storage
c := exec.CommandContext(ctx, Target(), "status", "-p", profile, "--output=json", "--layout=cluster", "--alsologtostderr")
// artificially set /var to 100% capacity
c.Env = append(os.Environ(), fmt.Sprintf("%s=100", constants.TestMemoryCapacityEnv))
c.Env = append(os.Environ(), fmt.Sprintf("%s=100", constants.TestStorageCapacityEnv))
rr, err := Run(t, c)
// status exits non-0 if status isn't Running
if err == nil {
Expand Down

0 comments on commit 44b93f4

Please sign in to comment.