Skip to content

Commit 9c6f051

Browse files
author
priyawadhwa
authored
Merge pull request #9028 from priyawadhwa/var-warning
Warn if /var disk space is full and add a solution message
2 parents dd11ed8 + a328961 commit 9c6f051

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

pkg/minikube/exit/exit.go

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ func WithError(msg string, err error) {
7373
// WithProblem outputs info related to a known problem and exits.
7474
func WithProblem(msg string, err error, p *problem.Problem) {
7575
out.ErrT(out.Empty, "")
76-
glog.Errorf("%+v\n", p)
7776
out.FailureT("[{{.id}}] {{.msg}} {{.error}}", out.V{"msg": msg, "id": p.ID, "error": p.Err})
7877
p.Display()
7978
if p.ShowIssueLink {

pkg/minikube/machine/fix.go

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func fixHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node) (*hos
5959
if err != nil {
6060
return h, errors.Wrap(err, "Error loading existing host. Please try running [minikube delete], then run [minikube start] again.")
6161
}
62+
defer postStartValidations(h, cc.Driver)
6263

6364
driverName := h.Driver.DriverName()
6465

pkg/minikube/machine/start.go

+29
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"os/exec"
2424
"path"
2525
"path/filepath"
26+
"strconv"
27+
"strings"
2628
"time"
2729

2830
"github.com/docker/machine/libmachine"
@@ -37,6 +39,7 @@ import (
3739
"k8s.io/minikube/pkg/minikube/config"
3840
"k8s.io/minikube/pkg/minikube/constants"
3941
"k8s.io/minikube/pkg/minikube/driver"
42+
"k8s.io/minikube/pkg/minikube/exit"
4043
"k8s.io/minikube/pkg/minikube/localpath"
4144
"k8s.io/minikube/pkg/minikube/out"
4245
"k8s.io/minikube/pkg/minikube/out/register"
@@ -149,6 +152,7 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) (
149152
if err != nil {
150153
return nil, errors.Wrap(err, "new host")
151154
}
155+
defer postStartValidations(h, cfg.Driver)
152156

153157
h.HostOptions.AuthOptions.CertDir = localpath.MiniPath()
154158
h.HostOptions.AuthOptions.StorePath = localpath.MiniPath()
@@ -202,6 +206,31 @@ func timedCreateHost(h *host.Host, api libmachine.API, t time.Duration) error {
202206
}
203207
}
204208

209+
// postStartValidations are validations against the host after it is created
210+
// TODO: Add validations for VM drivers as well, see issue #9035
211+
func postStartValidations(h *host.Host, drvName string) {
212+
if !driver.IsKIC(drvName) {
213+
return
214+
}
215+
// make sure /var isn't full, otherwise warn
216+
output, err := h.RunSSHCommand("df -h /var | awk 'NR==2{print $5}'")
217+
if err != nil {
218+
glog.Warningf("error running df -h /var: %v", err)
219+
}
220+
output = strings.Trim(output, "\n")
221+
percentageFull, err := strconv.Atoi(output[:len(output)-1])
222+
if err != nil {
223+
glog.Warningf("error getting percentage of /var that is free: %v", err)
224+
}
225+
if percentageFull >= 99 {
226+
exit.WithError("", fmt.Errorf("docker daemon out of memory. No space left on device"))
227+
}
228+
229+
if percentageFull > 80 {
230+
out.WarningT("The docker daemon is almost out of memory, run 'docker system prune' to free up space")
231+
}
232+
}
233+
205234
// postStart are functions shared between startHost and fixHost
206235
func postStartSetup(h *host.Host, mc config.ClusterConfig) error {
207236
glog.Infof("post-start starting for %q (driver=%q)", h.Name, h.DriverName)

pkg/minikube/problem/err_map.go

+15
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,18 @@ var stateProblems = map[string]match{
578578
Issues: []int{7256},
579579
},
580580
}
581+
582+
// dockerProblems are issues relating to issues with the docker driver
583+
var dockerProblems = map[string]match{
584+
"NO_SPACE_ON_DEVICE": {
585+
Regexp: re(`.*docker.*No space left on device.*`),
586+
Advice: `Try at least one of the following to free up space on the device:
587+
588+
1. Run "docker system prune" to remove unused docker data
589+
2. Increase the amount of memory allocated to Docker for Desktop via
590+
Docker icon > Preferences > Resources > Disk Image Size
591+
3. Run "minikube ssh -- docker system prune" if using the docker container runtime
592+
`,
593+
Issues: []int{9024},
594+
},
595+
}

pkg/minikube/problem/problem.go

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func FromError(err error, goos string) *Problem {
104104
netProblems,
105105
deployProblems,
106106
stateProblems,
107+
dockerProblems,
107108
}
108109

109110
var osMatch *Problem

0 commit comments

Comments
 (0)