11package discovery
22
3- import "context"
3+ import (
4+ "context"
5+ "log"
6+ )
47
58// VolumeInfo represents a discovered PVC volume
69type VolumeInfo struct {
@@ -22,6 +25,7 @@ type VolumeInfo struct {
2225 // Node-local info
2326 DevicePath string // resolved device path, e.g., /dev/sda
2427 DeviceName string // device name for diskstats, e.g., sda
28+ DeviceID string // major:minor device ID for diskstats lookup, e.g., "8:0"
2529 CSIDevicePath string // original CSI device path, e.g., /dev/disk/by-id/scsi-0DO_Volume_...
2630 MountPath string // host path, e.g., /var/lib/kubelet/pods/.../volumes/...
2731 ContainerMountPath string // path inside container, e.g., /data
@@ -51,28 +55,37 @@ func NewMultiDiscoverer(discoverers ...Discoverer) *MultiDiscoverer {
5155
5256// Discover tries all discoverers and returns merged results
5357func (m * MultiDiscoverer ) Discover (ctx context.Context ) ([]* VolumeInfo , error ) {
54- seen := make (map [string ]* VolumeInfo ) // key by device name
58+ seen := make (map [string ]* VolumeInfo ) // key by device ID (preferred) or device name
5559
5660 for _ , d := range m .discoverers {
5761 if ! d .Available (ctx ) {
62+ log .Printf ("discoverer %s not available" , d .Name ())
5863 continue
5964 }
6065
6166 volumes , err := d .Discover (ctx )
6267 if err != nil {
63- // Log but continue with other discoverers
68+ log . Printf ( "discoverer %s error: %v" , d . Name (), err )
6469 continue
6570 }
6671
72+ log .Printf ("discoverer %s found %d volumes" , d .Name (), len (volumes ))
73+
6774 for _ , v := range volumes {
68- if v .DeviceName == "" {
75+ // Use device ID as key if available, otherwise device name
76+ key := v .DeviceID
77+ if key == "" {
78+ key = v .DeviceName
79+ }
80+ if key == "" {
6981 continue
7082 }
71- if existing , exists := seen [v .DeviceName ]; exists {
83+
84+ if existing , exists := seen [key ]; exists {
7285 // Merge: fill in empty fields from new discoverer
7386 mergeVolumeInfo (existing , v )
7487 } else {
75- seen [v . DeviceName ] = v
88+ seen [key ] = v
7689 }
7790 }
7891 }
@@ -119,6 +132,9 @@ func mergeVolumeInfo(dst, src *VolumeInfo) {
119132 if dst .DevicePath == "" {
120133 dst .DevicePath = src .DevicePath
121134 }
135+ if dst .DeviceID == "" {
136+ dst .DeviceID = src .DeviceID
137+ }
122138 if dst .CSIDevicePath == "" {
123139 dst .CSIDevicePath = src .CSIDevicePath
124140 }
0 commit comments