28
28
soleTenancyValue = "sole-tenancy"
29
29
)
30
30
31
+ const podLabelAppName = "app.kubernetes.io/name"
32
+
31
33
// GetJobSet is called by the controller to return some JobSet based
32
34
// on the type: application, storage, or standalone
33
35
func GetJobSet (
@@ -45,7 +47,7 @@ func GetJobSet(
45
47
successJobs := getSuccessJobs (set .Metrics ())
46
48
47
49
// A base JobSet can hold one or more replicated jobs
48
- js := getBaseJobSet (spec , successJobs , set . HasSoleTenancy () )
50
+ js := getBaseJobSet (spec , successJobs )
49
51
50
52
// Get one or more replicated jobs, depending on the type
51
53
rjs , err := set .ReplicatedJobs (spec )
@@ -80,7 +82,7 @@ func getSuccessJobs(metrics []*Metric) []string {
80
82
}
81
83
82
84
// getBaseJobSet shared for either an application or isolated jobset
83
- func getBaseJobSet (set * api.MetricSet , successSet []string , soleTenancy bool ) * jobset.JobSet {
85
+ func getBaseJobSet (set * api.MetricSet , successSet []string ) * jobset.JobSet {
84
86
85
87
// When suspend is true we have a hard time debugging jobs, so keep false
86
88
suspend := false
@@ -112,9 +114,6 @@ func getBaseJobSet(set *api.MetricSet, successSet []string, soleTenancy bool) *j
112
114
}
113
115
114
116
// Do we want to assign 1 node: 1 pod? We can use Pod Anti-affinity for that
115
- if soleTenancy {
116
- js .ObjectMeta .Annotations = map [string ]string {jobset .ExclusiveKey : "kubernetes.io/hostname" }
117
- }
118
117
return & js
119
118
}
120
119
@@ -125,6 +124,7 @@ func GetReplicatedJob(
125
124
pods int32 ,
126
125
completions int32 ,
127
126
jobname string ,
127
+ soleTenancy bool ,
128
128
) (* jobset.ReplicatedJob , error ) {
129
129
130
130
// Default replicated job name, if not set
@@ -183,6 +183,11 @@ func GetReplicatedJob(
183
183
},
184
184
}
185
185
186
+ // Do we want sole tenancy?
187
+ if soleTenancy {
188
+ jobspec .Template .Spec .Affinity = getAffinity (set )
189
+ }
190
+
186
191
// Do we have a pull secret for the application image?
187
192
if set .Spec .Application .PullSecret != "" {
188
193
jobspec .Template .Spec .ImagePullSecrets = []corev1.LocalObjectReference {
@@ -193,3 +198,51 @@ func GetReplicatedJob(
193
198
job .Template .Spec = jobspec
194
199
return & job , nil
195
200
}
201
+
202
+ // getAffinity returns to pod affinity to ensure 1 address / node
203
+ func getAffinity (set * api.MetricSet ) * corev1.Affinity {
204
+ return & corev1.Affinity {
205
+ // Prefer to schedule pods on the same zone
206
+ PodAffinity : & corev1.PodAffinity {
207
+ PreferredDuringSchedulingIgnoredDuringExecution : []corev1.WeightedPodAffinityTerm {
208
+ {
209
+ Weight : 100 ,
210
+ PodAffinityTerm : corev1.PodAffinityTerm {
211
+ LabelSelector : & metav1.LabelSelector {
212
+ MatchExpressions : []metav1.LabelSelectorRequirement {
213
+ {
214
+ // added in getPodLabels
215
+ Key : podLabelAppName ,
216
+ Operator : metav1 .LabelSelectorOpIn ,
217
+ Values : []string {set .Name },
218
+ },
219
+ },
220
+ },
221
+ TopologyKey : "topology.kubernetes.io/zone" ,
222
+ },
223
+ },
224
+ },
225
+ },
226
+ // Prefer to schedule pods on different nodes
227
+ PodAntiAffinity : & corev1.PodAntiAffinity {
228
+ PreferredDuringSchedulingIgnoredDuringExecution : []corev1.WeightedPodAffinityTerm {
229
+ {
230
+ Weight : 100 ,
231
+ PodAffinityTerm : corev1.PodAffinityTerm {
232
+ LabelSelector : & metav1.LabelSelector {
233
+ MatchExpressions : []metav1.LabelSelectorRequirement {
234
+ {
235
+ // added in getPodLabels
236
+ Key : podLabelAppName ,
237
+ Operator : metav1 .LabelSelectorOpIn ,
238
+ Values : []string {set .Name },
239
+ },
240
+ },
241
+ },
242
+ TopologyKey : "kubernetes.io/hostname" ,
243
+ },
244
+ },
245
+ },
246
+ },
247
+ }
248
+ }
0 commit comments