@@ -223,28 +223,36 @@ func (wsc *WorkspaceController) handleWorkspaceRunning(ctx context.Context, ws *
223223
224224 var imageInfo * workspacev1.WorkspaceImageInfo = nil
225225 if ws .Status .ImageInfo == nil {
226- ctx , cancel := context .WithTimeout (ctx , 10 * time .Second )
227- defer cancel ()
228- id , err := wsc .runtime .WaitForContainer (ctx , ws .Name )
229- if err != nil {
230- return ctrl.Result {}, fmt .Errorf ("failed to wait for container: %w" , err )
231- }
232- info , err := wsc .runtime .GetContainerImageInfo (ctx , id )
233- if err != nil {
234- return ctrl.Result {}, fmt .Errorf ("failed to get container image info: %w" , err )
235- }
226+ getImageInfo := func () (* workspacev1.WorkspaceImageInfo , error ) {
227+ ctx , cancel := context .WithTimeout (ctx , 10 * time .Second )
228+ defer cancel ()
229+ id , err := wsc .runtime .WaitForContainer (ctx , ws .Name )
230+ if err != nil {
231+ return nil , fmt .Errorf ("failed to wait for container: %w" , err )
232+ }
233+ info , err := wsc .runtime .GetContainerImageInfo (ctx , id )
234+ if err != nil {
235+ return nil , fmt .Errorf ("failed to get container image info: %w" , err )
236+ }
236237
237- err = retry .RetryOnConflict (retryParams , func () error {
238- if err := wsc .Get (ctx , req .NamespacedName , ws ); err != nil {
239- return err
238+ err = retry .RetryOnConflict (retryParams , func () error {
239+ if err := wsc .Get (ctx , req .NamespacedName , ws ); err != nil {
240+ return err
241+ }
242+ ws .Status .ImageInfo = info
243+ return wsc .Status ().Update (ctx , ws )
244+ })
245+ if err != nil {
246+ return info , fmt .Errorf ("failed to update workspace with image info: %w" , err )
240247 }
241- ws . Status . ImageInfo = info
242- return wsc . Status (). Update ( ctx , ws )
243- } )
248+ return info , nil
249+ }
250+ imageInfo , err = getImageInfo ( )
244251 if err != nil {
245- glog .WithFields (ws .OWI ()).WithField ("workspace" , req .NamespacedName ).WithField ("phase" , ws .Status .Phase ).Errorf ("failed to update workspace with image info: %v" , err )
252+ glog .WithFields (ws .OWI ()).WithField ("workspace" , req .NamespacedName ).Errorf ("failed to get image info: %v" , err )
253+ } else {
254+ glog .WithFields (ws .OWI ()).WithField ("workspace" , req .NamespacedName ).WithField ("imageInfo" , glog.TrustedValueWrap {Value : imageInfo }).Info ("updated image info" )
246255 }
247- imageInfo = info
248256 }
249257 return ctrl.Result {}, wsc .operations .SetupWorkspace (ctx , ws .Name , imageInfo )
250258}
0 commit comments