Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/fatih/color v1.18.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/gorilla/mux v1.8.1
github.com/k8shell-io/common v0.37.0
github.com/k8shell-io/common v0.40.0
github.com/k8shell-io/k8shell-go v0.2.3
github.com/pkg/sftp v1.13.10
github.com/rs/zerolog v1.34.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ github.com/k8shell-io/common v0.36.0 h1:fkMH1XfYRLzDxqhIq5/luHusWWPGnCGJUXSTEIhE
github.com/k8shell-io/common v0.36.0/go.mod h1:E8dsb9ta4v3ne61AJgtRyTTbTkMMmKeCMAcXD+/9+cY=
github.com/k8shell-io/common v0.37.0 h1:whq66WosIJECKErUKZF1RQep7tdpOfI6GtP4hXREpsQ=
github.com/k8shell-io/common v0.37.0/go.mod h1:E8dsb9ta4v3ne61AJgtRyTTbTkMMmKeCMAcXD+/9+cY=
github.com/k8shell-io/common v0.39.0 h1:hfrKZYX2lBonornGrfK35rSY/+5o2sK+SakgUPKDL24=
github.com/k8shell-io/common v0.39.0/go.mod h1:E8dsb9ta4v3ne61AJgtRyTTbTkMMmKeCMAcXD+/9+cY=
github.com/k8shell-io/common v0.40.0 h1:MhQPVI5oe+JSdRJhWrtvCTJf0MaJDjM58KR7Nq3+lsM=
github.com/k8shell-io/common v0.40.0/go.mod h1:E8dsb9ta4v3ne61AJgtRyTTbTkMMmKeCMAcXD+/9+cY=
github.com/k8shell-io/k8shell-go v0.2.1 h1:6n88ijXkzP39//lIy4ai3XqtpSUXzoa/dVaWogHQYf4=
github.com/k8shell-io/k8shell-go v0.2.1/go.mod h1:j1JHgUIKIbaiRaitx6Pzw37ahqS4Hu9OcM4uvJ7BP4g=
github.com/k8shell-io/k8shell-go v0.2.2 h1:rwLOeIfyq1+l2Jyv0ak/lXZS7x6xbA5ye0yMsRkTonw=
Expand Down
12 changes: 12 additions & 0 deletions internal/apiclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ func (c *Client) GetUserProfile(ctx context.Context, username string) (*models.U
func (c *Client) SetUserPassword(ctx context.Context, username, password, currentPassword string) (*models.User, error) {
return c.sdk.SetUserPassword(ctx, username, password, currentPassword)
}

// StopWorkspace shuts down the named workspace, keeping its persistent
// storage intact so it can later be resumed with StartWorkspace.
func (c *Client) StopWorkspace(ctx context.Context, name string) error {
return c.sdk.DeleteWorkspace(ctx, name, false)
}

// TerminateWorkspace shuts down the named workspace and permanently deletes
// its persistent storage.
func (c *Client) TerminateWorkspace(ctx context.Context, name string) error {
return c.sdk.DeleteWorkspace(ctx, name, true)
}
190 changes: 0 additions & 190 deletions internal/grpc/command.go

This file was deleted.

3 changes: 0 additions & 3 deletions internal/grpc/grpcapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ type GRPCService struct {
UnixSocketStore *sync.Map // The store for the unix socket data
apiClientx *apiclient.Client // The API client to communicate with the API server
appManager *apps.AppManager // The app manager
CommandService *CommandServiceServer // The command service
sysInfo *system.SystemInfo // The system information
detachedSessionTTL time.Duration // max TTL for sessions with no client; 0 = no GC
allowSessionDetach bool // whether clients may detach/attach PTY sessions
Expand Down Expand Up @@ -127,7 +126,6 @@ func NewGRPCService(config *config.Config, blueprint *commonmodels.Blueprint, us
UnixSocketStore: &sync.Map{},
apiClientx: apiClient,
appManager: appManager,
CommandService: NewCommandServiceServer(),
sysInfo: sysInfo,
detachedSessionTTL: detachedTTL,
allowSessionDetach: config.Shells.AllowSessionDetach,
Expand Down Expand Up @@ -170,7 +168,6 @@ func (a *GRPCService) Serve(ctx context.Context) error {
k8shelldv1.RegisterSystemServiceServer(s, NewSystemServiceServer(a))
k8shelldv1.RegisterSshServiceServer(s, NewSshServiceServer(a))
k8shelldv1.RegisterAppServiceServer(s, NewAppServiceServer(a.appManager))
k8shelldv1.RegisterCommandServiceServer(s, a.CommandService)
a.logger.Info().Msgf("GRPC services server registered")
return nil
}); err != nil {
Expand Down
13 changes: 12 additions & 1 deletion internal/server/restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ func (a *RESTService) GetSessions(w http.ResponseWriter, r *http.Request) {
}

func (a *RESTService) Shutdown(w http.ResponseWriter, r *http.Request) {
if a.server.apiClientx == nil {
http.Error(w, "API server not configured.", http.StatusServiceUnavailable)
return
}

action := r.URL.Query().Get("action")
if action == "" {
action = "stop"
Expand All @@ -197,7 +202,13 @@ func (a *RESTService) Shutdown(w http.ResponseWriter, r *http.Request) {
return
}
a.logger.Debug().Msgf("Shutting down workspace %s (action=%s)", a.server.workspace, action)
_, err := a.server.grpcService.CommandService.SendCommand(r.Context(), "shutdown "+action)

var err error
if action == "delete" {
err = a.server.apiClientx.TerminateWorkspace(r.Context(), a.server.workspace)
} else {
err = a.server.apiClientx.StopWorkspace(r.Context(), a.server.workspace)
}
if err != nil {
a.logger.Warn().Msgf("Cannot shutdown workspace: %v", err)
http.Error(w, "Failed to shutdown workspace", http.StatusBadGateway)
Expand Down
Loading