Skip to content

Commit 0a68903

Browse files
utam0kroboquat
authored andcommitted
ws-manager: Refactor the annotation bool string.
1 parent 38a40f9 commit 0a68903

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package util
6+
7+
const (
8+
BooleanTrueString = "true"
9+
)

components/ws-manager/pkg/manager/monitor.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
wsk8s "github.com/gitpod-io/gitpod/common-go/kubernetes"
3535
"github.com/gitpod-io/gitpod/common-go/log"
3636
"github.com/gitpod-io/gitpod/common-go/tracing"
37+
"github.com/gitpod-io/gitpod/common-go/util"
3738
csapi "github.com/gitpod-io/gitpod/content-service/api"
3839
wsdaemon "github.com/gitpod-io/gitpod/ws-daemon/api"
3940
"github.com/gitpod-io/gitpod/ws-manager/api"
@@ -273,7 +274,7 @@ func actOnPodEvent(ctx context.Context, m actingManager, status *api.WorkspaceSt
273274
if status.Conditions.Failed != "" && !hasFailureAnnotation {
274275
// If this marking operation failes that's ok - we'll still continue to shut down the workspace.
275276
// The failure message won't persist while stopping the workspace though.
276-
err := m.markWorkspace(ctx, workspaceID, addMark(workspaceFailedBeforeStoppingAnnotation, "true"))
277+
err := m.markWorkspace(ctx, workspaceID, addMark(workspaceFailedBeforeStoppingAnnotation, util.BooleanTrueString))
277278
if err != nil {
278279
log.WithFields(wsk8s.GetOWIFromObject(&pod.ObjectMeta)).WithError(err).Debug("cannot mark workspace as workspaceFailedBeforeStoppingAnnotation")
279280
}
@@ -385,22 +386,20 @@ func actOnPodEvent(ctx context.Context, m actingManager, status *api.WorkspaceSt
385386
_, alreadyFinalized := wso.Pod.Annotations[startedDisposalAnnotation]
386387

387388
if (terminated || gone) && !alreadyFinalized {
388-
if isFailed, ok := wso.Pod.Annotations[workspaceFailedBeforeStoppingAnnotation]; ok && isFailed == "true" {
389-
if neverReady, ok := wso.Pod.Annotations[workspaceNeverReadyAnnotation]; ok && neverReady == "true" {
390-
// The workspace is never ready, so there is no need for a finalizer.
391-
if _, ok := pod.Annotations[workspaceExplicitFailAnnotation]; !ok {
392-
failMessage := status.Conditions.Failed
393-
if failMessage == "" {
394-
failMessage = "workspace failed to start."
395-
}
396-
err := m.markWorkspace(ctx, workspaceID, addMark(workspaceExplicitFailAnnotation, failMessage))
397-
if err != nil {
398-
log.WithError(err).Error("was unable to mark workspace as failed")
399-
}
389+
if wso.Pod.Annotations[workspaceFailedBeforeStoppingAnnotation] == util.BooleanTrueString && wso.Pod.Annotations[workspaceNeverReadyAnnotation] == util.BooleanTrueString {
390+
// The workspace is never ready, so there is no need for a finalizer.
391+
if _, ok := pod.Annotations[workspaceExplicitFailAnnotation]; !ok {
392+
failMessage := status.Conditions.Failed
393+
if failMessage == "" {
394+
failMessage = "workspace failed to start."
395+
}
396+
err := m.markWorkspace(ctx, workspaceID, addMark(workspaceExplicitFailAnnotation, failMessage))
397+
if err != nil {
398+
log.WithError(err).Error("was unable to mark workspace as failed")
400399
}
401-
402-
return m.modifyFinalizer(ctx, workspaceID, gitpodFinalizerName, false)
403400
}
401+
402+
return m.modifyFinalizer(ctx, workspaceID, gitpodFinalizerName, false)
404403
} else {
405404
// We start finalizing the workspace content only after the container is gone. This way we ensure there's
406405
// no process modifying the workspace content as we create the backup.
@@ -941,7 +940,7 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
941940
m.finalizerMapLock.Unlock()
942941
}()
943942

944-
err = m.manager.markWorkspace(ctx, workspaceID, addMark(startedDisposalAnnotation, "true"))
943+
err = m.manager.markWorkspace(ctx, workspaceID, addMark(startedDisposalAnnotation, util.BooleanTrueString))
945944
if err != nil {
946945
log.WithError(err).Error("was unable to update pod's start disposal state - this might cause an incorrect disposal state")
947946
}

0 commit comments

Comments
 (0)