From eb12cbe8330ec01e26c2b26dc3fa798a36dfd9d3 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Tue, 21 May 2024 07:17:20 -0400 Subject: [PATCH] fix(gateway/rest): use cluster status instead of manifest check service status prior trying shell using cluster API refs akash-network/support#87 Signed-off-by: Artur Troian --- gateway/rest/router.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/gateway/rest/router.go b/gateway/rest/router.go index 0c01a883..7643dd32 100644 --- a/gateway/rest/router.go +++ b/gateway/rest/router.go @@ -188,7 +188,7 @@ func newRouter(log log.Logger, addr sdk.Address, pclient provider.Client, ctxCon // POST /lease//shell lrouter.HandleFunc("/shell", - leaseShellHandler(log, pclient.Manifest(), pclient.Cluster())) + leaseShellHandler(log, pclient.Cluster())) return router } @@ -306,24 +306,18 @@ type leaseShellResponse struct { Message string `json:"message,omitempty"` } -func leaseShellHandler(log log.Logger, mclient pmanifest.Client, cclient cluster.Client) http.HandlerFunc { +func leaseShellHandler(log log.Logger, cclient cluster.Client) http.HandlerFunc { return func(rw http.ResponseWriter, req *http.Request) { leaseID := requestLeaseID(req) - // check if deployment actually exists in the first place before querying kubernetes - active, err := mclient.IsActive(req.Context(), leaseID.DeploymentID()) + // // check if deployment actually exists in the first place before querying kubernetes + status, err := cclient.LeaseStatus(req.Context(), leaseID) if err != nil { log.Error("failed checking deployment activity", "err", err) rw.WriteHeader(http.StatusInternalServerError) return } - if !active { - log.Info("no active deployment", "lease", leaseID) - rw.WriteHeader(http.StatusNotFound) - return - } - localLog := log.With("lease", leaseID.String(), "action", "shell") vars := req.URL.Query() @@ -357,6 +351,19 @@ func leaseShellHandler(log log.Logger, mclient pmanifest.Client, cclient cluster return } + svc, active := status[service] + if !active { + log.Info("no active deployment", "lease", leaseID) + rw.WriteHeader(http.StatusNotFound) + return + } + + if svc.Available == 0 { + log.Info("deployment does not have active replicas", "lease", leaseID) + rw.WriteHeader(http.StatusNotFound) + return + } + stdin := vars.Get("stdin") if 0 == len(stdin) { localLog.Error("missing parameter stdin")