Skip to content

Commit 6f0595d

Browse files
committed
WIP
1 parent bb65be7 commit 6f0595d

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

components/workspacekit/cmd/rings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ var ring1Cmd = &cobra.Command{
210210
defer handleExit(&exitCode)
211211

212212
defer log.Info("ring1 stopped")
213+
defer func() {
214+
log.Info("ring1 going to sleep")
215+
time.Sleep(5 * time.Minute)
216+
log.Info("ring1 woke up again")
217+
}()
213218

214219
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
215220
defer cancel()

components/ws-daemon/pkg/container/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"golang.org/x/xerrors"
1111

1212
"github.com/containerd/containerd/api/types/task"
13+
"github.com/containerd/containerd/sandbox"
1314
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
1415
)
1516

@@ -57,6 +58,7 @@ type Runtime interface {
5758
DisposeContainer(ctx context.Context, workspaceInstanceID string)
5859

5960
GetContainerTaskInfo(ctx context.Context, id ID) (*task.Process, error)
61+
GetSandboxStatus(ctx context.Context, instanceId string) (*sandbox.ControllerStatus, error)
6062

6163
ForceKillContainerTask(ctx context.Context, id ID) error
6264
}

components/ws-daemon/pkg/container/containerd.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/containerd/containerd/containers"
2525
"github.com/containerd/containerd/errdefs"
2626
"github.com/containerd/containerd/images"
27+
"github.com/containerd/containerd/sandbox"
2728
"github.com/containerd/platforms"
2829
"github.com/containerd/typeurl/v2"
2930
ocispecs "github.com/opencontainers/runtime-spec/specs-go"
@@ -577,6 +578,19 @@ func (s *Containerd) IsContainerdReady(ctx context.Context) (bool, error) {
577578
return true, nil
578579
}
579580

581+
func (s *Containerd) GetSandboxStatus(ctx context.Context, instanceId string) (*sandbox.ControllerStatus, error) {
582+
info, ok := s.wsiIdx[instanceId]
583+
if !ok || info.ID == "" {
584+
return nil, fmt.Errorf("no SandboxID found")
585+
}
586+
587+
resp, err := s.Client.SandboxController().Status(ctx, string(info.ID), true)
588+
if err != nil {
589+
return nil, fmt.Errorf("error retrieving sandbox status: %w", err)
590+
}
591+
return &resp, nil
592+
}
593+
580594
func (s *Containerd) GetContainerTaskInfo(ctx context.Context, id ID) (*task.Process, error) {
581595
task, err := s.Client.TaskService().Get(ctx, &tasks.GetRequest{
582596
ContainerID: string(id),

components/ws-daemon/pkg/content/hooks.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func WorkspaceLifecycleHooks(cfg Config, workspaceCIDR string, uidmapper *iws.Ui
4848
hookInstallQuota(xfs, true),
4949
},
5050
session.WorkspaceDisposed: {
51-
hookWipingTeardown(), // if ws.DoWipe == true: make sure we 100% tear down the workspace
51+
hookUnmount(),
5252
iws.StopServingWorkspace,
5353
hookRemoveQuota(xfs),
5454
},
@@ -170,15 +170,17 @@ func hookRemoveQuota(xfs *quota.XFS) session.WorkspaceLivecycleHook {
170170
}
171171
}
172172

173-
func hookWipingTeardown() session.WorkspaceLivecycleHook {
173+
func hookUnmount() session.WorkspaceLivecycleHook {
174174
return func(ctx context.Context, ws *session.Workspace) error {
175175
log := log.WithFields(ws.OWI())
176176

177-
if !ws.DoWipe {
178-
// this is the "default" case for 99% of all workspaces
179-
// TODO(gpl): We should probably make this the default for all workspaces - but not with this PR
180-
return nil
181-
}
177+
// if !ws.DoWipe {
178+
// // this is the "default" case for 99% of all workspaces
179+
// // TODO(gpl): We should probably make this the default for all workspaces - but not with this PR
180+
// return nil
181+
// }
182+
doWipe := true
183+
log.Info("unmount hook")
182184

183185
socketFN := filepath.Join(ws.ServiceLocDaemon, "daemon.sock")
184186
conn, err := grpc.DialContext(ctx, "unix://"+socketFN, grpc.WithTransportCredentials(insecure.NewCredentials()))
@@ -189,12 +191,12 @@ func hookWipingTeardown() session.WorkspaceLivecycleHook {
189191
client := daemonapi.NewInWorkspaceServiceClient(conn)
190192

191193
res, err := client.WipingTeardown(ctx, &daemonapi.WipingTeardownRequest{
192-
DoWipe: ws.DoWipe,
194+
DoWipe: doWipe,
193195
})
194196
if err != nil {
195197
return err
196198
}
197-
log.WithField("success", res.Success).Debug("wiping teardown done")
199+
log.WithField("success", res.Success).Info("unmount hook done")
198200

199201
return nil
200202
}

components/ws-daemon/pkg/controller/workspace_controller.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package controller
66

77
import (
88
"context"
9+
"encoding/json"
910
"fmt"
1011
"time"
1112

@@ -482,6 +483,7 @@ func (wsc *WorkspaceController) dumpWorkspaceContainerInfo(ctx context.Context,
482483
if err != nil {
483484
return fmt.Errorf("failed to wait for container: %w", err)
484485
}
486+
485487
task, err := wsc.runtime.GetContainerTaskInfo(ctx, id)
486488
if err != nil {
487489
return fmt.Errorf("failed to get container task info: %w", err)
@@ -493,6 +495,22 @@ func (wsc *WorkspaceController) dumpWorkspaceContainerInfo(ctx context.Context,
493495
"exitedAt": task.ExitedAt.AsTime(),
494496
"status": task.Status.String(),
495497
}).Info("container task info")
498+
499+
sandboxStatus, err := wsc.runtime.GetSandboxStatus(ctx, ws.Name)
500+
if err != nil {
501+
return fmt.Errorf("failed to get container sandbox status: %w", err)
502+
}
503+
504+
infoJson, _ := json.Marshal(sandboxStatus.Info)
505+
glog.WithFields(ws.OWI()).WithFields(logrus.Fields{
506+
"sandboxID": sandboxStatus.SandboxID,
507+
"sandboxPid": sandboxStatus.Pid,
508+
"createdAt": sandboxStatus.CreatedAt.String(),
509+
"exitedAt": sandboxStatus.ExitedAt.String(),
510+
"state": sandboxStatus.State,
511+
"extra": string(sandboxStatus.Extra.GetValue()),
512+
"info": string(infoJson),
513+
}).Info("container sandbox status")
496514
return nil
497515
}
498516

0 commit comments

Comments
 (0)