Skip to content

Commit

Permalink
fix(cleaner): add /dev mount to cleanup job (#649)
Browse files Browse the repository at this point in the history
mount /dev directory from host inside the container, so that wipefs
performed on the disk generates a corresponding udev change event and
the change is reflected on the host also.

Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm authored and kmova committed Sep 24, 2021
1 parent 6745dcf commit 3c8aabd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/649-akhilerm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mount /dev directory from host inside container so that wipefs gets reflected immediately on the host
16 changes: 13 additions & 3 deletions pkg/cleaner/jobcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package cleaner
import (
"context"
"fmt"

"github.com/openebs/node-disk-manager/api/v1alpha1"
"github.com/openebs/node-disk-manager/blockdevice"
"github.com/openebs/node-disk-manager/cmd/ndm_daemonset/controller"
Expand Down Expand Up @@ -116,14 +117,23 @@ func NewCleanupJob(bd *v1alpha1.BlockDevice, volMode VolumeMode, tolerations []v

jobContainer.Args = []string{args}

var volume v1.Volume
var volumeMount v1.VolumeMount

// in case of sparse disk, need to mount the sparse file directory
// and clear the sparse file
if bd.Spec.Details.DeviceType == blockdevice.SparseBlockDeviceType {
volume, volumeMount := getVolumeMounts(bd.Spec.Path, bd.Spec.Path, mountName)
jobContainer.VolumeMounts = []v1.VolumeMount{volumeMount}
podSpec.Volumes = []v1.Volume{volume}
volume, volumeMount = getVolumeMounts(bd.Spec.Path, bd.Spec.Path, mountName)
} else {
// for a non sparse disk, mount the /dev directory so that wipefs inside the container
// gets reflected outside the container also. When this is done a correspnding change
// event is also generated from udev
volume, volumeMount = getVolumeMounts("/dev", "/dev", mountName)
}

jobContainer.VolumeMounts = []v1.VolumeMount{volumeMount}
podSpec.Volumes = []v1.Volume{volume}

} else if volMode == VolumeModeFileSystem {
jobContainer.Command = []string{"/bin/sh", "-c"}
jobContainer.Args = []string{"find /tmp -mindepth 1 -maxdepth 1 -print0 | xargs -0 rm -rf"}
Expand Down

0 comments on commit 3c8aabd

Please sign in to comment.