mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
Merge pull request #125165 from carlory/clean-volume-util
remove unused functions in volume/util
This commit is contained in:
commit
ce961fdc84
@ -22,12 +22,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
storage "k8s.io/api/storage/v1"
|
|
||||||
"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"
|
||||||
apiruntime "k8s.io/apimachinery/pkg/runtime"
|
apiruntime "k8s.io/apimachinery/pkg/runtime"
|
||||||
@ -36,7 +34,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
storagehelpers "k8s.io/component-helpers/storage/volume"
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||||
@ -46,7 +43,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/volume/util/types"
|
"k8s.io/kubernetes/pkg/volume/util/types"
|
||||||
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler"
|
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler"
|
||||||
"k8s.io/mount-utils"
|
"k8s.io/mount-utils"
|
||||||
utilexec "k8s.io/utils/exec"
|
|
||||||
"k8s.io/utils/io"
|
"k8s.io/utils/io"
|
||||||
utilstrings "k8s.io/utils/strings"
|
utilstrings "k8s.io/utils/strings"
|
||||||
)
|
)
|
||||||
@ -111,22 +107,6 @@ func SetReady(dir string) {
|
|||||||
file.Close()
|
file.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSecretForPod locates secret by name in the pod's namespace and returns secret map
|
|
||||||
func GetSecretForPod(pod *v1.Pod, secretName string, kubeClient clientset.Interface) (map[string]string, error) {
|
|
||||||
secret := make(map[string]string)
|
|
||||||
if kubeClient == nil {
|
|
||||||
return secret, fmt.Errorf("cannot get kube client")
|
|
||||||
}
|
|
||||||
secrets, err := kubeClient.CoreV1().Secrets(pod.Namespace).Get(context.TODO(), secretName, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
|
||||||
return secret, err
|
|
||||||
}
|
|
||||||
for name, data := range secrets.Data {
|
|
||||||
secret[name] = string(data)
|
|
||||||
}
|
|
||||||
return secret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSecretForPV locates secret by name and namespace, verifies the secret type, and returns secret map
|
// GetSecretForPV locates secret by name and namespace, verifies the secret type, and returns secret map
|
||||||
func GetSecretForPV(secretNamespace, secretName, volumePluginName string, kubeClient clientset.Interface) (map[string]string, error) {
|
func GetSecretForPV(secretNamespace, secretName, volumePluginName string, kubeClient clientset.Interface) (map[string]string, error) {
|
||||||
secret := make(map[string]string)
|
secret := make(map[string]string)
|
||||||
@ -146,23 +126,6 @@ func GetSecretForPV(secretNamespace, secretName, volumePluginName string, kubeCl
|
|||||||
return secret, nil
|
return secret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetClassForVolume locates storage class by persistent volume
|
|
||||||
func GetClassForVolume(kubeClient clientset.Interface, pv *v1.PersistentVolume) (*storage.StorageClass, error) {
|
|
||||||
if kubeClient == nil {
|
|
||||||
return nil, fmt.Errorf("cannot get kube client")
|
|
||||||
}
|
|
||||||
className := storagehelpers.GetPersistentVolumeClass(pv)
|
|
||||||
if className == "" {
|
|
||||||
return nil, fmt.Errorf("volume has no storage class")
|
|
||||||
}
|
|
||||||
|
|
||||||
class, err := kubeClient.StorageV1().StorageClasses().Get(context.TODO(), className, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return class, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// LoadPodFromFile will read, decode, and return a Pod from a file.
|
// LoadPodFromFile will read, decode, and return a Pod from a file.
|
||||||
func LoadPodFromFile(filePath string) (*v1.Pod, error) {
|
func LoadPodFromFile(filePath string) (*v1.Pod, error) {
|
||||||
if filePath == "" {
|
if filePath == "" {
|
||||||
@ -538,13 +501,6 @@ func UnmapBlockVolume(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPluginMountDir returns the global mount directory name appended
|
|
||||||
// to the given plugin name's plugin directory
|
|
||||||
func GetPluginMountDir(host volume.VolumeHost, name string) string {
|
|
||||||
mntDir := filepath.Join(host.GetPluginDir(name), MountsInGlobalPDPath)
|
|
||||||
return mntDir
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsLocalEphemeralVolume determines whether the argument is a local ephemeral
|
// IsLocalEphemeralVolume determines whether the argument is a local ephemeral
|
||||||
// volume vs. some other type
|
// volume vs. some other type
|
||||||
// Local means the volume is using storage from the local disk that is managed by kubelet.
|
// Local means the volume is using storage from the local disk that is managed by kubelet.
|
||||||
@ -684,25 +640,6 @@ func HasMountRefs(mountPath string, mountRefs []string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteVolumeCache flush disk data given the specified mount path
|
|
||||||
func WriteVolumeCache(deviceMountPath string, exec utilexec.Interface) error {
|
|
||||||
// If runtime os is windows, execute Write-VolumeCache powershell command on the disk
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
cmdString := "Get-Volume -FilePath $env:mountpath | Write-Volumecache"
|
|
||||||
cmd := exec.Command("powershell", "/c", cmdString)
|
|
||||||
env := append(os.Environ(), fmt.Sprintf("mountpath=%s", deviceMountPath))
|
|
||||||
cmd.SetEnv(env)
|
|
||||||
klog.V(8).Infof("Executing command: %q", cmdString)
|
|
||||||
output, err := cmd.CombinedOutput()
|
|
||||||
klog.Infof("command (%q) execeuted: %v, output: %q", cmdString, err, string(output))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("command (%q) failed: %v, output: %q", cmdString, err, string(output))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// For linux runtime, it skips because unmount will automatically flush disk data
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsMultiAttachAllowed checks if attaching this volume to multiple nodes is definitely not allowed/possible.
|
// IsMultiAttachAllowed checks if attaching this volume to multiple nodes is definitely not allowed/possible.
|
||||||
// In its current form, this function can only reliably say for which volumes it's definitely forbidden. If it returns
|
// In its current form, this function can only reliably say for which volumes it's definitely forbidden. If it returns
|
||||||
// false, it is not guaranteed that multi-attach is actually supported by the volume type and we must rely on the
|
// false, it is not guaranteed that multi-attach is actually supported by the volume type and we must rely on the
|
||||||
|
Loading…
Reference in New Issue
Block a user