mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #111083 from nixpanic/mount-utils/no-systemd
mount-utils: only detect systemd when needed
This commit is contained in:
commit
a35c1f37b6
@ -58,7 +58,7 @@ const (
|
||||
// kubelet is running in the host's root mount namespace.
|
||||
type Mounter struct {
|
||||
mounterPath string
|
||||
withSystemd bool
|
||||
withSystemd *bool
|
||||
withSafeNotMountedBehavior bool
|
||||
}
|
||||
|
||||
@ -70,11 +70,21 @@ var _ MounterForceUnmounter = &Mounter{}
|
||||
func New(mounterPath string) Interface {
|
||||
return &Mounter{
|
||||
mounterPath: mounterPath,
|
||||
withSystemd: detectSystemd(),
|
||||
withSafeNotMountedBehavior: detectSafeNotMountedBehavior(),
|
||||
}
|
||||
}
|
||||
|
||||
// hasSystemd validates that the withSystemd bool is set, if it is not,
|
||||
// detectSystemd will be called once for this Mounter instance.
|
||||
func (mounter *Mounter) hasSystemd() bool {
|
||||
if mounter.withSystemd == nil {
|
||||
withSystemd := detectSystemd()
|
||||
mounter.withSystemd = &withSystemd
|
||||
}
|
||||
|
||||
return *mounter.withSystemd
|
||||
}
|
||||
|
||||
// Mount mounts source to target as fstype with given options. 'source' and 'fstype' must
|
||||
// be an empty string in case it's not required, e.g. for remount, or for auto filesystem
|
||||
// type, where kernel handles fstype for you. The mount 'options' is a list of options,
|
||||
@ -154,7 +164,7 @@ func (mounter *Mounter) doMount(mounterPath string, mountCmd string, source stri
|
||||
mountCmd = mounterPath
|
||||
}
|
||||
|
||||
if mounter.withSystemd && systemdMountRequired {
|
||||
if mounter.hasSystemd() && systemdMountRequired {
|
||||
// Try to run mount via systemd-run --scope. This will escape the
|
||||
// service where kubelet runs and any fuse daemons will be started in a
|
||||
// specific scope. kubelet service than can be restarted without killing
|
||||
|
@ -525,6 +525,14 @@ func TestSensitiveMountOptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasSystemd(t *testing.T) {
|
||||
mounter := &Mounter{}
|
||||
_ = mounter.hasSystemd()
|
||||
if mounter.withSystemd == nil {
|
||||
t.Error("Failed to run detectSystemd()")
|
||||
}
|
||||
}
|
||||
|
||||
func mountArgsContainString(t *testing.T, mountArgs []string, wanted string) bool {
|
||||
for _, mountArg := range mountArgs {
|
||||
if mountArg == wanted {
|
||||
|
Loading…
Reference in New Issue
Block a user