@@ -17,6 +17,8 @@ limitations under the License.
17
17
package image
18
18
19
19
import (
20
+ "fmt"
21
+
20
22
v1 "k8s.io/api/core/v1"
21
23
"k8s.io/apimachinery/pkg/types"
22
24
"k8s.io/kubernetes/pkg/volume"
@@ -28,7 +30,6 @@ import (
28
30
// feature "ImageVolume"
29
31
// See: https://kep.k8s.io/4639
30
32
type imagePlugin struct {
31
- spec * volume.Spec
32
33
volume.MetricsNil
33
34
}
34
35
@@ -44,9 +45,16 @@ func ProbeVolumePlugins() []volume.VolumePlugin {
44
45
return []volume.VolumePlugin {p }
45
46
}
46
47
47
- func (o * imagePlugin ) Init (volume.VolumeHost ) error { return nil }
48
- func (o * imagePlugin ) GetPluginName () string { return pluginName }
49
- func (o * imagePlugin ) GetVolumeName (spec * volume.Spec ) (string , error ) { return o .spec .Name (), nil }
48
+ func (o * imagePlugin ) Init (volume.VolumeHost ) error { return nil }
49
+ func (o * imagePlugin ) GetPluginName () string { return pluginName }
50
+ func (o * imagePlugin ) GetVolumeName (spec * volume.Spec ) (string , error ) {
51
+ volumeSource := getVolumeSource (spec )
52
+ if volumeSource == nil {
53
+ return "" , fmt .Errorf ("the volumeSpec does not reference an Image volume type" )
54
+ }
55
+
56
+ return volumeSource .Reference , nil
57
+ }
50
58
51
59
func (o * imagePlugin ) CanSupport (spec * volume.Spec ) bool {
52
60
return spec != nil && spec .Volume != nil && spec .Volume .Image != nil
@@ -61,7 +69,7 @@ func (o *imagePlugin) NewUnmounter(name string, podUID types.UID) (volume.Unmoun
61
69
}
62
70
63
71
func (o * imagePlugin ) ConstructVolumeSpec (volumeName , mountPath string ) (volume.ReconstructedVolume , error ) {
64
- return volume.ReconstructedVolume {Spec : o . spec }, nil
72
+ return volume.ReconstructedVolume {}, nil
65
73
}
66
74
67
75
func (o * imagePlugin ) GetAttributes () volume.Attributes {
@@ -81,3 +89,10 @@ func (o *imagePlugin) SupportsMountOption() bool
81
89
func (o * imagePlugin ) SupportsSELinuxContextMount (spec * volume.Spec ) (bool , error ) { return false , nil }
82
90
func (o * imagePlugin ) TearDown () error { return nil }
83
91
func (o * imagePlugin ) TearDownAt (string ) error { return nil }
92
+
93
+ func getVolumeSource (spec * volume.Spec ) * v1.ImageVolumeSource {
94
+ if spec == nil || spec .Volume == nil {
95
+ return nil
96
+ }
97
+ return spec .Volume .Image
98
+ }
0 commit comments