Skip to content

Commit

Permalink
fix: reject creating the same backing image to the same backup target
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 10023

Signed-off-by: Jack Lin <[email protected]>
  • Loading branch information
ChanYiLin committed Dec 24, 2024
1 parent f069d34 commit cbf6f8c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions webhook/resources/backupbackingimage/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,15 @@ func (bbi *backupBackingImageValidator) Create(request *admission.Request, newOb
return werror.NewInvalidError(fmt.Sprintf("backing image %v uses v2 data engine which doesn't support backup operations", backingImageName), "")
}

backupBackingImages, err := bbi.ds.ListBackupBackingImagesRO()
if err != nil {
return werror.NewInternalError(fmt.Sprintf("failed to list backup backing images: %v", err))
}
for _, otherBackupBackingImage := range backupBackingImages {
if otherBackupBackingImage.Spec.BackingImage == backingImageName && otherBackupBackingImage.Spec.BackupTargetName == backupBackingImage.Spec.BackupTargetName {
return werror.NewInvalidError(fmt.Sprintf("backup backing image %v for backup target %v already exists", backingImageName, backupBackingImage.Spec.BackupTargetName), "")
}
}

return nil
}

0 comments on commit cbf6f8c

Please sign in to comment.