Skip to content

Commit 8a90eb6

Browse files
authored
Add pool to JobRunningEvent and JobPendingEvent API messages (#4695)
Expose the pool of a job run in the JobRunningEvent and JobPendingEvent API messages, matching the existing behaviour of JobLeasedEvent. The pool is read from the pod's armadaproject.io/pool annotation by the executor and threaded through the internal JobRunRunning and JobRunAssigned events to the API conversion layer. Signed-off-by: Maurice Yap <mauriceyap@hotmail.co.uk>
1 parent 46d0689 commit 8a90eb6

File tree

11 files changed

+615
-382
lines changed

11 files changed

+615
-382
lines changed

internal/executor/reporter/event.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func CreateEventForCurrentState(pod *v1.Pod, clusterId string) (*armadaevents.Ev
3131
JobRunAssigned: &armadaevents.JobRunAssigned{
3232
RunId: runId,
3333
JobId: jobId,
34+
Pool: util.ExtractPool(pod),
3435
ResourceInfos: []*armadaevents.KubernetesResourceInfo{
3536
{
3637
ObjectMeta: &armadaevents.ObjectMeta{
@@ -57,6 +58,7 @@ func CreateEventForCurrentState(pod *v1.Pod, clusterId string) (*armadaevents.Ev
5758
JobRunRunning: &armadaevents.JobRunRunning{
5859
RunId: runId,
5960
JobId: jobId,
61+
Pool: util.ExtractPool(pod),
6062
ResourceInfos: []*armadaevents.KubernetesResourceInfo{
6163
{
6264
ObjectMeta: &armadaevents.ObjectMeta{

internal/executor/reporter/event_sender_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import (
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
k8sTypes "k8s.io/apimachinery/pkg/types"
1717

18-
"github.com/armadaproject/armada/internal/executor/domain"
19-
18+
"github.com/armadaproject/armada/internal/common/constants"
2019
"github.com/armadaproject/armada/internal/common/util"
20+
"github.com/armadaproject/armada/internal/executor/domain"
2121
"github.com/armadaproject/armada/pkg/executorapi"
2222
)
2323

@@ -103,7 +103,8 @@ func makeTestPod(phase v1.PodPhase) *v1.Pod {
103103
domain.JobRunId: uuid.New().String(),
104104
},
105105
Annotations: map[string]string{
106-
domain.JobSetId: "job-set-id-1",
106+
domain.JobSetId: "job-set-id-1",
107+
constants.PoolAnnotation: "test-pool",
107108
},
108109
CreationTimestamp: metav1.Time{time.Now().Add(-10 * time.Minute)},
109110
UID: k8sTypes.UID(util.NewULID()),

internal/executor/reporter/event_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ func TestCreateEventForCurrentState_WhenPodPending(t *testing.T) {
1717
assert.Nil(t, err)
1818

1919
assert.Len(t, result.Events, 1)
20-
_, ok := result.Events[0].Event.(*armadaevents.EventSequence_Event_JobRunAssigned)
20+
assigned, ok := result.Events[0].Event.(*armadaevents.EventSequence_Event_JobRunAssigned)
2121
assert.True(t, ok)
22+
assert.Equal(t, "test-pool", assigned.JobRunAssigned.Pool)
2223
}
2324

2425
func TestCreateEventForCurrentState_WhenPodRunning(t *testing.T) {
@@ -28,8 +29,9 @@ func TestCreateEventForCurrentState_WhenPodRunning(t *testing.T) {
2829
assert.Nil(t, err)
2930

3031
assert.Len(t, result.Events, 1)
31-
_, ok := result.Events[0].Event.(*armadaevents.EventSequence_Event_JobRunRunning)
32+
running, ok := result.Events[0].Event.(*armadaevents.EventSequence_Event_JobRunRunning)
3233
assert.True(t, ok)
34+
assert.Equal(t, "test-pool", running.JobRunRunning.Pool)
3335
}
3436

3537
func TestCreateEventForCurrentState_WhenPodFailed(t *testing.T) {

internal/server/event/conversion/conversions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ func FromInternalJobRunRunning(queueName string, jobSetName string, time time.Ti
382382
JobSetId: jobSetName,
383383
Queue: queueName,
384384
Created: protoutil.ToTimestamp(time),
385+
Pool: e.Pool,
385386
}
386387

387388
if len(e.ResourceInfos) > 0 {
@@ -409,6 +410,7 @@ func FromInternalJobRunAssigned(queueName string, jobSetName string, time time.T
409410
JobSetId: jobSetName,
410411
Queue: queueName,
411412
Created: protoutil.ToTimestamp(time),
413+
Pool: e.Pool,
412414
}
413415

414416
if len(e.ResourceInfos) > 0 {

internal/server/event/conversion/conversions_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ func TestConvertJobRunning(t *testing.T) {
574574
JobRunRunning: &armadaevents.JobRunRunning{
575575
RunId: runId,
576576
JobId: jobId,
577+
Pool: "test-pool",
577578
ResourceInfos: []*armadaevents.KubernetesResourceInfo{
578579
{
579580
ObjectMeta: &armadaevents.ObjectMeta{
@@ -608,6 +609,7 @@ func TestConvertJobRunning(t *testing.T) {
608609
PodNumber: podNumber,
609610
PodName: podName,
610611
PodNamespace: namespace,
612+
Pool: "test-pool",
611613
},
612614
},
613615
},
@@ -669,6 +671,7 @@ func TestConvertJobAssigned(t *testing.T) {
669671
JobRunAssigned: &armadaevents.JobRunAssigned{
670672
RunId: runId,
671673
JobId: jobId,
674+
Pool: "test-pool",
672675
ResourceInfos: []*armadaevents.KubernetesResourceInfo{
673676
{
674677
ObjectMeta: &armadaevents.ObjectMeta{
@@ -702,6 +705,7 @@ func TestConvertJobAssigned(t *testing.T) {
702705
PodNumber: podNumber,
703706
PodName: podName,
704707
PodNamespace: namespace,
708+
Pool: "test-pool",
705709
},
706710
},
707711
},

pkg/api/api.swagger.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,9 @@ func SwaggerJsonTemplate() string {
14301430
" \"type\": \"integer\",\n" +
14311431
" \"format\": \"int32\"\n" +
14321432
" },\n" +
1433+
" \"pool\": {\n" +
1434+
" \"type\": \"string\"\n" +
1435+
" },\n" +
14331436
" \"queue\": {\n" +
14341437
" \"type\": \"string\"\n" +
14351438
" }\n" +
@@ -1727,6 +1730,9 @@ func SwaggerJsonTemplate() string {
17271730
" \"type\": \"integer\",\n" +
17281731
" \"format\": \"int32\"\n" +
17291732
" },\n" +
1733+
" \"pool\": {\n" +
1734+
" \"type\": \"string\"\n" +
1735+
" },\n" +
17301736
" \"queue\": {\n" +
17311737
" \"type\": \"string\"\n" +
17321738
" }\n" +

pkg/api/api.swagger.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,9 @@
14191419
"type": "integer",
14201420
"format": "int32"
14211421
},
1422+
"pool": {
1423+
"type": "string"
1424+
},
14221425
"queue": {
14231426
"type": "string"
14241427
}
@@ -1716,6 +1719,9 @@
17161719
"type": "integer",
17171720
"format": "int32"
17181721
},
1722+
"pool": {
1723+
"type": "string"
1724+
},
17191725
"queue": {
17201726
"type": "string"
17211727
}

0 commit comments

Comments
 (0)