tom24d / tekton-step-observer Goto Github PK
View Code? Open in Web Editor NEWPlugin to report CloudEvents at step execution level for Tekton
License: Apache License 2.0
Plugin to report CloudEvents at step execution level for Tekton
License: Apache License 2.0
Describe the bug
when step observe controller detects the state that should be reported as CloudEvent, emit it and mark that has been actually "reported" in the metadata.annotation&PATCH it. However, 50% ratio the controller cannot get latest info with latest annotation from the TaskRun informer, so it cannot manage event emission status.
To Reproduce
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: hello1
spec:
steps:
- name: hello1
image: ubuntu
command:
- sleep
args:
- "15"
- name: hello2
image: ubuntu
command:
- sleep
args:
- "10 && exit 111"
- name: hello3
image: ubuntu
command:
- echo
args:
- "Hello World! ver 2"
tkn task start hello1
started
emission for step hello1
in the log:{"level":"info","logger":"step-observe-controller.step-observe-controller","caller":"step/reconciler.go:100","msg":"EVENT EMISSION step: hello1, type: dev.tekton.events.plugin.step.started.v1, annotation: &{[{hello1 [dev.tekton.events.plugin.step.started.v1]} {hello2 []} {hello3 []}]}","knative.dev/traceid":"e8522690-e741-46f3-935f-cf4c0c16ef31","knative.dev/key":"default/hello1-run-6dtq7"}
{"level":"info","logger":"step-observe-controller.step-observe-controller","caller":"step/reconciler.go:79","msg":"PATCH: {\"metadata\":{\"creationTimestamp\":null,\"annotations\":{\"tom24d.plugin.step-observer/result\":\"{\\\"statuses\\\":[{\\\"name\\\":\\\"hello1\\\",\\\"emitted\\\":[\\\"dev.tekton.events.plugin.step.started.v1\\\"]},{\\\"name\\\":\\\"hello2\\\",\\\"emitted\\\":[]},{\\\"name\\\":\\\"hello3\\\",\\\"emitted\\\":[]}]}\"}},\"spec\":{\"serviceAccountName\":\"\"},\"status\":{\"podName\":\"\"}}","knative.dev/traceid":"e8522690-e741-46f3-935f-cf4c0c16ef31","knative.dev/key":"default/hello1-run-6dtq7"}
{"level":"info","logger":"step-observe-controller.step-observe-controller","caller":"controller/controller.go:474","msg":"Reconcile succeeded. Time taken: 24.3282ms","knative.dev/traceid":"e8522690-e741-46f3-935f-cf4c0c16ef31","knative.dev/key":"default/hello1-run-6dtq7"}
{"level":"info","logger":"step-observe-controller.step-observe-controller","caller":"step/reconciler.go:34","msg":"RECEIVED annotation: &{[{hello1 [dev.tekton.events.plugin.step.started.v1]} {hello2 []} {hello3 []}]}","knative.dev/traceid":"e256592a-3798-4e44-be0c-c011e407ff43","knative.dev/key":"default/hello1-run-6dtq7"}
{"level":"info","logger":"step-observe-controller.step-observe-controller","caller":"step/reconciler.go:79","msg":"PATCH: {\"metadata\":{\"creationTimestamp\":null,\"annotations\":{\"tom24d.plugin.step-observer/result\":\"{\\\"statuses\\\":[{\\\"name\\\":\\\"hello1\\\",\\\"emitted\\\":[\\\"dev.tekton.events.plugin.step.started.v1\\\"]},{\\\"name\\\":\\\"hello2\\\",\\\"emitted\\\":[]},{\\\"name\\\":\\\"hello3\\\",\\\"emitted\\\":[]}]}\"}},\"spec\":{\"serviceAccountName\":\"\"},\"status\":{\"podName\":\"\"}}","knative.dev/traceid":"e256592a-3798-4e44-be0c-c011e407ff43","knative.dev/key":"default/hello1-run-6dtq7"}
{"level":"info","logger":"step-observe-controller.step-observe-controller","caller":"controller/controller.go:474","msg":"Reconcile succeeded. Time taken: 24.3593ms","knative.dev/traceid":"e256592a-3798-4e44-be0c-c011e407ff43","knative.dev/key":"default/hello1-run-6dtq7"}
{"level":"info","logger":"step-observe-controller.step-observe-controller","caller":"step/reconciler.go:34","msg":"RECEIVED annotation: &{[{hello1 []} {hello2 []} {hello3 []}]}","knative.dev/traceid":"e9279bec-1345-4db2-a7bb-1e5091942cba","knative.dev/key":"default/hello1-run-6dtq7"}
{"level":"info","logger":"step-observe-controller.step-observe-controller","caller":"step/reconciler.go:100","msg":"EVENT EMISSION step: hello1, type: dev.tekton.events.plugin.step.started.v1, annotation: &{[{hello1 [dev.tekton.events.plugin.step.started.v1]} {hello2 []} {hello3 []}]}","knative.dev/traceid":"e9279bec-1345-4db2-a7bb-1e5091942cba","knative.dev/key":"default/hello1-run-6dtq7"}
{"level":"info","logger":"step-observe-controller.step-observe-controller","caller":"step/reconciler.go:79","msg":"PATCH: {\"metadata\":{\"creationTimestamp\":null,\"annotations\":{\"tom24d.plugin.step-observer/result\":\"{\\\"statuses\\\":[{\\\"name\\\":\\\"hello1\\\",\\\"emitted\\\":[\\\"dev.tekton.events.plugin.step.started.v1\\\"]},{\\\"name\\\":\\\"hello2\\\",\\\"emitted\\\":[]},{\\\"name\\\":\\\"hello3\\\",\\\"emitted\\\":[]}]}\"}},\"spec\":{\"serviceAccountName\":\"\"},\"status\":{\"podName\":\"\"}}","knative.dev/traceid":"e9279bec-1345-4db2-a7bb-1e5091942cba","knative.dev/key":"default/hello1-run-6dtq7"}
Expected behavior
It should get the latest resource
Version info:
ContainerStateRunning.StartedAt
!= ContainerStateTerminated
makes hard to assert CloudEvent Time. consider it or give up.
Event log:
Validation: valid
Context Attributes,
specversion: 1.0
type: dev.tekton.events.plugin.step.succeeded.v1
source: /api/v1/namespaces/tekton-pipelines/pods/tekton-step-observer
id: c4b6214d-1a53-4960-bd3a-efe1aa69a477
time: 2020-08-05T13:16:28Z
datacontenttype: application/json
Extensions,
knativearrivaltime: 2020-08-05T13:16:29.6568031Z
knativehistory: inmemorychannel-kne-trigger-kn-channel.test-event-assertion-single-task-in-memory-channel-messagindmkw.svc.cluster.local
Data,
{
"podRef": {
"kind": "Pod",
"namespace": "test-event-assertion-single-task-in-memory-channel-messagindmkw",
"name": "e2e-test-step-observed-run-pod-n9ptp",
"apiVersion": "v1"
},
"log": "hello1\n",
"step": {
"name": "",
"image": "busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649",
"command": [
"/bin/sh"
],
"args": [
"-c",
"echo hello1"
],
"resources": {}
},
"stepState": {
"terminated": {
"exitCode": 0,
"reason": "Completed",
"startedAt": "2020-08-05T13:16:28Z",
"finishedAt": "2020-08-05T13:16:28Z",
"containerID": "containerd://a75e04dfc9f21e4f77c671bce594954034758a369ad029c95fd59d5620114898"
},
"name": "unnamed-0",
"container": "step-unnamed-0",
"imageID": "docker.io/library/busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649"
}
}
and
2020/08/05 13:16:27 eventdetails:
Validation: valid
Context Attributes,
specversion: 1.0
type: dev.tekton.events.plugin.step.started.v1
source: /api/v1/namespaces/tekton-pipelines/pods/tekton-step-observer
id: f440e80e-3455-4b7c-a91a-88c2c4ec1637
time: 2020-08-05T13:16:26Z
datacontenttype: application/json
Extensions,
knativearrivaltime: 2020-08-05T13:16:27.7858596Z
knativehistory: inmemorychannel-kne-trigger-kn-channel.test-event-assertion-single-task-in-memory-channel-messagindmkw.svc.cluster.local
Data,
{
"podRef": {
"kind": "Pod",
"namespace": "test-event-assertion-single-task-in-memory-channel-messagindmkw",
"name": "e2e-test-step-observed-run-pod-n9ptp",
"apiVersion": "v1"
},
"step": {
"name": "",
"image": "busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649",
"command": [
"/bin/sh"
],
"args": [
"-c",
"echo hello1"
],
"resources": {}
},
"stepState": {
"running": {
"startedAt": "2020-08-05T13:16:26Z"
},
"name": "unnamed-0",
"container": "step-unnamed-0",
"imageID": "docker.io/library/busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649"
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.