Skip to content

Commit 9780e27

Browse files
authored
Add worker label to worker pods to only stream logs from worker pods (#2162)
1 parent ed1d79d commit 9780e27

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

pkg/crds/controllers/batch/batchjob_controller_helpers.go

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,19 +215,21 @@ func (r *BatchJobReconciler) desiredEnqueuerJob(batchJob batch.BatchJob, queueUR
215215
Namespace: batchJob.Namespace,
216216
Parallelism: 1,
217217
Labels: map[string]string{
218-
"apiKind": userconfig.BatchAPIKind.String(),
219-
"apiName": batchJob.Spec.APIName,
220-
"apiID": batchJob.Spec.APIID,
221-
"jobID": batchJob.Name,
222-
"cortex.dev/api": "true",
218+
"apiKind": userconfig.BatchAPIKind.String(),
219+
"apiName": batchJob.Spec.APIName,
220+
"apiID": batchJob.Spec.APIID,
221+
"jobID": batchJob.Name,
222+
"cortex.dev/api": "true",
223+
"cortex.dev/batch": "enqueuer",
223224
},
224225
PodSpec: k8s.PodSpec{
225226
Labels: map[string]string{
226-
"apiKind": userconfig.BatchAPIKind.String(),
227-
"apiName": batchJob.Spec.APIName,
228-
"apiID": batchJob.Spec.APIID,
229-
"jobID": batchJob.Name,
230-
"cortex.dev/api": "true",
227+
"apiKind": userconfig.BatchAPIKind.String(),
228+
"apiName": batchJob.Spec.APIName,
229+
"apiID": batchJob.Spec.APIID,
230+
"jobID": batchJob.Name,
231+
"cortex.dev/api": "true",
232+
"cortex.dev/batch": "enqueuer",
231233
},
232234
Annotations: map[string]string{
233235
"traffic.sidecar.istio.io/excludeOutboundIPRanges": "0.0.0.0/0",
@@ -294,23 +296,25 @@ func (r *BatchJobReconciler) desiredWorkerJob(batchJob batch.BatchJob, apiSpec s
294296
Namespace: batchJob.Namespace,
295297
Parallelism: batchJob.Spec.Workers,
296298
Labels: map[string]string{
297-
"apiKind": userconfig.BatchAPIKind.String(),
298-
"apiName": batchJob.Spec.APIName,
299-
"apiID": batchJob.Spec.APIID,
300-
"specID": apiSpec.SpecID,
301-
"handlerID": apiSpec.HandlerID,
302-
"jobID": batchJob.Name,
303-
"cortex.dev/api": "true",
299+
"apiKind": userconfig.BatchAPIKind.String(),
300+
"apiName": batchJob.Spec.APIName,
301+
"apiID": batchJob.Spec.APIID,
302+
"specID": apiSpec.SpecID,
303+
"handlerID": apiSpec.HandlerID,
304+
"jobID": batchJob.Name,
305+
"cortex.dev/api": "true",
306+
"cortex.dev/batch": "worker",
304307
},
305308
PodSpec: k8s.PodSpec{
306309
Labels: map[string]string{
307-
"apiKind": userconfig.BatchAPIKind.String(),
308-
"apiName": batchJob.Spec.APIName,
309-
"apiID": batchJob.Spec.APIID,
310-
"specID": apiSpec.SpecID,
311-
"handlerID": apiSpec.HandlerID,
312-
"jobID": batchJob.Name,
313-
"cortex.dev/api": "true",
310+
"apiKind": userconfig.BatchAPIKind.String(),
311+
"apiName": batchJob.Spec.APIName,
312+
"apiID": batchJob.Spec.APIID,
313+
"specID": apiSpec.SpecID,
314+
"handlerID": apiSpec.HandlerID,
315+
"jobID": batchJob.Name,
316+
"cortex.dev/api": "true",
317+
"cortex.dev/batch": "worker",
314318
},
315319
Annotations: map[string]string{
316320
"traffic.sidecar.istio.io/excludeOutboundIPRanges": "0.0.0.0/0",

pkg/operator/endpoints/logs_job.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,11 @@ func ReadJobLogs(w http.ResponseWriter, r *http.Request) {
5252
}
5353
defer socket.Close()
5454

55-
operator.StreamLogsFromRandomPod(map[string]string{"apiName": apiName, "jobID": jobID}, socket)
55+
labels := map[string]string{"apiName": apiName, "jobID": jobID}
56+
57+
if deployedResource.Kind == userconfig.BatchAPIKind {
58+
labels["cortex.dev/batch"] = "worker"
59+
}
60+
61+
operator.StreamLogsFromRandomPod(labels, socket)
5662
}

0 commit comments

Comments
 (0)