From cbf6f8cb922c7c593779c059d4b87a02a75120ca Mon Sep 17 00:00:00 2001 From: Jack Lin Date: Tue, 24 Dec 2024 12:50:29 +0800 Subject: [PATCH] fix: reject creating the same backing image to the same backup target ref: longhorn/longhorn 10023 Signed-off-by: Jack Lin --- webhook/resources/backupbackingimage/validator.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/webhook/resources/backupbackingimage/validator.go b/webhook/resources/backupbackingimage/validator.go index 492c1c4153..79642c9bc5 100644 --- a/webhook/resources/backupbackingimage/validator.go +++ b/webhook/resources/backupbackingimage/validator.go @@ -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 }