Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the pods be removed when workspacekit fails. #10085

Merged
merged 3 commits into from
May 25, 2022
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
9 changes: 9 additions & 0 deletions components/common-go/util/const_string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package util

const (
BooleanTrueString = "true"
)
27 changes: 22 additions & 5 deletions components/ws-manager/pkg/manager/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
wsk8s "github.com/gitpod-io/gitpod/common-go/kubernetes"
"github.com/gitpod-io/gitpod/common-go/log"
"github.com/gitpod-io/gitpod/common-go/tracing"
"github.com/gitpod-io/gitpod/common-go/util"
csapi "github.com/gitpod-io/gitpod/content-service/api"
wsdaemon "github.com/gitpod-io/gitpod/ws-daemon/api"
"github.com/gitpod-io/gitpod/ws-manager/api"
Expand Down Expand Up @@ -268,7 +269,7 @@ func actOnPodEvent(ctx context.Context, m actingManager, status *api.WorkspaceSt
if status.Conditions.Failed != "" && !hasFailureAnnotation {
// If this marking operation failes that's ok - we'll still continue to shut down the workspace.
// The failure message won't persist while stopping the workspace though.
err := m.markWorkspace(ctx, workspaceID, addMark(workspaceFailedBeforeStoppingAnnotation, "true"))
err := m.markWorkspace(ctx, workspaceID, addMark(workspaceFailedBeforeStoppingAnnotation, util.BooleanTrueString))
if err != nil {
log.WithFields(wsk8s.GetOWIFromObject(&pod.ObjectMeta)).WithError(err).Debug("cannot mark workspace as workspaceFailedBeforeStoppingAnnotation")
}
Expand Down Expand Up @@ -380,9 +381,25 @@ func actOnPodEvent(ctx context.Context, m actingManager, status *api.WorkspaceSt
_, alreadyFinalized := wso.Pod.Annotations[startedDisposalAnnotation]

if (terminated || gone) && !alreadyFinalized {
// We start finalizing the workspace content only after the container is gone. This way we ensure there's
// no process modifying the workspace content as we create the backup.
go m.finalizeWorkspaceContent(ctx, wso)
if wso.Pod.Annotations[workspaceFailedBeforeStoppingAnnotation] == util.BooleanTrueString && wso.Pod.Annotations[workspaceNeverReadyAnnotation] == util.BooleanTrueString {
// The workspace is never ready, so there is no need for a finalizer.
if _, ok := pod.Annotations[workspaceExplicitFailAnnotation]; !ok {
failMessage := status.Conditions.Failed
if failMessage == "" {
failMessage = "workspace failed to start."
}
err := m.markWorkspace(ctx, workspaceID, addMark(workspaceExplicitFailAnnotation, failMessage))
if err != nil {
log.WithError(err).Error("was unable to mark workspace as failed")
}
}

return m.modifyFinalizer(ctx, workspaceID, gitpodFinalizerName, false)
} else {
// We start finalizing the workspace content only after the container is gone. This way we ensure there's
// no process modifying the workspace content as we create the backup.
go m.finalizeWorkspaceContent(ctx, wso)
}
}
}

Expand Down Expand Up @@ -922,7 +939,7 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
m.finalizerMapLock.Unlock()
}()

err = m.manager.markWorkspace(ctx, workspaceID, addMark(startedDisposalAnnotation, "true"))
err = m.manager.markWorkspace(ctx, workspaceID, addMark(startedDisposalAnnotation, util.BooleanTrueString))
if err != nil {
log.WithError(err).Error("was unable to update pod's start disposal state - this might cause an incorrect disposal state")
}
Expand Down
5 changes: 5 additions & 0 deletions components/ws-manager/pkg/manager/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ func (m *Manager) extractStatusFromPod(result *api.WorkspaceStatus, wso workspac
// While the pod is being deleted we do not care or want to know about any failure state.
// If the pod got stopped because it failed we will have sent out a Stopping status with a "failure"
result.Conditions.Failed = ""
} else {
if _, ok := pod.Annotations[workspaceNeverReadyAnnotation]; ok {
// The workspace is never ready, so there is no need for a stopping phase.
result.Phase = api.WorkspacePhase_STOPPED
}
}

var hasFinalizer bool
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"actions": [
{
"Func": "clearInitializerFromMap",
"Params": {
"podName": "ws-7b26a643-d588-4346-bc9e-b46e70831078"
}
},
{
"Func": "modifyFinalizer",
"Params": {
"add": false,
"finalizer": "gitpod.io/finalizer",
"workspaceID": "7b26a643-d588-4346-bc9e-b46e70831078"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"status": {
"id": "7b26a643-d588-4346-bc9e-b46e70831078",
"status_version": 65536,
"metadata": {
"owner": "3dfdef07-76e2-46a6-b0d4-eb959befd0ab",
"meta_id": "gitpodio-templategolang-cdhvbek9fyg",
"started_at": {
"seconds": 1653358271
}
},
"spec": {
"workspace_image": "eu.gcr.io/gitpod-core-dev/build/workspace-images:8b57bd729e88889eca09e96051dea52300481b8561e3225140beae1a12d190f4",
"deprecated_ide_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-9e0960d85f0c30b1ce57c9d14e6a905bc46f427c",
"url": "https://gitpodio-templategolang-cdhvbek9fyg.ws.to-failed-ws-start.preview.gitpod-dev.com",
"timeout": "60m",
"ide_image": {
"web_ref": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-9e0960d85f0c30b1ce57c9d14e6a905bc46f427c",
"supervisor_ref": "eu.gcr.io/gitpod-core-dev/build/supervisor:commit-6d6849daab686ff22e610d57cdaf303eab7697b5"
},
"class": "default"
},
"phase": 6,
"conditions": {},
"runtime": {
"node_name": "to-failed-ws-start",
"pod_name": "ws-7b26a643-d588-4346-bc9e-b46e70831078",
"node_ip": "10.0.2.2"
},
"auth": {
"owner_token": "yuvxCAtPRTShLfVETMXck-a71dphVi_u"
}
}
}
Loading