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 3f3d5bf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
36 changes: 33 additions & 3 deletions gateway/rest/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,23 @@ func newRouter(log log.Logger, addr sdk.Address, pclient provider.Client, ctxCon

hostnameRouter := router.PathPrefix(hostnamePrefix).Subrouter()
hostnameRouter.Use(requireOwner())
hostnameRouter.HandleFunc(migratePathPrefix, migrateHandler(log, pclient.Hostname(), pclient.ClusterService())).
hostnameRouter.HandleFunc(migratePathPrefix,
migrateHandler(log, pclient.Hostname(), pclient.ClusterService())).
Methods(http.MethodPost)

endpointRouter := router.PathPrefix(endpointPrefix).Subrouter()
endpointRouter.Use(requireOwner())
endpointRouter.HandleFunc(migratePathPrefix, migrateEndpointHandler(log, pclient.ClusterService(), pclient.Cluster())).
endpointRouter.HandleFunc(migratePathPrefix,
migrateEndpointHandler(log, pclient.ClusterService(), pclient.Cluster())).
Methods(http.MethodPost)

// PUT /deployment/manifest
drouter := router.PathPrefix(deploymentPathPrefix).Subrouter()
drouter.Use(
requireOwner(),
requireDeploymentID(),
)

// PUT /deployment/manifest
drouter.HandleFunc("/manifest",
createManifestHandler(log, pclient.Manifest())).
Methods(http.MethodPut)
Expand All @@ -152,6 +154,11 @@ func newRouter(log log.Logger, addr sdk.Address, pclient provider.Client, ctxCon
requireLeaseID(),
)

// GET /lease/<lease-id>/manifest
drouter.HandleFunc("/manifest",
getManifestHandler(log, pclient.Cluster())).
Methods(http.MethodGet)

// GET /lease/<lease-id>/status
lrouter.HandleFunc("/status",
leaseStatusHandler(log, pclient.Cluster(), ctxConfig)).
Expand Down Expand Up @@ -591,6 +598,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 3f3d5bf

Please sign in to comment.