Skip to content

Commit ba21ee7

Browse files
committed
review comments + log cleanup
1 parent eb1709c commit ba21ee7

File tree

14 files changed

+31
-35
lines changed

14 files changed

+31
-35
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cgroup
66

77
import (
88
"context"
9+
"errors"
910

1011
"github.com/gitpod-io/gitpod/common-go/cgroups"
1112
"github.com/gitpod-io/gitpod/common-go/log"
@@ -81,7 +82,7 @@ func (host *PluginHost) WorkspaceAdded(ctx context.Context, ws *dispatch.Workspa
8182

8283
cgroupPath, err := disp.Runtime.ContainerCGroupPath(ctx, ws.ContainerID)
8384
if err != nil {
84-
if err == context.Canceled {
85+
if errors.Is(err, context.Canceled) {
8586
return nil
8687
}
8788
return xerrors.Errorf("cannot get cgroup path for container %s: %w", ws.ContainerID, err)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ func (s *Containerd) WaitForContainerStop(ctx context.Context, workspaceInstance
431431
func (s *Containerd) DisposeContainer(ctx context.Context, workspaceInstanceID string) {
432432
log := log.WithContext(ctx)
433433

434-
log.Debug("CONTAINERD: DISPOSING CONTAINER")
435-
defer log.Debug("CONTAINERD: DISPOSING CONTAINER DONE")
434+
log.Debug("containerd: disposing container")
435+
defer log.Debug("containerd: disposing container done")
436436

437437
s.cond.L.Lock()
438438
defer s.cond.L.Unlock()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func hookWipingTeardown() session.WorkspaceLivecycleHook {
176176

177177
if !ws.DoWipe {
178178
// 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
179180
return nil
180181
}
181182

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ func (wsc *WorkspaceController) doWipeWorkspace(ctx context.Context, ws *workspa
255255
return ctrl.Result{Requeue: true, RequeueAfter: 100 * time.Millisecond}, nil
256256
}
257257

258-
setStateWipedCondition := func(s bool) {
258+
setStateWipedCondition := func(success bool) {
259259
err := retry.RetryOnConflict(retryParams, func() error {
260260
if err := wsc.Get(ctx, req.NamespacedName, ws); err != nil {
261261
return err
262262
}
263263

264-
if s {
264+
if success {
265265
ws.Status.SetCondition(workspacev1.NewWorkspaceConditionStateWiped("", metav1.ConditionTrue))
266266
} else {
267267
ws.Status.SetCondition(workspacev1.NewWorkspaceConditionStateWiped("", metav1.ConditionFalse))

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ func (wso *DefaultWorkspaceOperations) WipeWorkspace(ctx context.Context, instan
315315
wso.dispatch.DisposeWorkspace(ctx, instanceID)
316316

317317
// remove workspace daemon directory in the node
318-
log.Debug("DELETING WORKSPACE DAEMON DIR")
319-
defer log.Debug("DELETING WORKSPACE DAEMON DIR DONE")
320-
321318
removedChan := make(chan struct{}, 1)
322319
go func() {
323320
defer close(removedChan)
@@ -327,9 +324,10 @@ func (wso *DefaultWorkspaceOperations) WipeWorkspace(ctx context.Context, instan
327324
}
328325
}()
329326

330-
timeoutT := time.NewTicker(10 * time.Second)
327+
timeout := time.NewTicker(10 * time.Second)
328+
defer timeout.Stop()
331329
select {
332-
case <-timeoutT.C:
330+
case <-timeout.C:
333331
case <-removedChan:
334332
log.Debug("successfully removed workspace daemon directory")
335333
}

components/ws-daemon/pkg/cpulimit/dispatch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (d *DispatchListener) WorkspaceAdded(ctx context.Context, ws *dispatch.Work
181181

182182
cgroupPath, err := disp.Runtime.ContainerCGroupPath(ctx, ws.ContainerID)
183183
if err != nil {
184-
if dispatch.IsCancelled(ctx) {
184+
if errors.Is(err, context.Canceled) {
185185
return nil
186186
}
187187
return xerrors.Errorf("cannot start governer: %w", err)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bufio"
99
"bytes"
1010
"context"
11+
"errors"
1112
"io/ioutil"
1213
"path/filepath"
1314
"strings"
@@ -127,7 +128,7 @@ func (c *MarkUnmountFallback) WorkspaceUpdated(ctx context.Context, ws *dispatch
127128
}
128129

129130
err := unmountMark(ws.InstanceID)
130-
if err != nil && !dispatch.IsCancelled(ctx) {
131+
if err != nil && errors.Is(err, context.Canceled) {
131132
log.WithFields(ws.OWI()).WithError(err).Error("cannot unmount mark mount from within ws-daemon")
132133
c.activityCounter.WithLabelValues("false").Inc()
133134
} else {

components/ws-daemon/pkg/diskguard/guard.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type Guard struct {
7171
// Start starts the disk guard
7272
func (g *Guard) Start() {
7373
t := time.NewTicker(g.Interval)
74+
defer t.Stop()
7475
for {
7576
bvail, err := getAvailableBytes(g.Path)
7677
if err != nil {

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ func GetDispatchWaitGroup(ctx context.Context) *sync.WaitGroup {
115115
return ctx.Value(contextDispatchWaitGroup).(*sync.WaitGroup)
116116
}
117117

118-
func IsCancelled(ctx context.Context) bool {
119-
return context.Cause(ctx) != nil
120-
}
121-
122118
// Start starts the dispatch
123119
func (d *Dispatch) Start() error {
124120
ifac := informers.NewSharedInformerFactoryWithOptions(d.Kubernetes, podInformerResyncInterval, informers.WithNamespace(d.KubernetesNamespace))
@@ -195,8 +191,8 @@ func (d *Dispatch) DisposeWorkspace(ctx context.Context, instanceID string) {
195191
d.mu.Lock()
196192
defer d.mu.Unlock()
197193

198-
log.WithField("instanceID", instanceID).Debug("WS DISPOSE")
199-
defer log.WithField("instanceID", instanceID).Debug("WS DISPOSE DONE")
194+
log.WithField("instanceID", instanceID).Debug("disposing workspace")
195+
defer log.WithField("instanceID", instanceID).Debug("disposing workspace done")
200196

201197
// If we have that instanceID present, cancel it's context
202198
state, present := d.ctxs[instanceID]
@@ -237,10 +233,9 @@ func (d *Dispatch) handlePodUpdate(oldPod, newPod *corev1.Pod) {
237233
}
238234
disposedKey := disposedKey(workspaceInstanceID, newPod)
239235
if _, alreadyDisposed := d.disposedCtxs[disposedKey]; alreadyDisposed {
240-
log.WithField("disposedKey", disposedKey).Debug("DROPPING POD UPDATE FOR DISPOSED POD")
236+
log.WithField("disposedKey", disposedKey).Debug("dropping pod update for disposed pod")
241237
return
242238
}
243-
log.WithField("instanceID", workspaceInstanceID).Debugf("POD UPDATE: %s", workspaceInstanceID)
244239

245240
d.mu.Lock()
246241
defer d.mu.Unlock()
@@ -337,15 +332,15 @@ func (d *Dispatch) handlePodUpdate(oldPod, newPod *corev1.Pod) {
337332
}
338333
}()
339334
}
340-
log.WithField("instanceID", workspaceInstanceID).Debugf("POD UPDATE DONE: %s", workspaceInstanceID)
341335
}
342336

343337
func (d *Dispatch) handlePodDeleted(pod *corev1.Pod) {
344338
instanceID, ok := pod.Labels[wsk8s.WorkspaceIDLabel]
345339
if !ok {
346340
return
347341
}
348-
log.WithField("instanceID", instanceID).Debugf("POD DELETED: %s", instanceID)
342+
log.WithField("instanceID", instanceID).Debug("pod deleted")
343+
defer log.WithField("instanceID", instanceID).Debug("pod deleted done")
349344

350345
d.mu.Lock()
351346
defer d.mu.Unlock()
@@ -361,5 +356,4 @@ func (d *Dispatch) handlePodDeleted(pod *corev1.Pod) {
361356

362357
delete(d.ctxs, instanceID)
363358

364-
log.WithField("instanceID", instanceID).Debugf("POD DELETED DONE: %s", instanceID)
365359
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,9 +961,6 @@ func (wbs *InWorkspaceServiceServer) Teardown(ctx context.Context, req *api.Tear
961961
owi := wbs.Session.OWI()
962962
log := log.WithFields(owi)
963963

964-
log.Debug("TEARDOWN")
965-
defer log.Debug("TEARDOWN DONE")
966-
967964
var (
968965
success = true
969966
err error
@@ -981,8 +978,9 @@ func (wbs *InWorkspaceServiceServer) Teardown(ctx context.Context, req *api.Tear
981978
// WipingTeardown tears down every state we created using IWS
982979
func (wbs *InWorkspaceServiceServer) WipingTeardown(ctx context.Context, req *api.WipingTeardownRequest) (*api.WipingTeardownResponse, error) {
983980
log := log.WithFields(wbs.Session.OWI())
984-
log.WithField("doWipe", req.DoWipe).Debug("WIPING TEARDOWN")
985-
defer log.WithField("doWipe", req.DoWipe).Debug("WIPING TEARDOWN DONE")
981+
log.WithField("doWipe", req.DoWipe).Debug("iws.WipingTeardown")
982+
defer log.WithField("doWipe", req.DoWipe).Debug("iws.WipingTeardown done")
983+
986984
if !req.DoWipe {
987985
return &api.WipingTeardownResponse{Success: true}, nil
988986
}

0 commit comments

Comments
 (0)