mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Merge pull request #119829 from cvvz/fix-volumemanager-logs
fix: implement MarshalLog for structures in volumemanager for structured-logging.
This commit is contained in:
commit
a08ee80807
@ -23,6 +23,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-logr/logr"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
@ -37,6 +38,12 @@ import (
|
|||||||
utilstrings "k8s.io/utils/strings"
|
utilstrings "k8s.io/utils/strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// these interfaces are necessary to keep the structures private
|
||||||
|
// and at the same time log them correctly in structured logs.
|
||||||
|
var _ logr.Marshaler = podVolume{}
|
||||||
|
var _ logr.Marshaler = reconstructedVolume{}
|
||||||
|
var _ logr.Marshaler = globalVolumeInfo{}
|
||||||
|
|
||||||
type podVolume struct {
|
type podVolume struct {
|
||||||
podName volumetypes.UniquePodName
|
podName volumetypes.UniquePodName
|
||||||
volumeSpecName string
|
volumeSpecName string
|
||||||
@ -45,6 +52,22 @@ type podVolume struct {
|
|||||||
volumeMode v1.PersistentVolumeMode
|
volumeMode v1.PersistentVolumeMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p podVolume) MarshalLog() interface{} {
|
||||||
|
return struct {
|
||||||
|
PodName string `json:"podName"`
|
||||||
|
VolumeSpecName string `json:"volumeSpecName"`
|
||||||
|
VolumePath string `json:"volumePath"`
|
||||||
|
PluginName string `json:"pluginName"`
|
||||||
|
VolumeMode string `json:"volumeMode"`
|
||||||
|
}{
|
||||||
|
PodName: string(p.podName),
|
||||||
|
VolumeSpecName: p.volumeSpecName,
|
||||||
|
VolumePath: p.volumePath,
|
||||||
|
PluginName: p.pluginName,
|
||||||
|
VolumeMode: string(p.volumeMode),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type reconstructedVolume struct {
|
type reconstructedVolume struct {
|
||||||
volumeName v1.UniqueVolumeName
|
volumeName v1.UniqueVolumeName
|
||||||
podName volumetypes.UniquePodName
|
podName volumetypes.UniquePodName
|
||||||
@ -59,6 +82,28 @@ type reconstructedVolume struct {
|
|||||||
seLinuxMountContext string
|
seLinuxMountContext string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rv reconstructedVolume) MarshalLog() interface{} {
|
||||||
|
return struct {
|
||||||
|
VolumeName string `json:"volumeName"`
|
||||||
|
PodName string `json:"podName"`
|
||||||
|
VolumeSpecName string `json:"volumeSpecName"`
|
||||||
|
OuterVolumeSpecName string `json:"outerVolumeSpecName"`
|
||||||
|
PodUID string `json:"podUID"`
|
||||||
|
VolumeGIDValue string `json:"volumeGIDValue"`
|
||||||
|
DevicePath string `json:"devicePath"`
|
||||||
|
SeLinuxMountContext string `json:"seLinuxMountContext"`
|
||||||
|
}{
|
||||||
|
VolumeName: string(rv.volumeName),
|
||||||
|
PodName: string(rv.podName),
|
||||||
|
VolumeSpecName: rv.volumeSpec.Name(),
|
||||||
|
OuterVolumeSpecName: rv.outerVolumeSpecName,
|
||||||
|
PodUID: string(rv.pod.UID),
|
||||||
|
VolumeGIDValue: rv.volumeGidValue,
|
||||||
|
DevicePath: rv.devicePath,
|
||||||
|
SeLinuxMountContext: rv.seLinuxMountContext,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// globalVolumeInfo stores reconstructed volume information
|
// globalVolumeInfo stores reconstructed volume information
|
||||||
// for each pod that was using that volume.
|
// for each pod that was using that volume.
|
||||||
type globalVolumeInfo struct {
|
type globalVolumeInfo struct {
|
||||||
@ -71,6 +116,25 @@ type globalVolumeInfo struct {
|
|||||||
podVolumes map[volumetypes.UniquePodName]*reconstructedVolume
|
podVolumes map[volumetypes.UniquePodName]*reconstructedVolume
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gvi globalVolumeInfo) MarshalLog() interface{} {
|
||||||
|
podVolumes := make(map[volumetypes.UniquePodName]v1.UniqueVolumeName)
|
||||||
|
for podName, volume := range gvi.podVolumes {
|
||||||
|
podVolumes[podName] = volume.volumeName
|
||||||
|
}
|
||||||
|
|
||||||
|
return struct {
|
||||||
|
VolumeName string `json:"volumeName"`
|
||||||
|
VolumeSpecName string `json:"volumeSpecName"`
|
||||||
|
DevicePath string `json:"devicePath"`
|
||||||
|
PodVolumes map[volumetypes.UniquePodName]v1.UniqueVolumeName `json:"podVolumes"`
|
||||||
|
}{
|
||||||
|
VolumeName: string(gvi.volumeName),
|
||||||
|
VolumeSpecName: gvi.volumeSpec.Name(),
|
||||||
|
DevicePath: gvi.devicePath,
|
||||||
|
PodVolumes: podVolumes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (rc *reconciler) updateLastSyncTime() {
|
func (rc *reconciler) updateLastSyncTime() {
|
||||||
rc.timeOfLastSyncLock.Lock()
|
rc.timeOfLastSyncLock.Lock()
|
||||||
defer rc.timeOfLastSyncLock.Unlock()
|
defer rc.timeOfLastSyncLock.Unlock()
|
||||||
@ -181,7 +245,9 @@ func getVolumesFromPodDir(podDir string) ([]podVolume, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
klog.V(4).InfoS("Get volumes from pod directory", "path", podDir, "volumes", volumes)
|
for _, volume := range volumes {
|
||||||
|
klog.V(4).InfoS("Get volume from pod directory", "path", podDir, "volume", volume)
|
||||||
|
}
|
||||||
return volumes, nil
|
return volumes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user