@@ -18,6 +18,9 @@ limitations under the License.
1818package storage
1919
2020import (
21+ "encoding/json"
22+ "fmt"
23+
2124 corev1 "k8s.io/api/core/v1"
2225)
2326
@@ -142,21 +145,19 @@ func (v *VolMounts) Propagate(svc []PropagationType) []VolMounts {
142145 return vl
143146}
144147
145- // ConvertVolumeSource function to convert from a VolumeSource to a corev1.VolumeSource
146- func ConvertVolumeSource (v * VolumeSource ) corev1.VolumeSource {
147- return corev1.VolumeSource {
148- HostPath : v .HostPath ,
149- EmptyDir : v .EmptyDir ,
150- Secret : v .Secret ,
151- NFS : v .NFS ,
152- ISCSI : v .ISCSI ,
153- PersistentVolumeClaim : v .PersistentVolumeClaim ,
154- CephFS : v .CephFS ,
155- DownwardAPI : v .DownwardAPI ,
156- FC : v .FC ,
157- ConfigMap : v .ConfigMap ,
158- ScaleIO : v .ScaleIO ,
159- StorageOS : v .StorageOS ,
160- CSI : v .CSI ,
148+ // ToCoreVolumeSource - convert VolumeSource to corev1.VolumeSource
149+ func (s * VolumeSource ) ToCoreVolumeSource () (* corev1.VolumeSource , error ) {
150+ coreVolumeSource := & corev1.VolumeSource {}
151+
152+ coreVolumeBytes , err := json .Marshal (s )
153+ if err != nil {
154+ return nil , fmt .Errorf ("error marshalling VolumeSource: %w" , err )
161155 }
156+
157+ err = json .Unmarshal (coreVolumeBytes , coreVolumeSource )
158+ if err != nil {
159+ return nil , fmt .Errorf ("error unmarshalling VolumeSource: %w" , err )
160+ }
161+
162+ return coreVolumeSource , nil
162163}
0 commit comments