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")