Skip to content

fix: add retries to argo-event Sensors #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ assumes the name, condition and payload.dependencyName are identical
src:
dataKey: body
dependencyName: {{ .name }}
atLeastOnce: {{ .atLeastOnce }}
{{- if .retryStrategy }}
retryStrategy:
{{- .retryStrategy | toYaml | nindent 4 }}
{{- end }}
{{- if .policy }}
policy:
{{- .policy | toYaml | nindent 4 }}
{{- end }}
{{- end -}}

{{/* Logging trigger for the sensor - gets sensor.logging dict */}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
{{- include "event-reporters.rollout-reporter.labels" . | nindent 4}}
spec:
replicas: {{ .Values.rollout.eventSource.replicas }}
eventBusName: {{ default "codefresh-eventbus" .Values.global.runtime.eventBus.name }}
eventBusName: {{ include "codefresh-gitops-runtime.eventbus.name" .Values.global.runtime.eventBus }}
resource:
analysisruns:
eventTypes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
- name: analysisruns
eventSourceName: rollout-reporter
eventName: analysisruns
eventBusName: {{ default "codefresh-eventbus" .Values.global.runtime.eventBus.name }}
eventBusName: {{ include "codefresh-gitops-runtime.eventbus.name" .Values.global.runtime.eventBus }}
template:
serviceAccountName: {{ include "event-reporters.rollout-reporter.serviceAccountName" .}}
container:
Expand All @@ -40,8 +40,8 @@ spec:
{{- . | toYaml | nindent 6 }}
{{- end }}
triggers:
{{- include "event-reporters.http.trigger" (dict "name" "rollouts" "Values" .Values "payloadDest" "data.object" "retryStrategy" .Values.rollout.sensor.retryStrategy) | nindent 4 }}
{{- include "event-reporters.http.trigger" (dict "name" "replicasets" "Values" .Values "payloadDest" "data.object" "retryStrategy" .Values.rollout.sensor.retryStrategy) | nindent 4 }}
{{- include "event-reporters.http.trigger" (dict "name" "analysisruns" "Values" .Values "payloadDest" "data.object" "retryStrategy" .Values.rollout.sensor.retryStrategy) | nindent 4 }}
{{- include "event-reporters.http.trigger" (dict "name" "rollouts" "Values" .Values "payloadDest" "data.object" "retryStrategy" .Values.rollout.sensor.retryStrategy "policy" .Values.rollout.sensor.policy "atLeastOnce" .Values.rollout.sensor.atLeastOnce) | nindent 4 }}
{{- include "event-reporters.http.trigger" (dict "name" "replicasets" "Values" .Values "payloadDest" "data.object" "retryStrategy" .Values.rollout.sensor.retryStrategy "policy" .Values.rollout.sensor.policy "atLeastOnce" .Values.rollout.sensor.atLeastOnce) | nindent 4 }}
{{- include "event-reporters.http.trigger" (dict "name" "analysisruns" "Values" .Values "payloadDest" "data.object" "retryStrategy" .Values.rollout.sensor.retryStrategy "policy" .Values.rollout.sensor.policy "atLeastOnce" .Values.rollout.sensor.atLeastOnce) | nindent 4 }}
{{- include "event-reporters.log.trigger" (.Values.rollout.sensor.logging) | nindent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
{{- include "event-reporters.workflow-reporter.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.workflow.eventSource.replicas }}
eventBusName: {{ default "codefresh-eventbus" .Values.global.runtime.eventBus.name }}
eventBusName: {{ include "codefresh-gitops-runtime.eventbus.name" .Values.global.runtime.eventBus }}
resource:
workflows:
eventTypes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
- eventName: workflows
eventSourceName: workflow-reporter
name: workflows
eventBusName: {{ default "codefresh-eventbus" .Values.global.runtime.eventBus.name }}
eventBusName: {{ include "codefresh-gitops-runtime.eventbus.name" .Values.global.runtime.eventBus }}
template:
serviceAccountName: {{ include "event-reporters.workflow-reporter.serviceAccountName" .}}
container:
Expand All @@ -34,6 +34,6 @@ spec:
{{- . | toYaml | nindent 6 }}
{{- end }}
triggers:
{{- include "event-reporters.http.trigger" (dict "name" "workflows" "Values" .Values "payloadDest" "data.object" "retryStrategy" .Values.workflow.sensor.retryStrategy) | nindent 4 }}
{{- include "event-reporters.http.trigger" (dict "name" "workflows" "Values" .Values "payloadDest" "data.object" "retryStrategy" .Values.workflow.sensor.retryStrategy "policy" .Values.workflow.sensor.policy "atLeastOnce" .Values.workflow.sensor.atLeastOnce) | nindent 4 }}
{{- include "event-reporters.log.trigger" (.Values.workflow.sensor.logging) | nindent 4 }}
{{- end }}
14 changes: 14 additions & 0 deletions charts/gitops-runtime/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,17 @@ HTTPS_PROXY: {{ .Values.global.httpsProxy }}
NO_PROXY: {{ .Values.global.noProxy }}
{{- end }}
{{- end -}}

{{- define "codefresh-gitops-runtime.eventbus.name" }}
{{- $eventBusName := "" }}
{{- $eventBusType := .type }}
{{- if eq $eventBusType "nats" }}
{{- $eventBusName = default "codefresh-eventbus" .name }}
{{- else if eq $eventBusType "jetstream" }}
{{- $eventBusName = default "codefresh-eventbus-jetstream" .name }}
{{- else }}
{{- fail (printf "ERROR: EventBus type %s is inavlid, must be nats|jetstream" $eventBusType ) }}
{{- end }}

{{- printf "%s" $eventBusName }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $eventBusName := default "codefresh-eventbus" .Values.global.runtime.eventBus.name }}
{{- $eventBusName := (include "codefresh-gitops-runtime.eventbus.name" .Values.global.runtime.eventBus) }}
{{- $eventBusSpec := .Values.global.runtime.eventBus }}
{{- $eventBusType := .Values.global.runtime.eventBus.type }}
{{/* Remove name from eventbus spec */}}
Expand Down
2 changes: 1 addition & 1 deletion charts/gitops-runtime/templates/eventbus/pdb.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $eventBusName := default "codefresh-eventbus" .Values.global.runtime.eventBus.name }}
{{- $eventBusName := (include "codefresh-gitops-runtime.eventbus.name" .Values.global.runtime.eventBus) }}
{{- if .Values.global.runtime.eventBus.pdb.enabled }}
apiVersion: policy/v1
kind: PodDisruptionBudget
Expand Down
64 changes: 64 additions & 0 deletions charts/gitops-runtime/tests/event-reporters-sensors_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,67 @@ tests:
factor: 1.2
jitter: 3

- it: HTTP trigger contains policy if set - workflow reporter
template: 'event-reporters/workflow-reporter/sensor.yaml'
values:
- './values/mandatory-values.yaml'
set:
event-reporters.workflow.sensor:
policy:
status:
allow:
- 200
asserts:
- equal:
path: spec.triggers[0].policy
value:
status:
allow:
- 200

- it: HTTP trigger contains atLeastOnce if unset - rollout reporter
template: 'event-reporters/rollout-reporter/sensor.yaml'
values:
- './values/mandatory-values.yaml'
set:
event-reporters.rollout.sensor:
atLeastOnce: false
asserts:
- equal:
path: spec.triggers[0].atLeastOnce
value: false


- it: HTTP trigger contains atLeastOnce if unset - workflow reporter
template: 'event-reporters/workflow-reporter/sensor.yaml'
values:
- './values/mandatory-values.yaml'
set:
event-reporters.workflow.sensor:
atLeastOnce: false
asserts:
- equal:
path: spec.triggers[0].atLeastOnce
value: false

- it: uses the correct eventBusName if type is jetstream - rollout reporter
template: 'event-reporters/rollout-reporter/sensor.yaml'
values:
- './values/mandatory-values.yaml'
set:
global.runtime.eventBus.type: jetstream
asserts:
- equal:
path: spec.eventBusName
value: codefresh-eventbus-jetstream

- it: uses the correct eventBusName if type is jetstream - workflow reporter
template: 'event-reporters/workflow-reporter/sensor.yaml'
values:
- './values/mandatory-values.yaml'
set:
global.runtime.eventBus.type: jetstream
asserts:
- equal:
path: spec.eventBusName
value: codefresh-eventbus-jetstream
40 changes: 40 additions & 0 deletions charts/gitops-runtime/tests/eventbus_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ tests:
path: spec.nats
- notExists:
path: spec.jetstream
- equal:
path: metadata.name
value: codefresh-eventbus

- it: Should create an EventBus with the correct type (jetstream)
template: eventbus/codefresh-eventbus.yaml
Expand All @@ -26,3 +29,40 @@ tests:
path: spec.jetstream
- notExists:
path: spec.nats

- it: Should create an EventBus with the correct default name (nats)
template: eventbus/codefresh-eventbus.yaml
values:
- ./values/mandatory-values.yaml
set:
global.runtime.eventBus.type: nats
asserts:
- equal:
path: metadata.name
value: codefresh-eventbus

- it: Should create an EventBus with the correct override name (nats)
template: eventbus/codefresh-eventbus.yaml
values:
- ./values/mandatory-values.yaml
set:
global.runtime.eventBus:
name: manual-override
type: nats
asserts:
- equal:
path: metadata.name
value: manual-override

- it: Should create an EventBus with the correct override name (jetstream)
template: eventbus/codefresh-eventbus.yaml
values:
- ./values/mandatory-values.yaml
set:
global.runtime.eventBus:
name: manual-override
type: jetstream
asserts:
- equal:
path: metadata.name
value: manual-override
26 changes: 24 additions & 2 deletions charts/gitops-runtime/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ global:

# -- Runtime eventbus
eventBus:
# -- Eventbus name
name: 'codefresh-eventbus'
# -- Eventbus name
name: ''
# -- Annotations on EventBus resource
annotations: {}
# -- Pod disruption budget for the eventbus
Expand Down Expand Up @@ -374,6 +374,8 @@ event-reporters:
logging:
enabled: false
intervalSeconds: 0
# -- At Least Once
atLeastOnce: true
# -- Retry strategy for events sent to Codefresh
retryStrategy:
# -- Number of retries
Expand All @@ -384,6 +386,15 @@ event-reporters:
factor: 1.0
# -- The sleep between each retry is the duration plus an additional amount chosen uniformly at random from the interval between zero and `jitter * duration`.
jitter: 1
policy:
status:
allow:
- 200
- 201
- 204
- 400
- 401
- 404
replicas: 1
resources: {}
# -- Environment variables for sensor pods - add DEBUG_LOG: "true" to add debug level logs
Expand All @@ -405,6 +416,8 @@ event-reporters:
logging:
enabled: false
intervalSeconds: 0
# -- At Least Once
atLeastOnce: true
# -- Retry strategy for events sent to Codefresh
retryStrategy:
# -- Number of retries
Expand All @@ -415,6 +428,15 @@ event-reporters:
factor: 1.0
# -- The sleep between each retry is the duration plus an additional amount chosen uniformly at random from the interval between zero and `jitter * duration`.
jitter: 1
policy:
status:
allow:
- 200
- 201
- 204
- 400
- 401
- 404
replicas: 1
resources: {}
# -- Environment variables for sensor pods - add DEBUG_LOG: "true" to add debug level logs
Expand Down
1 change: 1 addition & 0 deletions tests/component-tests/setup/codefresh-isc
Submodule codefresh-isc added at 36db60
1 change: 1 addition & 0 deletions tests/component-tests/setup/simple-app
Submodule simple-app added at 725c73
Loading