Skip to content

Commit

Permalink
add vsInRGD to check if a vs need to be deleted
Browse files Browse the repository at this point in the history
Signed-off-by: youhangwang <[email protected]>
  • Loading branch information
youhangwang committed Jun 12, 2024
1 parent 2e21552 commit e8356b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
4 changes: 3 additions & 1 deletion controllers/cephfscg/replicationgroupdestination.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (m *rgdMachine) Conditions() *[]metav1.Condition {
return &m.ReplicationGroupDestination.Status.Conditions
}

//nolint:cyclop
//nolint:cyclop,funlen
func (m *rgdMachine) Synchronize(ctx context.Context) (mover.Result, error) {
createdRDs := []*volsyncv1alpha1.ReplicationDestination{}
rds := []*corev1.ObjectReference{}
Expand Down Expand Up @@ -136,11 +136,13 @@ func (m *rgdMachine) Synchronize(ctx context.Context) (mover.Result, error) {
readytoUse, err := m.CheckImagesReadyToUse(ctx, latestImages, m.ReplicationGroupDestination.Namespace)
if err != nil {
m.Logger.Error(err, "Failed to check if images are ready to use")

return mover.InProgress(), err
}

if !readytoUse {
m.Logger.Error(err, "Images are not ready to use")

return mover.InProgress(), nil
}

Expand Down
23 changes: 11 additions & 12 deletions controllers/util/cephfs_cg.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
)

const (
ManualStringAnnotaion = "ramendr.openshift.io/manual-string"

// do not delete the vs in a vgs, only for testing
SkipDeleteAnnotaion = "rgd.ramendr.openshift.io/do-not-delete"

Expand Down Expand Up @@ -275,13 +273,6 @@ func DeferDeleteImage(ctx context.Context,
labels[RGDOwnerLabel] = rgdName
volumeSnapshot.SetLabels(labels)

annotations := volumeSnapshot.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}
annotations[ManualStringAnnotaion] = manual
volumeSnapshot.SetAnnotations(annotations)

return k8sClient.Update(ctx, volumeSnapshot)
})
}
Expand All @@ -304,9 +295,7 @@ func CleanExpiredRDImages(ctx context.Context,
continue
}

ManualString, ok := vs.Annotations[ManualStringAnnotaion]
if ok && rgd.Status.LastSyncStartTime != nil &&
ManualString != rgd.Status.LastSyncStartTime.String() {
if !vsInRGD(vs, rgd) {
if err := k8sClient.Delete(ctx, &vsv1.VolumeSnapshot{
ObjectMeta: metav1.ObjectMeta{Name: vs.Name, Namespace: vs.Namespace},
}); err != nil {
Expand All @@ -317,3 +306,13 @@ func CleanExpiredRDImages(ctx context.Context,

return nil
}

func vsInRGD(vs vsv1.VolumeSnapshot, rgd *ramendrv1alpha1.ReplicationGroupDestination) bool {
for _, image := range rgd.Status.LatestImages {
if image.Name == vs.Name {
return true
}
}

return false
}

0 comments on commit e8356b3

Please sign in to comment.