@@ -13,10 +13,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
+ // +kubebuilder:object:generate:=true
16
17
17
18
package storage
18
19
19
20
import (
21
+ "encoding/json"
22
+ "fmt"
23
+
20
24
corev1 "k8s.io/api/core/v1"
21
25
)
22
26
@@ -40,6 +44,64 @@ const (
40
44
Compute PropagationType = "Compute"
41
45
)
42
46
47
+ // VolumeSource our slimmed down version of the VolumeSource struct with deprecated and "removed" fields removed to save space
48
+ type VolumeSource struct {
49
+ HostPath * corev1.HostPathVolumeSource `json:"hostPath,omitempty" protobuf:"bytes,1,opt,name=hostPath"`
50
+ // emptyDir represents a temporary directory that shares a pod's lifetime.
51
+ // More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir
52
+ // +optional
53
+ EmptyDir * corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty" protobuf:"bytes,2,opt,name=emptyDir"`
54
+ // secret represents a secret that should populate this volume.
55
+ // More info: https://kubernetes.io/docs/concepts/storage/volumes#secret
56
+ // +optional
57
+ Secret * corev1.SecretVolumeSource `json:"secret,omitempty" protobuf:"bytes,6,opt,name=secret"`
58
+ // nfs represents an NFS mount on the host that shares a pod's lifetime
59
+ // More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs
60
+ // +optional
61
+ NFS * corev1.NFSVolumeSource `json:"nfs,omitempty" protobuf:"bytes,7,opt,name=nfs"`
62
+ // iscsi represents an ISCSI Disk resource that is attached to a
63
+ // kubelet's host machine and then exposed to the pod.
64
+ // More info: https://examples.k8s.io/volumes/iscsi/README.md
65
+ // +optional
66
+ ISCSI * corev1.ISCSIVolumeSource `json:"iscsi,omitempty" protobuf:"bytes,8,opt,name=iscsi"`
67
+ // persistentVolumeClaimVolumeSource represents a reference to a
68
+ // PersistentVolumeClaim in the same namespace.
69
+ // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
70
+ // +optional
71
+ PersistentVolumeClaim * corev1.PersistentVolumeClaimVolumeSource `json:"persistentVolumeClaim,omitempty" protobuf:"bytes,10,opt,name=persistentVolumeClaim"`
72
+ // cephFS represents a Ceph FS mount on the host that shares a pod's lifetime
73
+ // +optional
74
+ CephFS * corev1.CephFSVolumeSource `json:"cephfs,omitempty" protobuf:"bytes,14,opt,name=cephfs"`
75
+ // downwardAPI represents downward API about the pod that should populate this volume
76
+ // +optional
77
+ DownwardAPI * corev1.DownwardAPIVolumeSource `json:"downwardAPI,omitempty" protobuf:"bytes,16,opt,name=downwardAPI"`
78
+ // fc represents a Fibre Channel resource that is attached to a kubelet's host machine and then exposed to the pod.
79
+ // +optional
80
+ FC * corev1.FCVolumeSource `json:"fc,omitempty" protobuf:"bytes,17,opt,name=fc"`
81
+ // configMap represents a configMap that should populate this volume
82
+ // +optional
83
+ ConfigMap * corev1.ConfigMapVolumeSource `json:"configMap,omitempty" protobuf:"bytes,19,opt,name=configMap"`
84
+ // scaleIO represents a ScaleIO persistent volume attached and mounted on Kubernetes nodes.
85
+ // +optional
86
+ ScaleIO * corev1.ScaleIOVolumeSource `json:"scaleIO,omitempty" protobuf:"bytes,25,opt,name=scaleIO"`
87
+ // storageOS represents a StorageOS volume attached and mounted on Kubernetes nodes.
88
+ // +optional
89
+ StorageOS * corev1.StorageOSVolumeSource `json:"storageos,omitempty" protobuf:"bytes,27,opt,name=storageos"`
90
+ // csi (Container Storage Interface) represents ephemeral storage that is handled by certain external CSI drivers (Beta feature).
91
+ // +optional
92
+ CSI * corev1.CSIVolumeSource `json:"csi,omitempty" protobuf:"bytes,28,opt,name=csi"`
93
+ }
94
+
95
+ // Volume our slimmed down version of Volume
96
+ type Volume struct {
97
+ // +kubebuilder:validation:Required
98
+ // Name of the volume
99
+ Name string `json:"name"`
100
+ // +kubebuilder:validation:Required
101
+ // VolumeSource defines the source of a volume to be mounted
102
+ VolumeSource VolumeSource `json:"volumeSource"`
103
+ }
104
+
43
105
// VolMounts is the data structure used to expose Volumes and Mounts that can
44
106
// be added to a pod according to the defined Propagation policy
45
107
type VolMounts struct {
@@ -50,7 +112,7 @@ type VolMounts struct {
50
112
// +kubebuilder:validation:Optional
51
113
ExtraVolType ExtraVolType `json:"extraVolType,omitempty"`
52
114
// +kubebuilder:validation:Required
53
- Volumes []corev1. Volume `json:"volumes"`
115
+ Volumes []Volume `json:"volumes"`
54
116
// +kubebuilder:validation:Required
55
117
Mounts []corev1.VolumeMount `json:"mounts"`
56
118
}
@@ -82,3 +144,20 @@ func (v *VolMounts) Propagate(svc []PropagationType) []VolMounts {
82
144
83
145
return vl
84
146
}
147
+
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 )
155
+ }
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
163
+ }
0 commit comments