Skip to content

Commit

Permalink
feat(gateway): allow tenant to recover manifest of active lease
Browse files Browse the repository at this point in the history
refs akash-network/support#227

Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Aug 20, 2024
1 parent 7e2a151 commit 5c6ec29
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 27 additions & 0 deletions gateway/rest/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func newRouter(log log.Logger, addr sdk.Address, pclient provider.Client, ctxCon
createManifestHandler(log, pclient.Manifest())).
Methods(http.MethodPut)

drouter.HandleFunc("/manifest",
getManifestHandler(pclient.Manifest())).

Check failure on line 150 in gateway/rest/router.go

View workflow job for this annotation

GitHub Actions / build-bins

not enough arguments in call to getManifestHandler

Check failure on line 150 in gateway/rest/router.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to getManifestHandler

Check failure on line 150 in gateway/rest/router.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to getManifestHandler

Check failure on line 150 in gateway/rest/router.go

View workflow job for this annotation

GitHub Actions / release-dry-run

not enough arguments in call to getManifestHandler

Check failure on line 150 in gateway/rest/router.go

View workflow job for this annotation

GitHub Actions / tests

not enough arguments in call to getManifestHandler

Check failure on line 150 in gateway/rest/router.go

View workflow job for this annotation

GitHub Actions / build-bins

not enough arguments in call to getManifestHandler

Check failure on line 150 in gateway/rest/router.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to getManifestHandler

Check failure on line 150 in gateway/rest/router.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to getManifestHandler

Check failure on line 150 in gateway/rest/router.go

View workflow job for this annotation

GitHub Actions / tests

not enough arguments in call to getManifestHandler
Methods(http.MethodGet)

lrouter := router.PathPrefix(leasePathPrefix).Subrouter()
lrouter.Use(
requireOwner(),
Expand Down Expand Up @@ -591,6 +595,29 @@ func createManifestHandler(log log.Logger, mclient pmanifest.Client) http.Handle
}
}

func getManifestHandler(log log.Logger, cclient cluster.ReadClient) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
found, grp, err := cclient.GetManifestGroup(r.Context(), requestLeaseID(r))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

if !found {
http.Error(w, "lease not found", http.StatusNotFound)
return
}

mgrp, _, err := grp.FromCRD()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

writeJSON(log, w, &manifest.Manifest{mgrp})
}
}

func leaseKubeEventsHandler(log log.Logger, cclient cluster.ReadClient) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
upgrader := websocket.Upgrader{
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/akash.network/v2beta2/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (m *Manifest) Deployment() (ctypes.IDeployment, error) {
return nil, err
}

group, schedulerParams, err := m.Spec.Group.fromCRD()
group, schedulerParams, err := m.Spec.Group.FromCRD()
if err != nil {
return nil, err
}
Expand All @@ -185,8 +185,8 @@ func (m *Manifest) Deployment() (ctypes.IDeployment, error) {
}, nil
}

// toAkash returns akash group details formatted from manifest group
func (m *ManifestGroup) fromCRD() (mani.Group, []*SchedulerParams, error) {
// FromCRD returns akash group details formatted from manifest group
func (m *ManifestGroup) FromCRD() (mani.Group, []*SchedulerParams, error) {
am := mani.Group{
Name: m.Name,
Services: make([]mani.Service, 0, len(m.Services)),
Expand Down

0 comments on commit 5c6ec29

Please sign in to comment.