Skip to content

Commit a7fe67d

Browse files
utam0kroboquat
utam0k
authored andcommitted
ws-manager: Prevent to slip the CREATING phase
1 parent 67d810e commit a7fe67d

File tree

3 files changed

+53
-27
lines changed

3 files changed

+53
-27
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,19 @@ func actOnPodEvent(ctx context.Context, m actingManager, manager *Manager, statu
317317
// The workspace has been scheduled on the cluster which means that we can start initializing it
318318
go func() {
319319
err := m.initializeWorkspaceContent(ctx, pod)
320-
321320
if err != nil {
322321
// workspace initialization failed, which means the workspace as a whole failed
323322
err = m.markWorkspace(ctx, workspaceID, addMark(workspaceExplicitFailAnnotation, err.Error()))
324323
if err != nil {
325324
log.WithError(err).Warn("was unable to mark workspace as failed")
326325
}
327326
}
327+
328+
err = m.markWorkspace(ctx, workspaceID, addMark(alreadyInitializingAnnotation, util.BooleanTrueString))
329+
if err != nil {
330+
log.WithError(err).Warn("was unable to mark workspace as already initializing")
331+
}
332+
328333
}()
329334

330335
case api.WorkspacePhase_INITIALIZING:

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

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,34 @@ type PodReconciler struct {
3333
// For more details, check Reconcile and its Result here:
3434
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
3535
func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
36-
go func() {
37-
var pod corev1.Pod
38-
err := r.Client.Get(context.Background(), req.NamespacedName, &pod)
39-
if errors.IsNotFound(err) {
40-
// pod is gone - that's ok
41-
if pod, ok := r.Pods[req.NamespacedName]; ok {
42-
delete(r.Pods, req.NamespacedName)
43-
queue := pod.Annotations[workspaceIDAnnotation]
44-
if queue == "" {
45-
return
46-
}
47-
r.Monitor.eventpool.Add(queue, watch.Event{
48-
Type: watch.Deleted,
49-
Object: &pod,
50-
})
36+
var pod corev1.Pod
37+
err := r.Client.Get(context.Background(), req.NamespacedName, &pod)
38+
if errors.IsNotFound(err) {
39+
// pod is gone - that's ok
40+
if pod, ok := r.Pods[req.NamespacedName]; ok {
41+
delete(r.Pods, req.NamespacedName)
42+
queue := pod.Annotations[workspaceIDAnnotation]
43+
if queue == "" {
44+
return ctrl.Result{}, nil
5145
}
52-
return
46+
r.Monitor.eventpool.Add(queue, watch.Event{
47+
Type: watch.Deleted,
48+
Object: &pod,
49+
})
5350
}
54-
r.Pods[req.NamespacedName] = pod
51+
return ctrl.Result{}, nil
52+
}
53+
r.Pods[req.NamespacedName] = pod
5554

56-
queue := pod.Annotations[workspaceIDAnnotation]
57-
if queue == "" {
58-
return
59-
}
55+
queue := pod.Annotations[workspaceIDAnnotation]
56+
if queue == "" {
57+
return ctrl.Result{}, nil
58+
}
6059

61-
r.Monitor.eventpool.Add(queue, watch.Event{
62-
Type: watch.Modified,
63-
Object: &pod,
64-
})
65-
}()
60+
r.Monitor.eventpool.Add(queue, watch.Event{
61+
Type: watch.Modified,
62+
Object: &pod,
63+
})
6664

6765
return ctrl.Result{}, nil
6866
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ func (wso *workspaceObjects) WasEverReady() (res bool) {
125125
return true
126126
}
127127

128+
func (wso *workspaceObjects) AlreadyInitializing() (res bool) {
129+
check := func(a map[string]string) bool {
130+
v, ok := a[alreadyInitializingAnnotation]
131+
if !ok {
132+
return false
133+
}
134+
return v == util.BooleanTrueString
135+
}
136+
137+
if wso.Pod != nil {
138+
return check(wso.Pod.Annotations)
139+
}
140+
141+
return true
142+
}
143+
128144
// HostName returns the name of the node this workspace is/was deployed to. If this workspace has never been deployed anywhere, HostName returns an empty string.
129145
func (wso *workspaceObjects) NodeName() string {
130146
if wso.Pod == nil {
@@ -486,6 +502,13 @@ func (m *Manager) extractStatusFromPod(result *api.WorkspaceStatus, wso workspac
486502
return nil
487503
}
488504

505+
// the pod phase of pending is somtimes slipped because it may not be PENDING at the stage of retrieving information on the workspace pod.
506+
if !wso.AlreadyInitializing() {
507+
result.Phase = api.WorkspacePhase_CREATING
508+
result.Message = "pod is running but init has not started yet or is not finished"
509+
return nil
510+
}
511+
489512
if _, neverReady := pod.Annotations[workspaceNeverReadyAnnotation]; !neverReady {
490513
// workspcae has been marked ready by a workspace-ready probe of the monitor
491514
result.Phase = api.WorkspacePhase_RUNNING

0 commit comments

Comments
 (0)