Skip to content

Commit

Permalink
fix(backup): modify backup target API to use OwnerIDFromBackupTarget
Browse files Browse the repository at this point in the history
instead of `NodeHasDefaultEngineImage` because we should allow to
modify a backup target without the `default` engine image.

ref: longhorn/longhorn 5411, 10043

Signed-off-by: James Lu <james.lu@suse.com>
  • Loading branch information
mantissahz committed Dec 27, 2024
1 parent 6fb6ddc commit 7efd8ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions api/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ func OwnerIDFromVolume(m *manager.VolumeManager) func(req *http.Request) (string
}
}

func OwnerIDFromBackupTarget(m *manager.VolumeManager) func(req *http.Request) (string, error) {
return func(req *http.Request) (string, error) {
backupTargetName := mux.Vars(req)["backupTargetName"]
backupTarget, err := m.GetBackupTarget(backupTargetName)
if err != nil {
return "", errors.Wrapf(err, "failed to get backup target '%s'", backupTargetName)
}
if backupTarget == nil {
return "", nil
}
return backupTarget.Status.OwnerID, nil
}
}

// NodeHasDefaultEngineImage picks a node that is ready and has default engine image deployed.
// To prevent the repeatedly forwarding the request around, prioritize the current node if it meets the requirement.
func NodeHasDefaultEngineImage(m *manager.VolumeManager) func(req *http.Request) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func NewRouter(s *Server) *mux.Router {
r.Methods("PUT").Path("/v1/backuptargets").Handler(f(schemas, s.BackupTargetSyncAll))
r.Methods("DELETE").Path("/v1/backuptargets/{backupTargetName}").Handler(f(schemas, s.BackupTargetDelete))
backupTargetActions := map[string]func(http.ResponseWriter, *http.Request) error{
"backupTargetSync": s.fwd.Handler(s.fwd.HandleProxyRequestByNodeID, s.fwd.GetHTTPAddressByNodeID(NodeHasDefaultEngineImage(s.m)), s.BackupTargetSync),
"backupTargetUpdate": s.fwd.Handler(s.fwd.HandleProxyRequestByNodeID, s.fwd.GetHTTPAddressByNodeID(NodeHasDefaultEngineImage(s.m)), s.BackupTargetUpdate),
"backupTargetSync": s.fwd.Handler(s.fwd.HandleProxyRequestByNodeID, s.fwd.GetHTTPAddressByNodeID(OwnerIDFromBackupTarget(s.m)), s.BackupTargetSync),
"backupTargetUpdate": s.fwd.Handler(s.fwd.HandleProxyRequestByNodeID, s.fwd.GetHTTPAddressByNodeID(OwnerIDFromBackupTarget(s.m)), s.BackupTargetUpdate),
}
for name, action := range backupTargetActions {
r.Methods("POST").Path("/v1/backuptargets/{backupTargetName}").Queries("action", name).Handler(f(schemas, action))
Expand Down

0 comments on commit 7efd8ed

Please sign in to comment.