Unify determination of whether a volume is ephemeral

This commit is contained in:
Shintaro Murakami
2021-03-05 14:25:51 +09:00
parent 96be00df69
commit fe7a862c2d
3 changed files with 8 additions and 14 deletions

View File

@@ -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
}