Skip to content

Commit

Permalink
[ws-manager-mk2] Remove headless from status (#16530)
Browse files Browse the repository at this point in the history
  • Loading branch information
WVerlaek authored Feb 23, 2023
1 parent 26c520c commit df3e15a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (wsc *WorkspaceController) handleWorkspaceInit(ctx context.Context, ws *wor
InstanceId: ws.Name,
},
Initializer: &init,
Headless: ws.Status.Headless,
Headless: ws.IsHeadless(),
})

if alreadyInit {
Expand Down
9 changes: 9 additions & 0 deletions components/ws-manager-api/go/crd/v1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ type WorkspaceList struct {
Items []Workspace `json:"items"`
}

// IsHeadless returns whether the workspace is a headless type.
// This is added as a function on the workspace, instead of a field
// in the status, to make it easier to consume and not e.g. have to
// wait for the first reconcile of a workspace to set the status
// resource.
func (w *Workspace) IsHeadless() bool {
return w.Spec.Type != WorkspaceTypeRegular
}

func init() {
SchemeBuilder.Register(&Workspace{}, &WorkspaceList{})
}
8 changes: 2 additions & 6 deletions components/ws-manager-mk2/controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ func updateWorkspaceStatus(ctx context.Context, workspace *workspacev1.Workspace
workspace.Status.Runtime.PodName = pod.Name
}

if workspace.Spec.Type != workspacev1.WorkspaceTypeRegular {
workspace.Status.Headless = true
}

if workspace.Status.URL == "" {
url, err := config.RenderWorkspaceURL(cfg.WorkspaceURLTemplate, workspace.Name, workspace.Spec.Ownership.WorkspaceID, cfg.GitpodHostURL)
if err != nil {
Expand Down Expand Up @@ -172,7 +168,7 @@ func updateWorkspaceStatus(ctx context.Context, workspace *workspacev1.Workspace
workspace.Status.Phase = workspacev1.WorkspacePhaseInitializing
}

case workspace.Status.Headless && (pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed):
case workspace.IsHeadless() && (pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed):
workspace.Status.Phase = workspacev1.WorkspacePhaseStopping

case pod.Status.Phase == corev1.PodUnknown:
Expand Down Expand Up @@ -249,7 +245,7 @@ func extractFailure(ws *workspacev1.Workspace, pod *corev1.Pod) (string, *worksp
return fmt.Sprintf("container %s ran with an error: exit code %d", cs.Name, terminationState.ExitCode), &phase
}
} else if terminationState.Reason == "Completed" && !isPodBeingDeleted(pod) {
if ws.Status.Headless {
if ws.IsHeadless() {
// headless workspaces are expected to finish
return "", nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (r *TimeoutReconciler) isWorkspaceTimedOut(ws *workspacev1.Workspace) (reas
timeout = util.Duration(customTimeout.Duration)
}
activity := activityNone
if ws.Status.Headless {
if ws.IsHeadless() {
timeout = timeouts.HeadlessWorkspace
lastActivity = &start
activity = activityRunningHeadless
Expand Down
16 changes: 10 additions & 6 deletions components/ws-manager-mk2/controllers/timeout_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var _ = Describe("TimeoutController", func() {
lastActivityAgo *time.Duration
age time.Duration
customTimeout *time.Duration
update func(ws *workspacev1.Workspace)
updateStatus func(ws *workspacev1.Workspace)
controllerRestart time.Time
expectTimeout bool
Expand All @@ -59,11 +60,14 @@ var _ = Describe("TimeoutController", func() {
r.activity.Store(ws.Name, now.Add(-*tc.lastActivityAgo))
}

if tc.customTimeout != nil {
updateObjWithRetries(fakeClient, ws, false, func(ws *workspacev1.Workspace) {
updateObjWithRetries(fakeClient, ws, false, func(ws *workspacev1.Workspace) {
if tc.customTimeout != nil {
ws.Spec.Timeout.Time = &metav1.Duration{Duration: *tc.customTimeout}
})
}
}
if tc.update != nil {
tc.update(ws)
}
})
updateObjWithRetries(fakeClient, ws, true, func(ws *workspacev1.Workspace) {
ws.Status.Phase = tc.phase
if tc.updateStatus != nil {
Expand Down Expand Up @@ -131,8 +135,8 @@ var _ = Describe("TimeoutController", func() {
}),
Entry("should timeout headless workspace", testCase{
phase: workspacev1.WorkspacePhaseRunning,
updateStatus: func(ws *workspacev1.Workspace) {
ws.Status.Headless = true
update: func(ws *workspacev1.Workspace) {
ws.Spec.Type = workspacev1.WorkspaceTypePrebuild
},
age: 2 * time.Hour,
lastActivityAgo: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var _ = Describe("WorkspaceController", func() {
g.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: ws.Name, Namespace: ws.Namespace}, ws)).To(Succeed())
g.Expect(ws.Status.OwnerToken).ToNot(BeEmpty())
g.Expect(ws.Status.URL).ToNot(BeEmpty())
g.Expect(ws.Status.Headless).To(BeFalse())
}, timeout, interval).Should(Succeed())

// TODO(wv): Once implemented, expect EverReady condition.
Expand Down Expand Up @@ -196,14 +195,8 @@ var _ = Describe("WorkspaceController", func() {
ws.Spec.Type = workspacev1.WorkspaceTypePrebuild
pod = createWorkspaceExpectPod(ws)

// Expect headless status to be reported.
Eventually(func() (bool, error) {
err := k8sClient.Get(ctx, types.NamespacedName{Name: ws.Name, Namespace: ws.Namespace}, ws)
if err != nil {
return false, err
}
return ws.Status.Headless, nil
}, timeout, interval).Should(BeTrue())
// Expect headless.
Expect(ws.IsHeadless()).To(BeTrue())

// Expect runtime status also gets reported for headless workspaces.
expectRuntimeStatus(ws, pod)
Expand Down
2 changes: 1 addition & 1 deletion components/ws-manager-mk2/service/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ func extractWorkspaceStatus(ws *workspacev1.Workspace) *wsmanapi.WorkspaceStatus
SupervisorRef: ws.Spec.Image.IDE.Supervisor,
},
IdeImageLayers: ws.Spec.Image.IDE.Refs,
Headless: ws.Status.Headless,
Headless: ws.IsHeadless(),
Url: ws.Status.URL,
Type: tpe,
Timeout: timeout,
Expand Down

0 comments on commit df3e15a

Please sign in to comment.