diff --git a/charts/gitops-runtime/templates/_components/event-reporters/_helpers.tpl b/charts/gitops-runtime/templates/_components/event-reporters/_helpers.tpl index f8dd300e..5e6b9fd4 100644 --- a/charts/gitops-runtime/templates/_components/event-reporters/_helpers.tpl +++ b/charts/gitops-runtime/templates/_components/event-reporters/_helpers.tpl @@ -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 */}} diff --git a/charts/gitops-runtime/templates/_components/event-reporters/rollout-reporter/_event-source.yaml b/charts/gitops-runtime/templates/_components/event-reporters/rollout-reporter/_event-source.yaml index b801e593..81395db4 100644 --- a/charts/gitops-runtime/templates/_components/event-reporters/rollout-reporter/_event-source.yaml +++ b/charts/gitops-runtime/templates/_components/event-reporters/rollout-reporter/_event-source.yaml @@ -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: diff --git a/charts/gitops-runtime/templates/_components/event-reporters/rollout-reporter/_sensor.yaml b/charts/gitops-runtime/templates/_components/event-reporters/rollout-reporter/_sensor.yaml index 6639b51b..b0cba840 100644 --- a/charts/gitops-runtime/templates/_components/event-reporters/rollout-reporter/_sensor.yaml +++ b/charts/gitops-runtime/templates/_components/event-reporters/rollout-reporter/_sensor.yaml @@ -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: @@ -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 }} diff --git a/charts/gitops-runtime/templates/_components/event-reporters/workflow-reporter/_event-source.yaml b/charts/gitops-runtime/templates/_components/event-reporters/workflow-reporter/_event-source.yaml index c613bb39..742a1102 100644 --- a/charts/gitops-runtime/templates/_components/event-reporters/workflow-reporter/_event-source.yaml +++ b/charts/gitops-runtime/templates/_components/event-reporters/workflow-reporter/_event-source.yaml @@ -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: diff --git a/charts/gitops-runtime/templates/_components/event-reporters/workflow-reporter/_sensor.yaml b/charts/gitops-runtime/templates/_components/event-reporters/workflow-reporter/_sensor.yaml index 77f02f91..f763de65 100644 --- a/charts/gitops-runtime/templates/_components/event-reporters/workflow-reporter/_sensor.yaml +++ b/charts/gitops-runtime/templates/_components/event-reporters/workflow-reporter/_sensor.yaml @@ -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: @@ -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 }} diff --git a/charts/gitops-runtime/templates/_helpers.tpl b/charts/gitops-runtime/templates/_helpers.tpl index 2e553ddd..bbfb102d 100644 --- a/charts/gitops-runtime/templates/_helpers.tpl +++ b/charts/gitops-runtime/templates/_helpers.tpl @@ -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 }} diff --git a/charts/gitops-runtime/templates/eventbus/codefresh-eventbus.yaml b/charts/gitops-runtime/templates/eventbus/codefresh-eventbus.yaml index d9957b19..4e773096 100644 --- a/charts/gitops-runtime/templates/eventbus/codefresh-eventbus.yaml +++ b/charts/gitops-runtime/templates/eventbus/codefresh-eventbus.yaml @@ -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 */}} diff --git a/charts/gitops-runtime/templates/eventbus/pdb.yaml b/charts/gitops-runtime/templates/eventbus/pdb.yaml index 14ed6868..1d74d750 100644 --- a/charts/gitops-runtime/templates/eventbus/pdb.yaml +++ b/charts/gitops-runtime/templates/eventbus/pdb.yaml @@ -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 diff --git a/charts/gitops-runtime/tests/event-reporters-sensors_test.yaml b/charts/gitops-runtime/tests/event-reporters-sensors_test.yaml index 340b5879..23bb0542 100644 --- a/charts/gitops-runtime/tests/event-reporters-sensors_test.yaml +++ b/charts/gitops-runtime/tests/event-reporters-sensors_test.yaml @@ -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 diff --git a/charts/gitops-runtime/tests/eventbus_test.yaml b/charts/gitops-runtime/tests/eventbus_test.yaml index f15c6462..b6ea09ea 100644 --- a/charts/gitops-runtime/tests/eventbus_test.yaml +++ b/charts/gitops-runtime/tests/eventbus_test.yaml @@ -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 @@ -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 diff --git a/charts/gitops-runtime/values.yaml b/charts/gitops-runtime/values.yaml index 46b86443..ce68ba28 100644 --- a/charts/gitops-runtime/values.yaml +++ b/charts/gitops-runtime/values.yaml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/component-tests/setup/codefresh-isc b/tests/component-tests/setup/codefresh-isc new file mode 160000 index 00000000..36db6073 --- /dev/null +++ b/tests/component-tests/setup/codefresh-isc @@ -0,0 +1 @@ +Subproject commit 36db6073a3c784095872b5243aeb1cbb31f85765 diff --git a/tests/component-tests/setup/simple-app b/tests/component-tests/setup/simple-app new file mode 160000 index 00000000..725c7353 --- /dev/null +++ b/tests/component-tests/setup/simple-app @@ -0,0 +1 @@ +Subproject commit 725c7353bd7859036d547c97b948734c91d30d61