@@ -294,11 +294,11 @@ func workspaceFilter() predicate.Predicate {
294294 UpdateFunc : func (e event.UpdateEvent ) bool {
295295 wsOld := e .ObjectOld .(* workspacev1.Workspace )
296296 ws := e .ObjectNew .(* workspacev1.Workspace )
297- if wsOld .Status .Runtime == nil && ws .Status .Runtime != nil {
297+ // if we haven't seen runtime info before and now it's there, let's reconcile
298+ if wsOld .Status .Runtime == nil && ws .Status .Runtime != nil && ws .Status .Runtime .NodeName != "" {
298299 return true
299300 }
300301
301- // if we've seen runtime info before, there's no need to reconcile again
302302 return false
303303 },
304304 DeleteFunc : func (e event.DeleteEvent ) bool {
@@ -333,13 +333,13 @@ func (wc *WorkspaceCountController) Reconcile(ctx context.Context, req ctrl.Requ
333333 nodeName := ws .Status .Runtime .NodeName
334334 for _ , ws := range workspaceList .Items {
335335 if ws .Status .Runtime != nil &&
336- ws .Status .Runtime .NodeName == nodeName &&
337- ws .DeletionTimestamp .IsZero () {
336+ ws .Status .Runtime .NodeName == nodeName {
338337 count ++
339338 }
340339 }
341340
342341 if err := wc .updateNodeAnnotation (ctx , nodeName , count ); err != nil {
342+ log .WithError (err ).WithField ("node" , nodeName ).Error ("failed to update node" )
343343 return ctrl.Result {}, err
344344 }
345345 log .WithField ("node" , nodeName ).WithField ("count" , count ).Info ("updated node annotation" )
@@ -358,8 +358,7 @@ func (wc *WorkspaceCountController) reconcileAllNodes(ctx context.Context) (ctrl
358358 workspaceCounts := make (map [string ]int )
359359 for _ , ws := range workspaceList .Items {
360360 if ws .Status .Runtime != nil &&
361- ws .Status .Runtime .NodeName != "" &&
362- ws .DeletionTimestamp .IsZero () {
361+ ws .Status .Runtime .NodeName != "" {
363362 workspaceCounts [ws .Status .Runtime .NodeName ]++
364363 }
365364 }
@@ -384,6 +383,9 @@ func (wc *WorkspaceCountController) reconcileAllNodes(ctx context.Context) (ctrl
384383
385384func (wc * WorkspaceCountController ) updateNodeAnnotation (ctx context.Context , nodeName string , count int ) error {
386385 return retry .RetryOnConflict (retry .DefaultBackoff , func () error {
386+ ctx , cancel := context .WithTimeout (ctx , 5 * time .Second )
387+ defer cancel ()
388+
387389 var node corev1.Node
388390 err := wc .Get (ctx , types.NamespacedName {Name : nodeName }, & node )
389391 if err != nil {
0 commit comments