@@ -120,6 +120,13 @@ func getSpecCommonPVCCleanupJob(workspace *common.DevWorkspaceWithConfig, cluste
120120 pvcName = workspace .Config .Workspace .PVCName
121121 }
122122
123+ targetNode , err := getCommonPVCTargetNode (workspace , clusterAPI )
124+ if err != nil {
125+ clusterAPI .Logger .Info ("Error getting target node for PVC" , "PVC" , fmt .Sprintf ("%s/%s" , workspace .Namespace , workspace .Config .Workspace .PVCName ), "error" , err )
126+ } else if targetNode == "" {
127+ clusterAPI .Logger .Info ("PVC does not have a target node annotation" , "PVC" , fmt .Sprintf ("%s/%s" , workspace .Namespace , workspace .Config .Workspace .PVCName ))
128+ }
129+
123130 jobLabels := map [string ]string {
124131 constants .DevWorkspaceIDLabel : workspaceId ,
125132 constants .DevWorkspaceNameLabel : workspace .Name ,
@@ -189,11 +196,30 @@ func getSpecCommonPVCCleanupJob(workspace *common.DevWorkspaceWithConfig, cluste
189196 },
190197 },
191198 },
199+ Affinity : & corev1.Affinity {},
192200 },
193201 },
194202 },
195203 }
196204
205+ if targetNode != "" {
206+ job .Spec .Template .Spec .Affinity .NodeAffinity = & corev1.NodeAffinity {
207+ RequiredDuringSchedulingIgnoredDuringExecution : & corev1.NodeSelector {
208+ NodeSelectorTerms : []corev1.NodeSelectorTerm {
209+ {
210+ MatchExpressions : []corev1.NodeSelectorRequirement {
211+ {
212+ Key : "kubernetes.io/hostname" ,
213+ Operator : corev1 .NodeSelectorOpIn ,
214+ Values : []string {targetNode },
215+ },
216+ },
217+ },
218+ },
219+ },
220+ }
221+ }
222+
197223 podTolerations , nodeSelector , err := nsconfig .GetNamespacePodTolerationsAndNodeSelector (workspace .Namespace , clusterAPI )
198224 if err != nil {
199225 return nil , err
@@ -226,3 +252,22 @@ func commonPVCExists(workspace *common.DevWorkspaceWithConfig, clusterAPI sync.C
226252 }
227253 return true , nil
228254}
255+
256+ func getCommonPVCTargetNode (workspace * common.DevWorkspaceWithConfig , clusterAPI sync.ClusterAPI ) (string , error ) {
257+ namespacedName := types.NamespacedName {
258+ Name : workspace .Config .Workspace .PVCName ,
259+ Namespace : workspace .Namespace ,
260+ }
261+ pvc := & corev1.PersistentVolumeClaim {}
262+ err := clusterAPI .Client .Get (clusterAPI .Ctx , namespacedName , pvc )
263+ if err != nil {
264+ return "" , err
265+ }
266+
267+ targetNode := ""
268+ if pvc .Annotations != nil {
269+ targetNode = pvc .Annotations [constants .SelectedNodeAnnotation ]
270+ }
271+
272+ return targetNode , nil
273+ }
0 commit comments