@@ -39,57 +39,67 @@ import (
39
39
// A volume.Spec that refers to an in-tree plugin spec is translated to refer
40
40
// to a migrated CSI plugin spec if all conditions for CSI migration on a node
41
41
// for the in-tree plugin is satisfied.
42
- func CreateVolumeSpec (podVolume v1.Volume , podNamespace string , nodeName types.NodeName , vpm * volume.VolumePluginMgr , pvcLister corelisters.PersistentVolumeClaimLister , pvLister corelisters.PersistentVolumeLister , csiMigratedPluginManager csimigration.PluginManager , csiTranslator csimigration.InTreeToCSITranslator ) (* volume.Spec , error ) {
42
+ func CreateVolumeSpec (podVolume v1.Volume , pod * v1.Pod , nodeName types.NodeName , vpm * volume.VolumePluginMgr , pvcLister corelisters.PersistentVolumeClaimLister , pvLister corelisters.PersistentVolumeLister , csiMigratedPluginManager csimigration.PluginManager , csiTranslator csimigration.InTreeToCSITranslator ) (* volume.Spec , error ) {
43
+ claimName := ""
44
+ readOnly := false
43
45
if pvcSource := podVolume .VolumeSource .PersistentVolumeClaim ; pvcSource != nil {
46
+ claimName = pvcSource .ClaimName
47
+ readOnly = pvcSource .ReadOnly
48
+ }
49
+ if ephemeralSource := podVolume .VolumeSource .Ephemeral ; ephemeralSource != nil && utilfeature .DefaultFeatureGate .Enabled (features .GenericEphemeralVolume ) {
50
+ claimName = pod .Name + "-" + podVolume .Name
51
+ readOnly = ephemeralSource .ReadOnly
52
+ }
53
+ if claimName != "" {
44
54
klog .V (10 ).Infof (
45
55
"Found PVC, ClaimName: %q/%q" ,
46
- podNamespace ,
47
- pvcSource . ClaimName )
56
+ pod . Namespace ,
57
+ claimName )
48
58
49
59
// If podVolume is a PVC, fetch the real PV behind the claim
50
60
pvName , pvcUID , err := getPVCFromCacheExtractPV (
51
- podNamespace , pvcSource . ClaimName , pvcLister )
61
+ pod . Namespace , claimName , pvcLister )
52
62
if err != nil {
53
63
return nil , fmt .Errorf (
54
64
"error processing PVC %q/%q: %v" ,
55
- podNamespace ,
56
- pvcSource . ClaimName ,
65
+ pod . Namespace ,
66
+ claimName ,
57
67
err )
58
68
}
59
69
60
70
klog .V (10 ).Infof (
61
71
"Found bound PV for PVC (ClaimName %q/%q pvcUID %v): pvName=%q" ,
62
- podNamespace ,
63
- pvcSource . ClaimName ,
72
+ pod . Namespace ,
73
+ claimName ,
64
74
pvcUID ,
65
75
pvName )
66
76
67
77
// Fetch actual PV object
68
78
volumeSpec , err := getPVSpecFromCache (
69
- pvName , pvcSource . ReadOnly , pvcUID , pvLister )
79
+ pvName , readOnly , pvcUID , pvLister )
70
80
if err != nil {
71
81
return nil , fmt .Errorf (
72
82
"error processing PVC %q/%q: %v" ,
73
- podNamespace ,
74
- pvcSource . ClaimName ,
83
+ pod . Namespace ,
84
+ claimName ,
75
85
err )
76
86
}
77
87
78
88
volumeSpec , err = translateInTreeSpecToCSIIfNeeded (volumeSpec , nodeName , vpm , csiMigratedPluginManager , csiTranslator )
79
89
if err != nil {
80
90
return nil , fmt .Errorf (
81
91
"error performing CSI migration checks and translation for PVC %q/%q: %v" ,
82
- podNamespace ,
83
- pvcSource . ClaimName ,
92
+ pod . Namespace ,
93
+ claimName ,
84
94
err )
85
95
}
86
96
87
97
klog .V (10 ).Infof (
88
98
"Extracted volumeSpec (%v) from bound PV (pvName %q) and PVC (ClaimName %q/%q pvcUID %v)" ,
89
99
volumeSpec .Name (),
90
100
pvName ,
91
- podNamespace ,
92
- pvcSource . ClaimName ,
101
+ pod . Namespace ,
102
+ claimName ,
93
103
pvcUID )
94
104
95
105
return volumeSpec , nil
@@ -219,7 +229,7 @@ func ProcessPodVolumes(pod *v1.Pod, addVolumes bool, desiredStateOfWorld cache.D
219
229
220
230
// Process volume spec for each volume defined in pod
221
231
for _ , podVolume := range pod .Spec .Volumes {
222
- volumeSpec , err := CreateVolumeSpec (podVolume , pod . Namespace , nodeName , volumePluginMgr , pvcLister , pvLister , csiMigratedPluginManager , csiTranslator )
232
+ volumeSpec , err := CreateVolumeSpec (podVolume , pod , nodeName , volumePluginMgr , pvcLister , pvLister , csiMigratedPluginManager , csiTranslator )
223
233
if err != nil {
224
234
klog .V (10 ).Infof (
225
235
"Error processing volume %q for pod %q/%q: %v" ,
0 commit comments