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

Fixes #4318 - k0s reset should not delete all when drives fail to unmount #5132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions pkg/cleanup/directories.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,29 @@ func (d *directories) Run() error {
}

var dataDirMounted bool
allKubeletsUnmounted := true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like it if the logic was flipped so that the two bools work the same way.

So, something like:

var kubeletDirsMounted bool

Then set it to true if unmount fails.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the dataDirMounted variable only appears to control logging, not functional.


// search and unmount kubelet volume mounts
for _, v := range procMounts {
if v.Path == filepath.Join(d.Config.dataDir, "kubelet") {
logrus.Debugf("%v is mounted! attempting to unmount...", v.Path)
if err = mounter.Unmount(v.Path); err != nil {
allKubeletsUnmounted = false
logrus.Warningf("failed to unmount %v", v.Path)
}
} else if v.Path == d.Config.dataDir {
dataDirMounted = true
}
}

if !allKubeletsUnmounted {
if dataDirMounted {
return fmt.Errorf("unable to remove the contents of mounted data-dir (%s) as not all mounts could be unmounted", d.Config.dataDir)
} else {
return fmt.Errorf("unable to remove k0s generated data-dir (%s) as not all mounts could be unmounted", d.Config.dataDir)
}
}

if dataDirMounted {
logrus.Debugf("removing the contents of mounted data-dir (%s)", d.Config.dataDir)
} else {
Expand Down
Loading