Skip to content

Commit

Permalink
fix(backup): allow a backup target to set the same URL again
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 5411, 9987

Signed-off-by: James Lu <[email protected]>
  • Loading branch information
mantissahz committed Dec 19, 2024
1 parent f62d1c3 commit 092fe53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions datastore/longhorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (s *DataStore) ValidateSetting(name, value string) (err error) {
}
return fmt.Errorf("cannot modify BackupTarget since there are existing standby volumes: %v", standbyVolumeNames)
}
if err := s.ValidateBackupTargetURL(value); err != nil {
if err := s.ValidateBackupTargetURL(types.DefaultBackupTargetName, value); err != nil {
return err
}
case types.SettingNameBackupTargetCredentialSecret:
Expand Down Expand Up @@ -4281,7 +4281,7 @@ func (s *DataStore) RemoveFinalizerForBackupTarget(backupTarget *longhorn.Backup
}

// ValidateBackupTargetURL checks if the given backup target URL is already used by other backup targets
func (s *DataStore) ValidateBackupTargetURL(backupTargetURL string) error {
func (s *DataStore) ValidateBackupTargetURL(backupTargetName, backupTargetURL string) error {
if backupTargetURL == "" {
return nil
}
Expand All @@ -4293,7 +4293,7 @@ func (s *DataStore) ValidateBackupTargetURL(backupTargetURL string) error {
if err := checkBackupTargetURLFormat(u); err != nil {
return err
}
if err := s.validateBackupTargetURLExisting(u); err != nil {
if err := s.validateBackupTargetURLExisting(backupTargetName, u); err != nil {
return err
}

Expand All @@ -4317,7 +4317,7 @@ func checkBackupTargetURLFormat(u *url.URL) error {
}

// validateBackupTargetURLExisting checks if the given backup target URL is already used by other backup targets
func (s *DataStore) validateBackupTargetURLExisting(u *url.URL) error {
func (s *DataStore) validateBackupTargetURLExisting(backupTargetName string, u *url.URL) error {
newBackupTargetPath, err := getBackupTargetPath(u)
if err != nil {
return err
Expand All @@ -4340,7 +4340,7 @@ func (s *DataStore) validateBackupTargetURLExisting(u *url.URL) error {
if err != nil {
return err
}
if oldBackupTargetPath == newBackupTargetPath {
if oldBackupTargetPath == newBackupTargetPath && backupTargetName != bt.Name {
return fmt.Errorf("url %s is the same to backup target %v", u.String(), bt.Name)
}
}
Expand Down
4 changes: 2 additions & 2 deletions webhook/resources/backuptarget/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (b *backupTargetValidator) Create(request *admission.Request, newObj runtim
return werror.NewInvalidError(fmt.Sprintf("invalid name %v", backupTarget.Name), "")
}

if err := b.ds.ValidateBackupTargetURL(backupTarget.Spec.BackupTargetURL); err != nil {
if err := b.ds.ValidateBackupTargetURL(backupTarget.Name, backupTarget.Spec.BackupTargetURL); err != nil {
return werror.NewInvalidError(err.Error(), "")
}

Expand Down Expand Up @@ -100,7 +100,7 @@ func (b *backupTargetValidator) Update(request *admission.Request, oldObj runtim
secretChanged := oldBackupTarget.Spec.CredentialSecret != newBackupTarget.Spec.CredentialSecret

if urlChanged {
if err := b.ds.ValidateBackupTargetURL(newBackupTarget.Spec.BackupTargetURL); err != nil {
if err := b.ds.ValidateBackupTargetURL(newBackupTarget.Name, newBackupTarget.Spec.BackupTargetURL); err != nil {
return werror.NewInvalidError(err.Error(), "")
}
}
Expand Down

0 comments on commit 092fe53

Please sign in to comment.