Skip to content

Commit 56f3db4

Browse files
feat(venona): report task status to te platform (#522)
1 parent ab1f720 commit 56f3db4

File tree

23 files changed

+389
-67
lines changed

23 files changed

+389
-67
lines changed

charts/cf-runtime/Chart.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v2
22
description: A Helm chart for Codefresh Runner
33
name: cf-runtime
4-
version: 7.1.10
4+
version: 7.2.0
55
keywords:
66
- codefresh
77
- runner
@@ -17,8 +17,8 @@ annotations:
1717
artifacthub.io/containsSecurityUpdates: "false"
1818
# Supported kinds: `added`, `changed`, `deprecated`, `removed`, `fixed`, `security`:
1919
artifacthub.io/changes: |
20-
- kind: fixed
21-
description: "Using cache for multiple tags (Engine 1.174.19)"
20+
- kind: added
21+
description: "Chart version exposed to the `venona` and `engine` pods"
2222
dependencies:
2323
- name: cf-common
2424
repository: oci://quay.io/codefresh/charts

charts/cf-runtime/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Codefresh Runner
22

3-
![Version: 7.1.10](https://img.shields.io/badge/Version-7.1.10-informational?style=flat-square)
3+
![Version: 7.2.0](https://img.shields.io/badge/Version-7.2.0-informational?style=flat-square)
44

55
Helm chart for deploying [Codefresh Runner](https://codefresh.io/docs/docs/installation/codefresh-runner/) to Kubernetes.
66

charts/cf-runtime/templates/_components/runner/environment-variables/_main-container.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CODEFRESH_TOKEN:
1616
name: {{ include "runner.fullname" . }}
1717
key: agent-codefresh-token
1818
DOCKER_REGISTRY: {{ .Values.global.imageRegistry }}
19+
RUNTIME_CHART_VERSION: {{ .Chart.Version }}
1920
{{- end }}
2021

2122
{{- define "runner.environment-variables" }}

charts/cf-runtime/templates/runtime/runtime-env-spec-tmpl.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ runtimeScheduler:
3737
CR_6177_FIXER: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.CR_6177_FIXER) | squote }}
3838
GC_BUILDER_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.GC_BUILDER_IMAGE) | squote }}
3939
COSIGN_IMAGE_SIGNER_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.COSIGN_IMAGE_SIGNER_IMAGE) | squote }}
40+
RUNTIME_CHART_VERSION: {{ .Chart.Version }}
4041
{{- with $engineContext.userEnvVars }}
4142
userEnvVars: {{- toYaml . | nindent 4 }}
4243
{{- end }}

charts/cf-runtime/tests/private-registry/private_registry_test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ tests:
5757
CR_6177_FIXER: 'somedomain.io/alpine:tagoverride'
5858
GC_BUILDER_IMAGE: 'somedomain.io/codefresh/cf-gc-builder:tagoverride'
5959
COSIGN_IMAGE_SIGNER_IMAGE: 'somedomain.io/codefresh/cf-cosign-image-signer:tagoverride'
60+
RUNTIME_CHART_VERSION: [\w.-]+
6061
workflowLimits:
6162
MAXIMUM_ALLOWED_TIME_BEFORE_PRE_STEPS_SUCCESS: 600
6263
MAXIMUM_ALLOWED_WORKFLOW_AGE_BEFORE_TERMINATION: 86400

charts/cf-runtime/tests/runtime/runtime_onprem_test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ tests:
7070
CR_6177_FIXER: 'alpine:tagoverride'
7171
GC_BUILDER_IMAGE: 'quay.io/codefresh/cf-gc-builder:tagoverride'
7272
COSIGN_IMAGE_SIGNER_IMAGE: 'quay.io/codefresh/cf-cosign-image-signer:tagoverride'
73+
RUNTIME_CHART_VERSION: [\w.-]+
7374
workflowLimits:
7475
MAXIMUM_ALLOWED_TIME_BEFORE_PRE_STEPS_SUCCESS: 600
7576
MAXIMUM_ALLOWED_WORKFLOW_AGE_BEFORE_TERMINATION: 86400

charts/cf-runtime/tests/runtime/runtime_test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ tests:
7171
CR_6177_FIXER: 'alpine:tagoverride'
7272
GC_BUILDER_IMAGE: 'quay.io/codefresh/cf-gc-builder:tagoverride'
7373
COSIGN_IMAGE_SIGNER_IMAGE: 'quay.io/codefresh/cf-cosign-image-signer:tagoverride'
74+
RUNTIME_CHART_VERSION: [\w.-]+
7475
userEnvVars:
7576
- name: ALICE
7677
valueFrom:

venona/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.10.8
1+
2.0.0

venona/cmd/start.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,13 @@ func run(options startOptions) {
230230

231231
httpClient.Transport = monitor.NewRoundTripper(httpClient.Transport)
232232

233+
userAgent := fmt.Sprintf("cf-classic-runner/%s", version)
234+
if runtimeVersion := os.Getenv("RUNTIME_CHART_VERSION"); runtimeVersion != "" {
235+
userAgent += fmt.Sprintf(" cf-classic-runtime/%s", runtimeVersion)
236+
}
233237
httpHeaders := http.Header{}
234238
{
235-
httpHeaders.Add("User-Agent", fmt.Sprintf("codefresh-runner-%s", version))
239+
httpHeaders.Add("User-Agent", userAgent)
236240
}
237241

238242
cf = codefresh.New(codefresh.Options{

venona/pkg/agent/agent.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func New(opts *Options) (*Agent, error) {
125125
Monitor: opts.Monitor,
126126
Concurrency: opts.Concurrency,
127127
BufferSize: opts.BufferSize,
128+
Codefresh: opts.Codefresh,
128129
})
129130
return &Agent{
130131
id: id,
@@ -192,7 +193,7 @@ func (a *Agent) startTaskPullerRoutine(ctx context.Context) {
192193

193194
// perform all agentTasks (in goroutine)
194195
for i := range agentTasks {
195-
a.handleAgentTask(&agentTasks[i])
196+
a.handleAgentTask(ctx, &agentTasks[i])
196197
}
197198

198199
// send all wfTasks to tasksQueue
@@ -241,6 +242,25 @@ func (a *Agent) reportStatus(ctx context.Context, status codefresh.AgentStatus)
241242
}
242243
}
243244

245+
func (a *Agent) reportTaskStatus(ctx context.Context, taskDef task.Task, err error) {
246+
status := task.TaskStatus{
247+
OccurredAt: time.Now(),
248+
StatusRevision: taskDef.Metadata.CurrentStatusRevision + 1,
249+
}
250+
if err != nil {
251+
status.Status = task.StatusError
252+
status.Reason = err.Error()
253+
status.IsRetriable = true // TODO: make this configurable depending on the error
254+
} else {
255+
status.Status = task.StatusSuccess
256+
}
257+
258+
statusErr := a.cf.ReportTaskStatus(ctx, taskDef.Id, status)
259+
if statusErr != nil {
260+
a.log.Error("failed reporting task status", "error", statusErr, "task", taskDef.Id, "workflow", taskDef.Metadata.WorkflowId)
261+
}
262+
}
263+
244264
func (a *Agent) getTasks(ctx context.Context) (task.Tasks, []*workflow.Workflow) {
245265
tasks := a.pullTasks(ctx)
246266
return a.splitTasks(tasks)
@@ -276,18 +296,18 @@ func (a *Agent) splitTasks(tasks task.Tasks) (task.Tasks, []*workflow.Workflow)
276296
t.Timeline.Pulled = pullTime
277297
agentTasks = append(agentTasks, t)
278298
case task.TypeCreatePod, task.TypeCreatePVC, task.TypeDeletePod, task.TypeDeletePVC:
279-
wf, ok := wfMap[t.Metadata.Workflow]
299+
wf, ok := wfMap[t.Metadata.WorkflowId]
280300
if !ok {
281301
wf = workflow.New(t.Metadata)
282-
wfMap[t.Metadata.Workflow] = wf
302+
wfMap[t.Metadata.WorkflowId] = wf
283303
}
284304

285305
err := wf.AddTask(&t)
286306
if err != nil {
287307
a.log.Error("failed adding task to workflow", "error", err)
288308
}
289309
default:
290-
a.log.Error("unrecognized task type", "type", t.Type, "tid", t.Metadata.Workflow, "runtime", t.Metadata.ReName)
310+
a.log.Error("unrecognized task type", "type", t.Type, "tid", t.Metadata.WorkflowId, "runtime", t.Metadata.ReName)
291311
}
292312
}
293313

@@ -313,14 +333,14 @@ func (a *Agent) splitTasks(tasks task.Tasks) (task.Tasks, []*workflow.Workflow)
313333
return agentTasks, workflows
314334
}
315335

316-
func (a *Agent) handleAgentTask(t *task.Task) {
317-
a.log.Info("executing agent task", "tid", t.Metadata.Workflow)
336+
func (a *Agent) handleAgentTask(ctx context.Context, t *task.Task) {
337+
a.log.Info("executing agent task", "tid", t.Metadata.WorkflowId)
318338
a.wg.Add(1)
319339
go func() {
320340
defer a.wg.Done()
321341
txn := task.NewTaskTransaction(a.monitor, t.Metadata)
322342
defer txn.End()
323-
err := a.executeAgentTask(t)
343+
err := a.executeAgentTask(ctx, t)
324344

325345
if err != nil {
326346
a.log.Error(err.Error())
@@ -330,7 +350,7 @@ func (a *Agent) handleAgentTask(t *task.Task) {
330350
}()
331351
}
332352

333-
func (a *Agent) executeAgentTask(t *task.Task) error {
353+
func (a *Agent) executeAgentTask(ctx context.Context, t *task.Task) error {
334354
t.Timeline.Started = time.Now()
335355
specJSON, err := json.Marshal(t.Spec)
336356
if err != nil {
@@ -348,9 +368,12 @@ func (a *Agent) executeAgentTask(t *task.Task) error {
348368
}
349369

350370
err = e(&spec, a.log)
371+
if t.Metadata.ShouldReportStatus {
372+
a.reportTaskStatus(ctx, *t, err)
373+
}
351374
sinceCreation, inRunner, processed := t.GetLatency()
352375
a.log.Info("Done handling agent task",
353-
"tid", t.Metadata.Workflow,
376+
"tid", t.Metadata.WorkflowId,
354377
"time since creation", sinceCreation,
355378
"time in runner", inRunner,
356379
"processing time", processed,
@@ -410,7 +433,7 @@ func proxyRequest(t *task.AgentTask, log logger.Logger) error {
410433
func groupTasks(tasks task.Tasks) map[string]task.Tasks {
411434
candidates := map[string]task.Tasks{}
412435
for _, task := range tasks {
413-
name := task.Metadata.Workflow
436+
name := task.Metadata.WorkflowId
414437
if name == "" {
415438
// If for some reason the task is not related to any workflow
416439
// Might heppen in older versions on Codefresh

0 commit comments

Comments
 (0)