@@ -1918,11 +1918,24 @@ func (r *MantleBackupReconciler) reconcileZeroOutJob(
19181918 return ctrl.Result {}, nil
19191919 }
19201920
1921- if err := r .createOrUpdateZeroOutPV (ctx , backup , snapshotTarget .pv ); err != nil {
1921+ if err := r .createOrUpdateStaticPV (
1922+ ctx ,
1923+ snapshotTarget .pv ,
1924+ snapshotTarget .pv .Spec .CSI .VolumeAttributes ["imageName" ],
1925+ snapshotTarget .pv .Spec .Capacity ,
1926+ MakeZeroOutPVName (backup ),
1927+ labelComponentZeroOutVolume ,
1928+ ); err != nil {
19221929 return ctrl.Result {}, err
19231930 }
19241931
1925- if err := r .createOrUpdateZeroOutPVC (ctx , backup , snapshotTarget .pvc ); err != nil {
1932+ if err := r .createOrUpdateStaticPVC (
1933+ ctx ,
1934+ MakeZeroOutPVCName (backup ),
1935+ MakeZeroOutPVName (backup ),
1936+ labelComponentZeroOutVolume ,
1937+ snapshotTarget .pvc .Spec .Resources ,
1938+ ); err != nil {
19261939 return ctrl.Result {}, err
19271940 }
19281941
@@ -1940,24 +1953,40 @@ func (r *MantleBackupReconciler) reconcileZeroOutJob(
19401953 return requeueReconciliation (), nil
19411954}
19421955
1943- func (r * MantleBackupReconciler ) createOrUpdateZeroOutPV (
1956+ // createOrUpdateStaticPV creates or updates a static PersistentVolume (PV) resource.
1957+ // It copies relevant CSI and metadata fields from the basePV, sets the provided volume handle,
1958+ // capacity, and component label, and ensures the PV is configured for static provisioning.
1959+ //
1960+ // Parameters:
1961+ //
1962+ // ctx - context for the API calls
1963+ // basePV - source PV to copy CSI and metadata fields from
1964+ // volume - volume handle to assign to the new PV
1965+ // capacity - resource capacity for the PV
1966+ // newPvName - name for the new or updated PV
1967+ // componentName - label value for the component
1968+ //
1969+ // Returns an error if creation or update fails.
1970+ func (r * MantleBackupReconciler ) createOrUpdateStaticPV (
19441971 ctx context.Context ,
1945- backup * mantlev1.MantleBackup ,
1946- targetPV * corev1.PersistentVolume ,
1972+ basePV * corev1.PersistentVolume ,
1973+ volume string ,
1974+ capacity corev1.ResourceList ,
1975+ newPvName , componentName string ,
19471976) error {
19481977 var pv corev1.PersistentVolume
1949- pv .SetName (MakeZeroOutPVName ( backup ) )
1978+ pv .SetName (newPvName )
19501979 _ , err := ctrl .CreateOrUpdate (ctx , r .Client , & pv , func () error {
19511980 labels := pv .GetLabels ()
19521981 if labels == nil {
19531982 labels = map [string ]string {}
19541983 }
19551984 labels ["app.kubernetes.io/name" ] = labelAppNameValue
1956- labels ["app.kubernetes.io/component" ] = labelComponentZeroOutVolume
1985+ labels ["app.kubernetes.io/component" ] = componentName
19571986 pv .SetLabels (labels )
19581987
19591988 pv .Spec .AccessModes = []corev1.PersistentVolumeAccessMode {corev1 .ReadWriteOnce }
1960- pv .Spec .Capacity = targetPV . Spec . Capacity
1989+ pv .Spec .Capacity = capacity
19611990 pv .Spec .PersistentVolumeReclaimPolicy = corev1 .PersistentVolumeReclaimRetain
19621991 pv .Spec .StorageClassName = ""
19631992
@@ -1967,47 +1996,60 @@ func (r *MantleBackupReconciler) createOrUpdateZeroOutPV(
19671996 if pv .Spec .CSI == nil {
19681997 pv .Spec .CSI = & corev1.CSIPersistentVolumeSource {}
19691998 }
1970- pv .Spec .CSI .Driver = targetPV .Spec .CSI .Driver
1971- pv .Spec .CSI .ControllerExpandSecretRef = targetPV .Spec .CSI .ControllerExpandSecretRef
1972- pv .Spec .CSI .NodeStageSecretRef = targetPV .Spec .CSI .NodeStageSecretRef
1973- pv .Spec .CSI .VolumeHandle = targetPV . Spec . CSI . VolumeAttributes [ "imageName" ]
1999+ pv .Spec .CSI .Driver = basePV .Spec .CSI .Driver
2000+ pv .Spec .CSI .ControllerExpandSecretRef = basePV .Spec .CSI .ControllerExpandSecretRef
2001+ pv .Spec .CSI .NodeStageSecretRef = basePV .Spec .CSI .NodeStageSecretRef
2002+ pv .Spec .CSI .VolumeHandle = volume
19742003
19752004 if pv .Spec .CSI .VolumeAttributes == nil {
19762005 pv .Spec .CSI .VolumeAttributes = map [string ]string {}
19772006 }
1978- pv .Spec .CSI .VolumeAttributes ["clusterID" ] = targetPV .Spec .CSI .VolumeAttributes ["clusterID" ]
1979- pv .Spec .CSI .VolumeAttributes ["imageFeatures" ] = targetPV .Spec .CSI .VolumeAttributes ["imageFeatures" ]
1980- pv .Spec .CSI .VolumeAttributes ["imageFormat" ] = targetPV .Spec .CSI .VolumeAttributes ["imageFormat" ]
1981- pv .Spec .CSI .VolumeAttributes ["pool" ] = targetPV .Spec .CSI .VolumeAttributes ["pool" ]
2007+ pv .Spec .CSI .VolumeAttributes ["clusterID" ] = basePV .Spec .CSI .VolumeAttributes ["clusterID" ]
2008+ pv .Spec .CSI .VolumeAttributes ["imageFeatures" ] = basePV .Spec .CSI .VolumeAttributes ["imageFeatures" ]
2009+ pv .Spec .CSI .VolumeAttributes ["imageFormat" ] = basePV .Spec .CSI .VolumeAttributes ["imageFormat" ]
2010+ pv .Spec .CSI .VolumeAttributes ["pool" ] = basePV .Spec .CSI .VolumeAttributes ["pool" ]
19822011 pv .Spec .CSI .VolumeAttributes ["staticVolume" ] = "true"
19832012
19842013 return nil
19852014 })
19862015 return err
19872016}
19882017
1989- func (r * MantleBackupReconciler ) createOrUpdateZeroOutPVC (
2018+ // createOrUpdateStaticPVC creates or updates a PersistentVolumeClaim (PVC) for binding to a static PersistentVolume (PV).
2019+ // This function configures the PVC to reference the specified static PV, sets labels, access modes, storage class,
2020+ // and resource requirements for static volume provisioning.
2021+ //
2022+ // Parameters:
2023+ //
2024+ // ctx - context for the API calls
2025+ // pvcName - name for the new or updated PVC
2026+ // pvName - name of the static PV to bind to
2027+ // componentName - label value for the component
2028+ // resources - resource requirements for the PVC
2029+ //
2030+ // Returns an error if creation or update fails.
2031+ func (r * MantleBackupReconciler ) createOrUpdateStaticPVC (
19902032 ctx context.Context ,
1991- backup * mantlev1. MantleBackup ,
1992- targetPVC * corev1.PersistentVolumeClaim ,
2033+ pvcName , pvName , componentName string ,
2034+ resources corev1.VolumeResourceRequirements ,
19932035) error {
19942036 var pvc corev1.PersistentVolumeClaim
1995- pvc .SetName (MakeZeroOutPVCName ( backup ) )
2037+ pvc .SetName (pvcName )
19962038 pvc .SetNamespace (r .managedCephClusterID )
19972039 _ , err := ctrl .CreateOrUpdate (ctx , r .Client , & pvc , func () error {
19982040 labels := pvc .GetLabels ()
19992041 if labels == nil {
20002042 labels = map [string ]string {}
20012043 }
20022044 labels ["app.kubernetes.io/name" ] = labelAppNameValue
2003- labels ["app.kubernetes.io/component" ] = labelComponentZeroOutVolume
2045+ labels ["app.kubernetes.io/component" ] = componentName
20042046 pvc .SetLabels (labels )
20052047
20062048 storageClassName := ""
20072049 pvc .Spec .StorageClassName = & storageClassName
20082050 pvc .Spec .AccessModes = []corev1.PersistentVolumeAccessMode {corev1 .ReadWriteOnce }
2009- pvc .Spec .Resources = targetPVC . Spec . Resources
2010- pvc .Spec .VolumeName = MakeZeroOutPVName ( backup )
2051+ pvc .Spec .Resources = resources
2052+ pvc .Spec .VolumeName = pvName
20112053
20122054 volumeMode := corev1 .PersistentVolumeBlock
20132055 pvc .Spec .VolumeMode = & volumeMode
0 commit comments