From adc42673d5f343c2a9b2cf0e9c4655ee04f8c2da Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Mon, 14 Oct 2024 17:06:17 -0400 Subject: [PATCH] A custom slimmed down version of VolumeSource Slim down VolumeSource by removing deprecated and "removed" fields from the struct. This will slim down our nested use of ExtraMounts --- modules/storage/storage.go | 80 +++++++++++++++++++++++- modules/storage/zz_generated.deepcopy.go | 55 ---------------- 2 files changed, 79 insertions(+), 56 deletions(-) delete mode 100644 modules/storage/zz_generated.deepcopy.go diff --git a/modules/storage/storage.go b/modules/storage/storage.go index aeee8922..5f317e88 100644 --- a/modules/storage/storage.go +++ b/modules/storage/storage.go @@ -40,6 +40,84 @@ 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"` + // flocker represents a Flocker volume attached to a kubelet's host machine. This depends on the Flocker control service being running + // +optional + Flocker *corev1.FlockerVolumeSource `json:"flocker,omitempty" protobuf:"bytes,15,opt,name=flocker"` + // 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"` + // quobyte represents a Quobyte mount on the host that shares a pod's lifetime + // +optional + Quobyte *corev1.QuobyteVolumeSource `json:"quobyte,omitempty" protobuf:"bytes,21,opt,name=quobyte"` + // 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"` + // image represents an OCI object (a container image or artifact) pulled and mounted on the kubelet's host machine. + // The volume is resolved at pod startup depending on which PullPolicy value is provided: + // + //Image *corev1.ImageVolumeSource `json:"image,omitempty" protobuf:"bytes,30,opt,name=image"` +} + +// 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 { @@ -50,7 +128,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"` } diff --git a/modules/storage/zz_generated.deepcopy.go b/modules/storage/zz_generated.deepcopy.go deleted file mode 100644 index 044024f0..00000000 --- a/modules/storage/zz_generated.deepcopy.go +++ /dev/null @@ -1,55 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright 2022. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -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. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package storage - -import ( - "k8s.io/api/core/v1" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *VolMounts) DeepCopyInto(out *VolMounts) { - *out = *in - if in.Volumes != nil { - in, out := &in.Volumes, &out.Volumes - *out = make([]v1.Volume, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Mounts != nil { - in, out := &in.Mounts, &out.Mounts - *out = make([]v1.VolumeMount, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderVolMounts. -func (in *VolMounts) DeepCopy() *VolMounts { - if in == nil { - return nil - } - out := new(VolMounts) - in.DeepCopyInto(out) - return out -}