@@ -39,7 +39,7 @@ import (
39
39
"github.com/gitpod-io/gitpod/ws-manager/api"
40
40
"github.com/gitpod-io/gitpod/ws-manager/pkg/manager/internal/workpool"
41
41
42
- volumesnapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v6 /apis/volumesnapshot/v1"
42
+ volumesnapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v4 /apis/volumesnapshot/v1"
43
43
)
44
44
45
45
const (
@@ -870,13 +870,13 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
870
870
deletedPVC bool
871
871
pvcFeatureEnabled bool
872
872
markVolumeSnapshotAnnotation bool
873
- pvcVolumeSnapshotName string
873
+ // volume snapshot name is 1:1 mapped to workspace id
874
+ pvcVolumeSnapshotName string = workspaceID
874
875
pvcVolumeSnapshotContentName string
875
876
pvcVolumeSnapshotClassName string
876
877
)
877
878
if wso .Pod != nil {
878
879
_ , pvcFeatureEnabled = wso .Pod .Labels [pvcWorkspaceFeatureAnnotation ]
879
- pvcVolumeSnapshotName = workspaceID
880
880
wsClassName := ""
881
881
if _ , ok := wso .Pod .Labels [workspaceClassLabel ]; ok {
882
882
wsClassName = wso .Pod .Labels [workspaceClassLabel ]
@@ -929,16 +929,14 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
929
929
}
930
930
931
931
if pvcFeatureEnabled {
932
+ // pvc was created with the name of the pod. see createDefiniteWorkspacePod()
932
933
pvcName := wso .Pod .Name
933
934
if ! createdVolumeSnapshot {
934
935
// create snapshot object out of PVC
935
936
volumeSnapshot := & volumesnapshotv1.VolumeSnapshot {
936
937
ObjectMeta : metav1.ObjectMeta {
937
938
Name : pvcVolumeSnapshotName ,
938
939
Namespace : m .manager .Config .Namespace ,
939
- Labels : map [string ]string {
940
- "workspaceID" : workspaceID ,
941
- },
942
940
},
943
941
Spec : volumesnapshotv1.VolumeSnapshotSpec {
944
942
Source : volumesnapshotv1.VolumeSnapshotSource {
@@ -949,7 +947,7 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
949
947
}
950
948
951
949
err = m .manager .Clientset .Create (ctx , volumeSnapshot )
952
- if err != nil {
950
+ if err != nil && ! k8serr . IsAlreadyExists ( err ) {
953
951
err = xerrors .Errorf ("cannot create volumesnapshot: %v" , err )
954
952
return true , nil , err
955
953
}
@@ -963,6 +961,7 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
963
961
Jitter : 0.1 ,
964
962
Cap : 10 * time .Minute ,
965
963
}
964
+ log = log .WithField ("VolumeSnapshot.Name" , pvcVolumeSnapshotName )
966
965
err = wait .ExponentialBackoff (backoff , func () (bool , error ) {
967
966
var volumeSnapshot volumesnapshotv1.VolumeSnapshot
968
967
err := m .manager .Clientset .Get (ctx , types.NamespacedName {Namespace : m .manager .Config .Namespace , Name : pvcVolumeSnapshotName }, & volumeSnapshot )
@@ -971,37 +970,38 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
971
970
// volumesnapshot doesn't exist yet, retry again
972
971
return false , nil
973
972
}
974
- log .WithError (err ).WithField ( "VolumeSnapshot.Name" , pvcVolumeSnapshotName ). Error ("was unable to get volume snapshot" )
973
+ log .WithError (err ).Error ("was unable to get volume snapshot" )
975
974
return false , err
976
975
}
977
976
if volumeSnapshot .Status != nil {
978
- if volumeSnapshot .Status .ReadyToUse != nil && * (volumeSnapshot .Status .ReadyToUse ) {
977
+ if volumeSnapshot .Status .ReadyToUse != nil && * (volumeSnapshot .Status .ReadyToUse ) && volumeSnapshot . Status . BoundVolumeSnapshotContentName != nil {
979
978
pvcVolumeSnapshotContentName = * volumeSnapshot .Status .BoundVolumeSnapshotContentName
980
979
return true , nil
981
980
}
982
981
if volumeSnapshot .Status .Error != nil {
983
982
if volumeSnapshot .Status .Error .Message != nil {
984
983
err = xerrors .Errorf ("error during volume snapshot creation: %s" , * volumeSnapshot .Status .Error .Message )
985
- log .WithError (err ).WithField ( "VolumeSnapshot.Name" , pvcVolumeSnapshotName ). Error ("unable to create volume snapshot" )
984
+ log .WithError (err ).Error ("unable to create volume snapshot" )
986
985
return false , err
987
986
}
988
- log .WithField ( "VolumeSnapshot.Name" , pvcVolumeSnapshotName ). Error ("unknown error during volume snapshot creation" )
987
+ log .Error ("unknown error during volume snapshot creation" )
989
988
return false , xerrors .Errorf ("unknown error during volume snapshot creation" )
990
989
}
991
990
}
992
991
return false , nil
993
992
})
994
993
if err != nil {
995
- log .WithError (err ).WithField ( "VolumeSnapshot.Name" , pvcVolumeSnapshotName ). Errorf ("failed while waiting for volume snapshot to get ready" )
994
+ log .WithError (err ).Errorf ("failed while waiting for volume snapshot to get ready" )
996
995
return true , nil , err
997
996
}
998
997
readyVolumeSnapshot = true
999
998
}
1000
999
if readyVolumeSnapshot && ! markVolumeSnapshotAnnotation {
1000
+ log = log .WithField ("VolumeSnapshotContent.Name" , pvcVolumeSnapshotContentName )
1001
1001
var volumeSnapshotContent volumesnapshotv1.VolumeSnapshotContent
1002
1002
err := m .manager .Clientset .Get (ctx , types.NamespacedName {Namespace : "" , Name : pvcVolumeSnapshotContentName }, & volumeSnapshotContent )
1003
1003
if err != nil {
1004
- log .WithError (err ).WithField ( "VolumeSnapshotContent.Name" , pvcVolumeSnapshotContentName ). Error ("was unable to get volume snapshot content" )
1004
+ log .WithError (err ).Error ("was unable to get volume snapshot content" )
1005
1005
return true , nil , err
1006
1006
}
1007
1007
@@ -1038,38 +1038,36 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
1038
1038
},
1039
1039
},
1040
1040
)
1041
- if pvcErr != nil {
1041
+ if pvcErr != nil && ! k8serr . IsNotFound ( pvcErr ) {
1042
1042
log .WithError (pvcErr ).Errorf ("failed to delete pvc `%s`" , pvcName )
1043
1043
}
1044
1044
deletedPVC = true
1045
1045
}
1046
- } else {
1047
- if doSnapshot {
1048
- // if this is a prebuild take a snapshot and mark the workspace
1049
- var res * wsdaemon.TakeSnapshotResponse
1050
- res , err = snc .TakeSnapshot (ctx , & wsdaemon.TakeSnapshotRequest {Id : workspaceID })
1046
+ } else if doSnapshot {
1047
+ // if this is a prebuild take a snapshot and mark the workspace
1048
+ var res * wsdaemon.TakeSnapshotResponse
1049
+ res , err = snc .TakeSnapshot (ctx , & wsdaemon.TakeSnapshotRequest {Id : workspaceID })
1050
+ if err != nil {
1051
+ tracing .LogError (span , err )
1052
+ log .WithError (err ).Warn ("cannot take snapshot" )
1053
+ err = xerrors .Errorf ("cannot take snapshot: %v" , err )
1054
+ err = m .manager .markWorkspace (ctx , workspaceID , addMark (workspaceExplicitFailAnnotation , err .Error ()))
1055
+ if err != nil {
1056
+ log .WithError (err ).Warn ("was unable to mark workspace as failed" )
1057
+ }
1058
+ }
1059
+
1060
+ if res != nil {
1061
+ err = m .manager .markWorkspace (context .Background (), workspaceID , addMark (workspaceSnapshotAnnotation , res .Url ))
1051
1062
if err != nil {
1052
1063
tracing .LogError (span , err )
1053
- log .WithError (err ).Warn ("cannot take snapshot" )
1054
- err = xerrors .Errorf ("cannot take snapshot: %v" , err )
1064
+ log .WithError (err ).Warn ("cannot mark headless workspace with snapshot - that's one prebuild lost " )
1065
+ err = xerrors .Errorf ("cannot remember snapshot: %v" , err )
1055
1066
err = m .manager .markWorkspace (ctx , workspaceID , addMark (workspaceExplicitFailAnnotation , err .Error ()))
1056
1067
if err != nil {
1057
1068
log .WithError (err ).Warn ("was unable to mark workspace as failed" )
1058
1069
}
1059
1070
}
1060
-
1061
- if res != nil {
1062
- err = m .manager .markWorkspace (context .Background (), workspaceID , addMark (workspaceSnapshotAnnotation , res .Url ))
1063
- if err != nil {
1064
- tracing .LogError (span , err )
1065
- log .WithError (err ).Warn ("cannot mark headless workspace with snapshot - that's one prebuild lost" )
1066
- err = xerrors .Errorf ("cannot remember snapshot: %v" , err )
1067
- err = m .manager .markWorkspace (ctx , workspaceID , addMark (workspaceExplicitFailAnnotation , err .Error ()))
1068
- if err != nil {
1069
- log .WithError (err ).Warn ("was unable to mark workspace as failed" )
1070
- }
1071
- }
1072
- }
1073
1071
}
1074
1072
}
1075
1073
0 commit comments