Skip to content

Commit

Permalink
A custom slimmed down version of VolumeSource
Browse files Browse the repository at this point in the history
Slim down VolumeSource by removing deprecated and "removed"
fields from the struct. This will slim down our nested
use of ExtraMounts

Also, adds ConvertVolumeSource function to the storage module
which converts from VolumeSource to a corev1.VolumeSource
  • Loading branch information
dprince committed Oct 16, 2024
1 parent e5c35d2 commit e3abf73
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 4 deletions.
93 changes: 92 additions & 1 deletion modules/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// +kubebuilder:object:generate:=true

package storage

Expand Down Expand Up @@ -40,6 +41,74 @@ const (
Compute PropagationType = "Compute"
)

// VolumeSource our slimmed down version of the VolumeSource struct with deprecated and "removed" fields removed to save space
type VolumeSource struct {
HostPath *corev1.HostPathVolumeSource `json:"hostPath,omitempty" protobuf:"bytes,1,opt,name=hostPath"`
// emptyDir represents a temporary directory that shares a pod's lifetime.
// More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir
// +optional
EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty" protobuf:"bytes,2,opt,name=emptyDir"`
// secret represents a secret that should populate this volume.
// More info: https://kubernetes.io/docs/concepts/storage/volumes#secret
// +optional
Secret *corev1.SecretVolumeSource `json:"secret,omitempty" protobuf:"bytes,6,opt,name=secret"`
// nfs represents an NFS mount on the host that shares a pod's lifetime
// More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs
// +optional
NFS *corev1.NFSVolumeSource `json:"nfs,omitempty" protobuf:"bytes,7,opt,name=nfs"`
// iscsi represents an ISCSI Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
// More info: https://examples.k8s.io/volumes/iscsi/README.md
// +optional
ISCSI *corev1.ISCSIVolumeSource `json:"iscsi,omitempty" protobuf:"bytes,8,opt,name=iscsi"`
// persistentVolumeClaimVolumeSource represents a reference to a
// PersistentVolumeClaim in the same namespace.
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
// +optional
PersistentVolumeClaim *corev1.PersistentVolumeClaimVolumeSource `json:"persistentVolumeClaim,omitempty" protobuf:"bytes,10,opt,name=persistentVolumeClaim"`
// cephFS represents a Ceph FS mount on the host that shares a pod's lifetime
// +optional
CephFS *corev1.CephFSVolumeSource `json:"cephfs,omitempty" protobuf:"bytes,14,opt,name=cephfs"`
// downwardAPI represents downward API about the pod that should populate this volume
// +optional
DownwardAPI *corev1.DownwardAPIVolumeSource `json:"downwardAPI,omitempty" protobuf:"bytes,16,opt,name=downwardAPI"`
// fc represents a Fibre Channel resource that is attached to a kubelet's host machine and then exposed to the pod.
// +optional
FC *corev1.FCVolumeSource `json:"fc,omitempty" protobuf:"bytes,17,opt,name=fc"`
// configMap represents a configMap that should populate this volume
// +optional
ConfigMap *corev1.ConfigMapVolumeSource `json:"configMap,omitempty" protobuf:"bytes,19,opt,name=configMap"`
// photonPersistentDisk represents a PhotonController persistent disk attached and mounted on kubelets host machine
PhotonPersistentDisk *corev1.PhotonPersistentDiskVolumeSource `json:"photonPersistentDisk,omitempty" protobuf:"bytes,23,opt,name=photonPersistentDisk"`
// projected items for all in one resources secrets, configmaps, and downward API
Projected *corev1.ProjectedVolumeSource `json:"projected,omitempty" protobuf:"bytes,26,opt,name=projected"`
// scaleIO represents a ScaleIO persistent volume attached and mounted on Kubernetes nodes.
// +optional
ScaleIO *corev1.ScaleIOVolumeSource `json:"scaleIO,omitempty" protobuf:"bytes,25,opt,name=scaleIO"`
// storageOS represents a StorageOS volume attached and mounted on Kubernetes nodes.
// +optional
StorageOS *corev1.StorageOSVolumeSource `json:"storageos,omitempty" protobuf:"bytes,27,opt,name=storageos"`
// csi (Container Storage Interface) represents ephemeral storage that is handled by certain external CSI drivers (Beta feature).
// +optional
CSI *corev1.CSIVolumeSource `json:"csi,omitempty" protobuf:"bytes,28,opt,name=csi"`
// ephemeral represents a volume that is handled by a cluster storage driver.
// The volume's lifecycle is tied to the pod that defines it - it will be created before the pod starts,
// and deleted when the pod is removed.
//
// +optional
Ephemeral *corev1.EphemeralVolumeSource `json:"ephemeral,omitempty" protobuf:"bytes,29,opt,name=ephemeral"`
}

// Volume our slimmed down version of Volume
type Volume struct {
// +kubebuilder:validation:Required
// Name of the volume
Name string `json:"name"`
// +kubebuilder:validation:Required
// VolumeSource defines the source of a volume to be mounted
VolumeSource VolumeSource `json:"volumeSource"`
}

// VolMounts is the data structure used to expose Volumes and Mounts that can
// be added to a pod according to the defined Propagation policy
type VolMounts struct {
Expand All @@ -50,7 +119,7 @@ type VolMounts struct {
// +kubebuilder:validation:Optional
ExtraVolType ExtraVolType `json:"extraVolType,omitempty"`
// +kubebuilder:validation:Required
Volumes []corev1.Volume `json:"volumes"`
Volumes []Volume `json:"volumes"`
// +kubebuilder:validation:Required
Mounts []corev1.VolumeMount `json:"mounts"`
}
Expand Down Expand Up @@ -82,3 +151,25 @@ func (v *VolMounts) Propagate(svc []PropagationType) []VolMounts {

return vl
}

// ConvertVolumeSource function to convert from a VolumeSource to a corev1.VolumeSource
func ConvertVolumeSource(v *VolumeSource) corev1.VolumeSource {
return corev1.VolumeSource{
HostPath: v.HostPath,
EmptyDir: v.EmptyDir,
Secret: v.Secret,
NFS: v.NFS,
ISCSI: v.ISCSI,
PersistentVolumeClaim: v.PersistentVolumeClaim,
CephFS: v.CephFS,
DownwardAPI: v.DownwardAPI,
FC: v.FC,
ConfigMap: v.ConfigMap,
PhotonPersistentDisk: v.PhotonPersistentDisk,
Projected: v.Projected,
ScaleIO: v.ScaleIO,
StorageOS: v.StorageOS,
CSI: v.CSI,
Ephemeral: v.Ephemeral,
}
}
122 changes: 119 additions & 3 deletions modules/storage/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e3abf73

Please sign in to comment.