@@ -120,6 +120,13 @@ func getSpecCommonPVCCleanupJob(workspace *common.DevWorkspaceWithConfig, cluste
120
120
pvcName = workspace .Config .Workspace .PVCName
121
121
}
122
122
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
+
123
130
jobLabels := map [string ]string {
124
131
constants .DevWorkspaceIDLabel : workspaceId ,
125
132
constants .DevWorkspaceNameLabel : workspace .Name ,
@@ -189,11 +196,30 @@ func getSpecCommonPVCCleanupJob(workspace *common.DevWorkspaceWithConfig, cluste
189
196
},
190
197
},
191
198
},
199
+ Affinity : & corev1.Affinity {},
192
200
},
193
201
},
194
202
},
195
203
}
196
204
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
+
197
223
podTolerations , nodeSelector , err := nsconfig .GetNamespacePodTolerationsAndNodeSelector (workspace .Namespace , clusterAPI )
198
224
if err != nil {
199
225
return nil , err
@@ -226,3 +252,22 @@ func commonPVCExists(workspace *common.DevWorkspaceWithConfig, clusterAPI sync.C
226
252
}
227
253
return true , nil
228
254
}
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