mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #83591 from jingxu97/Oct/cache
Flush data cache during unmount device for GCE-PD in Windows
This commit is contained in:
commit
18cef954a1
@ -384,6 +384,14 @@ func (detacher *gcePersistentDiskDetacher) Detach(volumeName string, nodeName ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (detacher *gcePersistentDiskDetacher) UnmountDevice(deviceMountPath string) error {
|
func (detacher *gcePersistentDiskDetacher) UnmountDevice(deviceMountPath string) error {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
// Flush data cache for windows because it does not do so automatically during unmount device
|
||||||
|
exec := detacher.host.GetExec(gcePersistentDiskPluginName)
|
||||||
|
err := volumeutil.WriteVolumeCache(deviceMountPath, exec)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return mount.CleanupMountPoint(deviceMountPath, detacher.host.GetMounter(gcePersistentDiskPluginName), false)
|
return mount.CleanupMountPoint(deviceMountPath, detacher.host.GetMounter(gcePersistentDiskPluginName), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
@ -29,7 +30,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
apiruntime "k8s.io/apimachinery/pkg/runtime"
|
||||||
utypes "k8s.io/apimachinery/pkg/types"
|
utypes "k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
@ -196,7 +197,7 @@ func LoadPodFromFile(filePath string) (*v1.Pod, error) {
|
|||||||
pod := &v1.Pod{}
|
pod := &v1.Pod{}
|
||||||
|
|
||||||
codec := legacyscheme.Codecs.UniversalDecoder()
|
codec := legacyscheme.Codecs.UniversalDecoder()
|
||||||
if err := runtime.DecodeInto(codec, podDef, pod); err != nil {
|
if err := apiruntime.DecodeInto(codec, podDef, pod); err != nil {
|
||||||
return nil, fmt.Errorf("failed decoding file: %v", err)
|
return nil, fmt.Errorf("failed decoding file: %v", err)
|
||||||
}
|
}
|
||||||
return pod, nil
|
return pod, nil
|
||||||
@ -582,3 +583,18 @@ func HasMountRefs(mountPath string, mountRefs []string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WriteVolumeCache flush disk data given the spcified mount path
|
||||||
|
func WriteVolumeCache(deviceMountPath string, exec mount.Exec) error {
|
||||||
|
// If runtime os is windows, execute Write-VolumeCache powershell command on the disk
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
cmd := fmt.Sprintf("Get-Volume -FilePath %s | Write-Volumecache", deviceMountPath)
|
||||||
|
output, err := exec.Run("powershell", "/c", cmd)
|
||||||
|
klog.Infof("command (%q) execeuted: %v, output: %q", cmd, err, string(output))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("command (%q) failed: %v, output: %q", cmd, err, string(output))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// For linux runtime, it skips because unmount will automatically flush disk data
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user