@@ -53,6 +53,8 @@ const (
5353 labelComponentExportJob = "export-job"
5454 labelComponentUploadJob = "upload-job"
5555 labelComponentImportJob = "import-job"
56+ labelComponentVerifyJob = "verify-job"
57+ labelComponentVerifyVolume = "verify-volume"
5658 labelComponentZeroOutJob = "zeroout-job"
5759 labelComponentZeroOutVolume = "zeroout-volume"
5860 annotRemoteUID = "mantle.cybozu.io/remote-uid"
@@ -619,6 +621,44 @@ func (r *MantleBackupReconciler) replicateManifests(
619621 return ctrl.Result {}, nil
620622}
621623
624+ func (r * MantleBackupReconciler ) verify (
625+ ctx context.Context ,
626+ backup * mantlev1.MantleBackup ,
627+ ) error {
628+ // logger := log.FromContext(ctx)
629+
630+ // check the clone of the snapshot if exists
631+ var pvc corev1.PersistentVolumeClaim
632+ if err := json .Unmarshal ([]byte (backup .Status .PVCManifest ), & pvc ); err != nil {
633+ return fmt .Errorf ("failed to unmarshal PVC manifest: %w" , err )
634+ }
635+
636+ var pv corev1.PersistentVolume
637+ if err := json .Unmarshal ([]byte (backup .Status .PVManifest ), & pv ); err != nil {
638+ return fmt .Errorf ("failed to unmarshal PV manifest: %w" , err )
639+ }
640+
641+ snapshotName := backup .Name
642+ cloneName := fmt .Sprintf ("mantle-verify-%s" , backup .UID )
643+ verifyPvName := fmt .Sprintf ("mantle-verify-%s" , backup .UID )
644+
645+ // create a clone by the snapshot bound to the MB
646+ if err := createCloneByPV (ctx , r .ceph , & pv , snapshotName , cloneName ); err != nil {
647+ return fmt .Errorf ("failed to create a clone by the snapshot: %w" , err )
648+ }
649+
650+ // create a static PV with the clone
651+ if err := r .createOrUpdateVerifyPV (ctx , backup , & pv , cloneName , verifyPvName ); err != nil {
652+ return fmt .Errorf ("failed to create a static PV with the clone: %w" , err )
653+ }
654+
655+ // create a PVC with the PV
656+ // create a Job to execute e2fsck on the PVC
657+ // wait for the Job to complete
658+ // update MB's conditions field
659+ return nil
660+ }
661+
622662func (r * MantleBackupReconciler ) provisionRBDSnapshot (
623663 ctx context.Context ,
624664 backup * mantlev1.MantleBackup ,
@@ -1944,20 +1984,55 @@ func (r *MantleBackupReconciler) createOrUpdateZeroOutPV(
19441984 ctx context.Context ,
19451985 backup * mantlev1.MantleBackup ,
19461986 targetPV * corev1.PersistentVolume ,
1987+ ) error {
1988+ return r .createOrUpdateStaticPV (
1989+ ctx ,
1990+ targetPV ,
1991+ targetPV .Spec .CSI .VolumeAttributes ["imageName" ],
1992+ targetPV .Spec .Capacity ,
1993+ MakeZeroOutPVName (backup ),
1994+ labelComponentZeroOutVolume ,
1995+ )
1996+ }
1997+
1998+ func (r * MantleBackupReconciler ) createOrUpdateVerifyPV (
1999+ ctx context.Context ,
2000+ backup * mantlev1.MantleBackup ,
2001+ basePV * corev1.PersistentVolume ,
2002+ cloneName , newPvName string ,
2003+ ) error {
2004+ return r .createOrUpdateStaticPV (
2005+ ctx ,
2006+ basePV ,
2007+ cloneName ,
2008+ corev1.ResourceList {
2009+ corev1 .ResourceStorage : * resource .NewQuantity (* backup .Status .SnapSize , resource .BinarySI ),
2010+ },
2011+ newPvName ,
2012+ labelComponentVerifyVolume ,
2013+ )
2014+ }
2015+
2016+ func (r * MantleBackupReconciler ) createOrUpdateStaticPV (
2017+ ctx context.Context ,
2018+ basePV * corev1.PersistentVolume ,
2019+ volume string ,
2020+ capacity corev1.ResourceList ,
2021+ newPvName , componentName string ,
19472022) error {
19482023 var pv corev1.PersistentVolume
1949- pv .SetName (MakeZeroOutPVName ( backup ) )
2024+ pv .SetName (newPvName )
19502025 _ , err := ctrl .CreateOrUpdate (ctx , r .Client , & pv , func () error {
19512026 labels := pv .GetLabels ()
19522027 if labels == nil {
19532028 labels = map [string ]string {}
19542029 }
19552030 labels ["app.kubernetes.io/name" ] = labelAppNameValue
1956- labels ["app.kubernetes.io/component" ] = labelComponentZeroOutVolume
2031+ labels ["app.kubernetes.io/component" ] = componentName
19572032 pv .SetLabels (labels )
19582033
19592034 pv .Spec .AccessModes = []corev1.PersistentVolumeAccessMode {corev1 .ReadWriteOnce }
1960- pv .Spec .Capacity = targetPV . Spec . Capacity
2035+ pv .Spec .Capacity = capacity
19612036 pv .Spec .PersistentVolumeReclaimPolicy = corev1 .PersistentVolumeReclaimRetain
19622037 pv .Spec .StorageClassName = ""
19632038
@@ -1967,18 +2042,18 @@ func (r *MantleBackupReconciler) createOrUpdateZeroOutPV(
19672042 if pv .Spec .CSI == nil {
19682043 pv .Spec .CSI = & corev1.CSIPersistentVolumeSource {}
19692044 }
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" ]
2045+ pv .Spec .CSI .Driver = basePV .Spec .CSI .Driver
2046+ pv .Spec .CSI .ControllerExpandSecretRef = basePV .Spec .CSI .ControllerExpandSecretRef
2047+ pv .Spec .CSI .NodeStageSecretRef = basePV .Spec .CSI .NodeStageSecretRef
2048+ pv .Spec .CSI .VolumeHandle = volume
19742049
19752050 if pv .Spec .CSI .VolumeAttributes == nil {
19762051 pv .Spec .CSI .VolumeAttributes = map [string ]string {}
19772052 }
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" ]
2053+ pv .Spec .CSI .VolumeAttributes ["clusterID" ] = basePV .Spec .CSI .VolumeAttributes ["clusterID" ]
2054+ pv .Spec .CSI .VolumeAttributes ["imageFeatures" ] = basePV .Spec .CSI .VolumeAttributes ["imageFeatures" ]
2055+ pv .Spec .CSI .VolumeAttributes ["imageFormat" ] = basePV .Spec .CSI .VolumeAttributes ["imageFormat" ]
2056+ pv .Spec .CSI .VolumeAttributes ["pool" ] = basePV .Spec .CSI .VolumeAttributes ["pool" ]
19822057 pv .Spec .CSI .VolumeAttributes ["staticVolume" ] = "true"
19832058
19842059 return nil
0 commit comments