@@ -1054,6 +1054,7 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
1054
1054
}
1055
1055
}
1056
1056
1057
+ var snc wsdaemon.WorkspaceContentServiceClient
1057
1058
doBackup := wso .WasEverReady () && ! wso .IsWorkspaceHeadless ()
1058
1059
doBackupLogs := tpe == api .WorkspaceType_PREBUILD
1059
1060
doSnapshot := tpe == api .WorkspaceType_PREBUILD
@@ -1069,49 +1070,22 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
1069
1070
return & csapi.GitStatus {}, nil
1070
1071
}
1071
1072
1072
- // we're not yet finalizing - start the process
1073
- snc , err := m .manager .connectToWorkspaceDaemon (ctx , * wso )
1074
- if err != nil {
1075
- tracing .LogError (span , err )
1076
- return nil , status .Errorf (codes .Unavailable , "cannot connect to workspace daemon: %q" , err )
1077
- }
1078
-
1079
- var workspaceExistsResult * wsdaemon.IsWorkspaceExistsResponse
1080
- workspaceExistsResult , err = snc .IsWorkspaceExists (ctx , & wsdaemon.IsWorkspaceExistsRequest {Id : workspaceID })
1081
- if err != nil {
1082
- tracing .LogError (span , err )
1083
- return nil , err
1084
- }
1085
- if ! workspaceExistsResult .Exists {
1086
- // nothing to backup, workspace does not exist
1087
- return nil , status .Error (codes .NotFound , "workspace does not exist" )
1088
- }
1089
-
1090
- // make sure that workspace was ready, otherwise there is no need to backup anything
1091
- // as we might backup corrupted workspace state
1092
- // this also ensures that if INITIALIZING still going, that we will wait for it to finish before disposing the workspace
1093
- _ , err = snc .WaitForInit (ctx , & wsdaemon.WaitForInitRequest {Id : workspaceID })
1094
- if err != nil {
1095
- tracing .LogError (span , err )
1096
- return nil , err
1097
- }
1098
-
1099
- // only set status to started if we actually confirmed that workspace is ready and we are about to do actual disposal
1100
- // otherwise we risk overwriting previous disposal status
1101
- if ! markedDisposalStatusStarted {
1102
- statusStarted := & workspaceDisposalStatus {
1103
- Status : DisposalStarted ,
1104
- }
1105
- err = m .manager .markDisposalStatus (ctx , workspaceID , statusStarted )
1106
- if err != nil {
1107
- tracing .LogError (span , err )
1108
- log .WithError (err ).Error ("was unable to update pod's start disposal status - this might cause an incorrect disposal status" )
1109
- } else {
1110
- markedDisposalStatusStarted = true
1073
+ if pvcFeatureEnabled {
1074
+ // only set status to started if we actually confirmed that workspace is ready and we are about to do actual disposal
1075
+ // otherwise we risk overwriting previous disposal status
1076
+ if ! markedDisposalStatusStarted {
1077
+ statusStarted := & workspaceDisposalStatus {
1078
+ Status : DisposalStarted ,
1079
+ }
1080
+ err = m .manager .markDisposalStatus (ctx , workspaceID , statusStarted )
1081
+ if err != nil {
1082
+ tracing .LogError (span , err )
1083
+ log .WithError (err ).Error ("was unable to update pod's start disposal status - this might cause an incorrect disposal status" )
1084
+ } else {
1085
+ markedDisposalStatusStarted = true
1086
+ }
1111
1087
}
1112
- }
1113
1088
1114
- if pvcFeatureEnabled {
1115
1089
// pvc was created with the name of the pod. see createDefiniteWorkspacePod()
1116
1090
pvcName := wso .Pod .Name
1117
1091
if ! createdVolumeSnapshot {
@@ -1267,6 +1241,48 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
1267
1241
deletedPVC = true
1268
1242
}
1269
1243
} else if doSnapshot {
1244
+ // we're not yet finalizing - start the process
1245
+ snc , err = m .manager .connectToWorkspaceDaemon (ctx , * wso )
1246
+ if err != nil {
1247
+ tracing .LogError (span , err )
1248
+ return nil , status .Errorf (codes .Unavailable , "cannot connect to workspace daemon: %q" , err )
1249
+ }
1250
+
1251
+ var workspaceExistsResult * wsdaemon.IsWorkspaceExistsResponse
1252
+ workspaceExistsResult , err = snc .IsWorkspaceExists (ctx , & wsdaemon.IsWorkspaceExistsRequest {Id : workspaceID })
1253
+ if err != nil {
1254
+ tracing .LogError (span , err )
1255
+ return nil , err
1256
+ }
1257
+ if ! workspaceExistsResult .Exists {
1258
+ // nothing to backup, workspace does not exist
1259
+ return nil , status .Error (codes .NotFound , "workspace does not exist" )
1260
+ }
1261
+
1262
+ // make sure that workspace was ready, otherwise there is no need to backup anything
1263
+ // as we might backup corrupted workspace state
1264
+ // this also ensures that if INITIALIZING still going, that we will wait for it to finish before disposing the workspace
1265
+ _ , err = snc .WaitForInit (ctx , & wsdaemon.WaitForInitRequest {Id : workspaceID })
1266
+ if err != nil {
1267
+ tracing .LogError (span , err )
1268
+ return nil , err
1269
+ }
1270
+
1271
+ // only set status to started if we actually confirmed that workspace is ready and we are about to do actual disposal
1272
+ // otherwise we risk overwriting previous disposal status
1273
+ if ! markedDisposalStatusStarted {
1274
+ statusStarted := & workspaceDisposalStatus {
1275
+ Status : DisposalStarted ,
1276
+ }
1277
+ err = m .manager .markDisposalStatus (ctx , workspaceID , statusStarted )
1278
+ if err != nil {
1279
+ tracing .LogError (span , err )
1280
+ log .WithError (err ).Error ("was unable to update pod's start disposal status - this might cause an incorrect disposal status" )
1281
+ } else {
1282
+ markedDisposalStatusStarted = true
1283
+ }
1284
+ }
1285
+
1270
1286
// if this is a prebuild take a snapshot and mark the workspace
1271
1287
var res * wsdaemon.TakeSnapshotResponse
1272
1288
res , err = snc .TakeSnapshot (ctx , & wsdaemon.TakeSnapshotRequest {Id : workspaceID })
@@ -1296,6 +1312,13 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
1296
1312
1297
1313
// DiposeWorkspace will "degenerate" to a simple wait if the finalization/disposal process is already running.
1298
1314
// This is unlike the initialization process where we wait for things to finish in a later phase.
1315
+ // we're not yet finalizing - start the process
1316
+ snc , err = m .manager .connectToWorkspaceDaemon (ctx , * wso )
1317
+ if err != nil {
1318
+ tracing .LogError (span , err )
1319
+ return nil , status .Errorf (codes .Unavailable , "cannot connect to workspace daemon: %q" , err )
1320
+ }
1321
+
1299
1322
resp , err := snc .DisposeWorkspace (ctx , & wsdaemon.DisposeWorkspaceRequest {
1300
1323
Id : workspaceID ,
1301
1324
Backup : doBackup && ! pvcFeatureEnabled ,
0 commit comments