Skip to content

Commit 639f65a

Browse files
committed
remove unnecessary field MantleRestore.status.pool
`MantleRestore.status.pool` was kept to delete MR without MantleBackup. But the procedure of deletion has changed, and the field is unused. Signed-off-by: Yuji Ito <llamerada.jp@gmail.com>
1 parent 4392eb0 commit 639f65a

5 files changed

Lines changed: 8 additions & 35 deletions

File tree

api/v1/mantlerestore_types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ type MantleRestoreStatus struct {
2828

2929
// 'clusterID' specifies the Ceph cluster ID the source PV/PVC belongs to
3030
ClusterID string `json:"clusterID,omitempty"`
31-
32-
// 'pool' specifies pool name the volumes are restored to
33-
Pool string `json:"pool,omitempty"`
3431
}
3532

3633
const (

charts/mantle-cluster-wide/templates/mantle.cybozu.io_mantlerestores.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ spec:
112112
- type
113113
type: object
114114
type: array
115-
pool:
116-
description: '''pool'' specifies pool name the volumes are restored
117-
to'
118-
type: string
119115
type: object
120116
type: object
121117
served: true

config/crd/bases/mantle.cybozu.io_mantlerestores.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ spec:
112112
- type
113113
type: object
114114
type: array
115-
pool:
116-
description: '''pool'' specifies pool name the volumes are restored
117-
to'
118-
type: string
119115
type: object
120116
type: object
121117
served: true

internal/controller/mantlerestore_controller.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,6 @@ func (r *MantleRestoreReconciler) restore(ctx context.Context, restore *mantlev1
141141
return requeueReconciliation(), nil
142142
}
143143

144-
// store the pool name in the status
145-
var pv corev1.PersistentVolume
146-
err = json.Unmarshal([]byte(backup.Status.PVManifest), &pv)
147-
if err != nil {
148-
logger.Error(err, "failed to unmarshal PV manifest", "backup", backup.Name, "namespace", backup.Namespace)
149-
return ctrl.Result{}, err
150-
}
151-
restore.Status.Pool = pv.Spec.CSI.VolumeAttributes["pool"]
152-
if restore.Status.Pool == "" {
153-
err := fmt.Errorf("pool not found in PV manifest")
154-
logger.Error(err, "status.pool cannot be set", "backup", backup.Name, "namespace", backup.Namespace)
155-
return ctrl.Result{}, err
156-
}
157-
err = r.client.Status().Update(ctx, restore)
158-
if err != nil {
159-
logger.Error(err, "failed to update status.pool", "status", restore.Status)
160-
return ctrl.Result{}, err
161-
}
162-
163144
// create a clone image from the backup
164145
if err := r.cloneImageFromBackup(ctx, restore, &backup); err != nil {
165146
logger.Error(err, "failed to clone image from backup", "backup", backup.Name, "namespace", backup.Namespace)
@@ -213,23 +194,27 @@ func (r *MantleRestoreReconciler) cloneImageFromBackup(ctx context.Context, rest
213194
if bkImage == "" {
214195
return fmt.Errorf("imageName not found in PV manifest")
215196
}
197+
pool := pv.Spec.CSI.VolumeAttributes["pool"]
198+
if pool == "" {
199+
return fmt.Errorf("pool not found in PV manifest")
200+
}
216201

217-
images, err := r.ceph.RBDLs(restore.Status.Pool)
202+
images, err := r.ceph.RBDLs(pool)
218203
if err != nil {
219204
return fmt.Errorf("failed to list RBD images: %w", err)
220205
}
221206

222207
// check if the image already exists
223208
if slices.Contains(images, r.restoringRBDImageName(restore)) {
224-
info, err := r.ceph.RBDInfo(restore.Status.Pool, r.restoringRBDImageName(restore))
209+
info, err := r.ceph.RBDInfo(pool, r.restoringRBDImageName(restore))
225210
if err != nil {
226211
return fmt.Errorf("failed to get RBD info: %w", err)
227212
}
228213
if info.Parent == nil {
229214
return fmt.Errorf("failed to get RBD info: parent field is empty")
230215
}
231216

232-
if info.Parent.Pool == restore.Status.Pool && info.Parent.Image == bkImage && info.Parent.Snapshot == backup.Name {
217+
if info.Parent.Pool == pool && info.Parent.Image == bkImage && info.Parent.Snapshot == backup.Name {
233218
logger.Info("image already exists", "image", r.restoringRBDImageName(restore))
234219
return nil
235220
} else {
@@ -245,7 +230,7 @@ func (r *MantleRestoreReconciler) cloneImageFromBackup(ctx context.Context, rest
245230
}
246231

247232
// create a clone image from the backup
248-
return r.ceph.RBDClone(restore.Status.Pool, bkImage, backup.Name, r.restoringRBDImageName(restore), features)
233+
return r.ceph.RBDClone(pool, bkImage, backup.Name, r.restoringRBDImageName(restore), features)
249234
}
250235

251236
func (r *MantleRestoreReconciler) createOrUpdateRestoringPV(ctx context.Context, restore *mantlev1.MantleRestore, backup *mantlev1.MantleBackup) error {

test/e2e/singlek8s/restore_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ func (test *restoreTest) testCloneImageFromBackup() {
412412
},
413413
Status: mantlev1.MantleRestoreStatus{
414414
ClusterID: cephCluster1Namespace,
415-
Pool: test.poolName,
416415
},
417416
}
418417
var info *rbdInfo

0 commit comments

Comments
 (0)