Skip to content

Commit 6eec60a

Browse files
authored
fix: correct event callback handling as action is now required (#609)
1 parent 49d5810 commit 6eec60a

5 files changed

Lines changed: 14 additions & 7 deletions

File tree

helm/example-batch-job-controller/bin/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ echo "calling report callback: ${CALLBACK_SERVICE_RESULT_URL}"
99

1010

1111
curl --silent --show-error -X POST -H 'Content-Disposition: attachment;filename="test.txt"' --data-binary 'This is an uploaded file' "${CALLBACK_SERVICE_FILE_URL}"
12-
curl --silent --show-error -X POST -H "Content-Type: application/json; charset=utf-8" --data-binary '{"warning": false,"reason": "TestReason","message": "test message with %s","args": ["arg"]}' "${CALLBACK_SERVICE_EVENT_URL}"
12+
curl --silent --show-error -X POST -H "Content-Type: application/json; charset=utf-8" --data-binary '{"warning": false,"action": "callback","reason": "TestReason","message": "test message with %s","args": ["arg"]}' "${CALLBACK_SERVICE_EVENT_URL}"
1313
curl --silent --show-error -X POST -H "Content-Type: application/json; charset=utf-8" --data-binary '{ "my_metric": [{ "value": 1.0, "labels": { "label_a": "AAA", "label_b": "BBB" }}] }' "${CALLBACK_SERVICE_RESULT_URL}"
1414

1515
echo "done"

pkg/http/postserver-event.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ func (s *PostServer) postEventCallback(ctx *gin.Context, postLog logr.Logger, po
2626
return err
2727
}
2828

29+
action := event.Action
30+
if action == "" {
31+
action = "N/A"
32+
}
33+
2934
if len(event.Args) > 0 {
30-
s.EventRecorder.Eventf(pod, pod, event.Type(), event.Reason, "", event.Message, event.args()...)
35+
s.EventRecorder.Eventf(pod, pod, event.Type(), event.Reason, action, event.Message, event.args()...)
3136
} else {
32-
s.EventRecorder.Eventf(pod, pod, event.Type(), event.Reason, "", event.Message)
37+
s.EventRecorder.Eventf(pod, pod, event.Type(), event.Reason, action, event.Message)
3338
}
3439
return nil
3540
}

pkg/http/postserver_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131

3232
const (
3333
reportJSON = `{ "test": [{ "value": 1.0, "labels": { "label_a": "AAA", "label_b": "BBB" }}] }`
34-
eventMessageJSON = `{ "warning": true, "reason": "TestReason", "message": "test message" }`
35-
eventMessageInvalidJSON = `{ "warning": true, "reason": "testReason", "message": "test message" }`
34+
eventMessageJSON = `{ "warning": true, "action": "TestAction", "reason": "TestReason", "message": "test message" }`
35+
eventMessageInvalidJSON = `{ "warning": true, "action": "TestAction", "reason": "testReason", "message": "test message" }`
3636
eventMessageArgsJSON = `{ "warning": true, "reason": "TestReason", "message": "test message: %s" ,"args" : ["a1"]}`
3737
)
3838

@@ -288,7 +288,7 @@ var _ = Describe("HTTP", func() {
288288
mockSink.EXPECT().WithValues("node", node, "id", executionID).Return(mockSink)
289289
mockSink.EXPECT().WithValues("length", gm.Any()).Return(mockSink)
290290
mockSink.EXPECT().WithValues("pod", gm.Any(), "type", "Warning", "reason", "TestReason", "event-message", "test message").Return(mockSink)
291-
mockRecord.EXPECT().Eventf(gm.Any(), gm.Any(), "Warning", "TestReason", "", "test message")
291+
mockRecord.EXPECT().Eventf(gm.Any(), gm.Any(), "Warning", "TestReason", "TestAction", "test message")
292292
mockSink.EXPECT().Info(gm.Any(), "event created")
293293
mockReader.EXPECT().
294294
Get(gm.Any(), client.ObjectKey{Namespace: s.Config.Namespace, Name: s.Config.PodName(node, executionID)}, gm.AssignableToTypeOf(&corev1.Pod{}))
@@ -304,7 +304,7 @@ var _ = Describe("HTTP", func() {
304304
mockSink.EXPECT().WithValues("node", node, "id", executionID).Return(mockSink)
305305
mockSink.EXPECT().WithValues("length", gm.Any()).Return(mockSink)
306306
mockSink.EXPECT().WithValues("pod", gm.Any(), "type", "Warning", "reason", "TestReason", "event-message", "test message: a1").Return(mockSink)
307-
mockRecord.EXPECT().Eventf(gm.Any(), gm.Any(), "Warning", "TestReason", "", "test message: %s", "a1")
307+
mockRecord.EXPECT().Eventf(gm.Any(), gm.Any(), "Warning", "TestReason", "N/A", "test message: %s", "a1")
308308
mockSink.EXPECT().Info(gm.Any(), "event created")
309309
mockReader.EXPECT().
310310
Get(gm.Any(), client.ObjectKey{Namespace: s.Config.Namespace, Name: s.Config.PodName(node, executionID)}, gm.AssignableToTypeOf(&corev1.Pod{}))

pkg/http/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
// Event to be sent as k8s event
1111
type Event struct {
1212
Waring bool `json:"warning"`
13+
Action string `json:"action"`
1314
Reason string `json:"reason" validate:"required,first_char_must_be_uppercase"`
1415
Message string `json:"message,omitempty" validate:"required"`
1516
Args []string `json:"args,omitempty"`

pkg/http/types_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var _ = Describe("types", func() {
1414
Waring: false,
1515
Reason: "AnyReason",
1616
Message: "message",
17+
Action: "action",
1718
}
1819
})
1920
Context("Event.Validate", func() {

0 commit comments

Comments
 (0)