mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Unify determination of whether a volume is ephemeral
This commit is contained in:
parent
96be00df69
commit
fe7a862c2d
@ -31,6 +31,7 @@ import (
|
||||
v1resource "k8s.io/kubernetes/pkg/api/v1/resource"
|
||||
evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
volumeutils "k8s.io/kubernetes/pkg/volume/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -343,9 +344,7 @@ func localVolumeNames(pod *v1.Pod) []string {
|
||||
result := []string{}
|
||||
for _, volume := range pod.Spec.Volumes {
|
||||
if volume.HostPath != nil ||
|
||||
(volume.EmptyDir != nil && volume.EmptyDir.Medium != v1.StorageMediumMemory) ||
|
||||
volume.ConfigMap != nil ||
|
||||
volume.GitRepo != nil {
|
||||
volumeutils.IsLocalEphemeralVolume(volume) {
|
||||
result = append(result, volume.Name)
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
stats "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
"k8s.io/kubernetes/pkg/volume/util"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
@ -122,7 +123,7 @@ func (s *volumeStatCalculator) calcAndStoreStats() {
|
||||
}
|
||||
}
|
||||
volumeStats := s.parsePodVolumeStats(name, pvcRef, metric, volSpec)
|
||||
if isVolumeEphemeral(volSpec) {
|
||||
if util.IsLocalEphemeralVolume(volSpec) {
|
||||
ephemeralStats = append(ephemeralStats, volumeStats)
|
||||
} else {
|
||||
persistentStats = append(persistentStats, volumeStats)
|
||||
@ -165,11 +166,3 @@ func (s *volumeStatCalculator) parsePodVolumeStats(podName string, pvcRef *stats
|
||||
UsedBytes: &used, Inodes: &inodes, InodesFree: &inodesFree, InodesUsed: &inodesUsed},
|
||||
}
|
||||
}
|
||||
|
||||
func isVolumeEphemeral(volume v1.Volume) bool {
|
||||
if (volume.EmptyDir != nil && volume.EmptyDir.Medium == v1.StorageMediumDefault) ||
|
||||
volume.ConfigMap != nil || volume.GitRepo != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -583,10 +583,12 @@ func GetPluginMountDir(host volume.VolumeHost, name string) string {
|
||||
|
||||
// IsLocalEphemeralVolume determines whether the argument is a local ephemeral
|
||||
// volume vs. some other type
|
||||
// Local means the volume is using storage from the local disk that is managed by kubelet.
|
||||
// Ephemeral means the lifecycle of the volume is the same as the Pod.
|
||||
func IsLocalEphemeralVolume(volume v1.Volume) bool {
|
||||
return volume.GitRepo != nil ||
|
||||
(volume.EmptyDir != nil && volume.EmptyDir.Medium != v1.StorageMediumMemory) ||
|
||||
volume.ConfigMap != nil || volume.DownwardAPI != nil
|
||||
(volume.EmptyDir != nil && volume.EmptyDir.Medium == v1.StorageMediumDefault) ||
|
||||
volume.ConfigMap != nil
|
||||
}
|
||||
|
||||
// GetPodVolumeNames returns names of volumes that are used in a pod,
|
||||
|
Loading…
Reference in New Issue
Block a user