diff --git a/argo-event/.helmignore b/argo-event/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/argo-event/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/argo-event/Chart.yaml b/argo-event/Chart.yaml new file mode 100644 index 0000000..d0fb74e --- /dev/null +++ b/argo-event/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v2 +name: argo-event +description: A Helm chart for deploying argo event +type: application +version: 0.0.1 diff --git a/argo-event/templates/_eventsource.tpl b/argo-event/templates/_eventsource.tpl new file mode 100644 index 0000000..57908fb --- /dev/null +++ b/argo-event/templates/_eventsource.tpl @@ -0,0 +1,8 @@ +{{- define "source.webhook" }} + {{- $item := index . 0 -}} + {{- $globalVal := index . 1 -}} + {{- $item.eventName | required "Missing eventName" }}: + endpoint: {{ $item.endpoint | required (printf "Missing endpoint for source: %s" $item.eventName) | printf "/webhook%s" }} + method: {{ $item.method | required (printf "Missing method for source: %s " $item.eventName) }} + port: {{ $globalVal.eventsource.config.webhookPort | quote}} +{{- end }} \ No newline at end of file diff --git a/argo-event/templates/_helper.tpl b/argo-event/templates/_helper.tpl new file mode 100644 index 0000000..25800a3 --- /dev/null +++ b/argo-event/templates/_helper.tpl @@ -0,0 +1,9 @@ +{{- define "helper.containType" -}} + {{- $list := index . 0 -}} + {{- $search := index . 1 -}} + {{- if eq (first $list).type $search -}} + yes + {{- else if gt 1 (len $list) -}} + {{- include "helper.containType" (list (rest $list) $search) -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/argo-event/templates/_sensor.tpl b/argo-event/templates/_sensor.tpl new file mode 100644 index 0000000..ede8656 --- /dev/null +++ b/argo-event/templates/_sensor.tpl @@ -0,0 +1,11 @@ +{{- define "trigger.http" }} + http: + url: {{ .url }} + method: {{ .method | default "POST"}} + headers: + content-type: application/json + {{- with .payload }} + payload: + {{- toYaml . | nindent 14 }} + {{- end -}} +{{- end }} \ No newline at end of file diff --git a/argo-event/templates/eventbus.yaml b/argo-event/templates/eventbus.yaml new file mode 100644 index 0000000..6d2afc7 --- /dev/null +++ b/argo-event/templates/eventbus.yaml @@ -0,0 +1,83 @@ +apiVersion: argoproj.io/v1alpha1 +kind: EventBus +metadata: + name: {{ .Values.name }} + labels: + {{- with .Values.labels }} + {{ toYaml . | nindent 4 }} + {{- end }} + app: {{ .Values.name }}-eventbus +spec: + jetstream: + metadata: + labels: + {{- with .Values.labels }} + {{ toYaml . | nindent 8 }} + {{- end }} + app: {{ .Values.name }}-eventbus + + version: {{ .Values.eventbus.config.version }} + + affinity: + {{- with .Values.eventbus.config.affinity.nodeAffinity }} + nodeAffinity: {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.eventbus.config.affinity.podAffinity }} + podAffinity: {{- toYaml . | nindent 8 }} + {{- end }} + podAntiAffinity: + {{- with .Values.eventbus.config.affinity.podAntiAffinity }} + {{- if hasKey . "requiredDuringSchedulingIgnoredDuringExecution" }} + requiredDuringSchedulingIgnoredDuringExecution: {{- toYaml .requiredDuringSchedulingIgnoredDuringExecution | nindent 10 }} + {{- end }} + {{- end }} + preferredDuringSchedulingIgnoredDuringExecution: + {{- with .Values.eventbus.config.affinity.podAntiAffinity }} + {{- if hasKey . "preferredDuringSchedulingIgnoredDuringExecution" }} + {{- toYaml .preferredDuringSchedulingIgnoredDuringExecution | nindent 10 }} + {{- end }} + {{- end }} + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: app + operator: In + values: + - {{ $.Values.name }}-eventbus + topologyKey: topology.kubernetes.io/zone + weight: 100 + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: app + operator: In + values: + - {{ $.Values.name }}-eventbus + topologyKey: kubernetes.io/hostname + weight: 99 + + {{- with .Values.eventbus.config.persistence }} + persistence: + {{- with .storageClassName }} + storageClassName: {{ . }} + {{- end }} + {{- with .accessMode }} + accessMode: {{ . }} + {{- end }} + volumeSize: {{ .volumeSize | required "Missing volumeSize for jetstream"}} + {{- end }} + + replicas: {{ .Values.eventbus.config.replicas | min 3 }} + + {{- with .Values.eventbus.config }} + streamConfig: | + {{- with .maxAge }} + maxAge: {{ . }} + {{- end }} + {{- with .duplicates }} + duplicates: {{ . }} + {{- end }} + {{- end }} + + settings: | + max_file_store: {{ .Values.eventbus.config.maxFileStore }} \ No newline at end of file diff --git a/argo-event/templates/eventsource.yaml b/argo-event/templates/eventsource.yaml new file mode 100644 index 0000000..e8dc505 --- /dev/null +++ b/argo-event/templates/eventsource.yaml @@ -0,0 +1,73 @@ +apiVersion: argoproj.io/v1alpha1 +kind: EventSource +metadata: + name: {{ .Values.name }} + labels: + {{- with .Values.labels }} + {{ toYaml . | nindent 4 }} + {{- end }} + app: {{ .Values.name }}-eventsource +spec: + eventBusName: {{ .Values.name }} + replicas: {{ .Values.eventsource.config.replicas | max 1 }} + + template: + metadata: + labels: + {{- with .Values.labels }} + {{ toYaml . | nindent 8 }} + {{- end }} + app: {{ .Values.name }}-eventsource + affinity: + {{- with .Values.eventsource.config.affinity.nodeAffinity }} + nodeAffinity: {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.eventsource.config.affinity.podAffinity }} + podAffinity: {{- toYaml . | nindent 8 }} + {{- end }} + podAntiAffinity: + {{- with .Values.eventsource.config.affinity.podAntiAffinity }} + {{- if hasKey . "requiredDuringSchedulingIgnoredDuringExecution" }} + requiredDuringSchedulingIgnoredDuringExecution: {{- toYaml .requiredDuringSchedulingIgnoredDuringExecution | nindent 10 }} + {{- end }} + {{- end }} + preferredDuringSchedulingIgnoredDuringExecution: + {{- with .Values.eventsource.config.affinity.podAntiAffinity }} + {{- if hasKey . "preferredDuringSchedulingIgnoredDuringExecution" }} + {{- toYaml .preferredDuringSchedulingIgnoredDuringExecution | nindent 10 }} + {{- end }} + {{- end }} + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: app + operator: In + values: + - {{ $.Values.name }}-eventsource + topologyKey: topology.kubernetes.io/zone + weight: 100 + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: app + operator: In + values: + - {{ $.Values.name }}-eventsource + topologyKey: kubernetes.io/hostname + weight: 99 + + service: + ports: + - port: {{ .Values.eventsource.config.servicePort }} + targetPort: {{ .Values.eventsource.config.webhookPort }} + + {{- with .Values.eventsource.source -}} + {{if eq (include "helper.containType" (list . "webhook" )) "yes" }} + webhook: + {{- range $index, $element := . }} + {{- if eq $element.type "webhook" }} + {{ template "source.webhook" (list $element $.Values) }} + {{- end }} + {{- end }} + {{- end -}} + {{ end }} \ No newline at end of file diff --git a/argo-event/templates/ingress.yaml b/argo-event/templates/ingress.yaml new file mode 100644 index 0000000..c990387 --- /dev/null +++ b/argo-event/templates/ingress.yaml @@ -0,0 +1,31 @@ +{{- if .Values.ingress -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ .Values.name }} + annotations: + {{- toYaml .Values.ingress.annotations | nindent 4}} +spec: + {{- if .Values.ingress.tls }} + tls: + - hosts: + {{- range .Values.ingress.tls.hosts }} + - "{{ .host }}" + {{- end }} + secretName: {{ .Values.ingress.tls.secretName }} + {{- end }} + rules: + - + {{- if .Values.ingress.host }} + host: {{ .Values.ingress.host }} + {{- end }} + http: + paths: + - backend: + service: + name: {{ .Values.name }}-eventsource-svc + port: + number: {{ .Values.eventsource.config.servicePort }} + path: {{ .Values.ingress.path }} + pathType: ImplementationSpecific +{{- end -}} diff --git a/argo-event/templates/sensor.yaml b/argo-event/templates/sensor.yaml new file mode 100644 index 0000000..2c0a8f0 --- /dev/null +++ b/argo-event/templates/sensor.yaml @@ -0,0 +1,82 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Sensor +metadata: + name: {{ .Values.name }} + labels: + {{- with .Values.labels }} + {{ toYaml . | nindent 4 }} + {{- end }} + app: {{ .Values.name }}-sensor +spec: + eventBusName: {{ .Values.name }} + replicas: {{ .Values.eventsensor.config.replicas | max 1 }} + + template: + metadata: + labels: + {{- with .Values.labels }} + {{ toYaml . | nindent 8 }} + {{- end }} + app: {{ .Values.name }}-sensor + affinity: + {{- with .Values.eventsensor.config.affinity.nodeAffinity }} + nodeAffinity: {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.eventsensor.config.affinity.podAffinity }} + podAffinity: {{- toYaml . | nindent 8 }} + {{- end }} + podAntiAffinity: + {{- with .Values.eventsensor.config.affinity.podAntiAffinity }} + {{- if hasKey . "requiredDuringSchedulingIgnoredDuringExecution" }} + requiredDuringSchedulingIgnoredDuringExecution: {{- toYaml .requiredDuringSchedulingIgnoredDuringExecution | nindent 10 }} + {{- end }} + {{- end }} + preferredDuringSchedulingIgnoredDuringExecution: + {{- with .Values.eventsensor.config.affinity.podAntiAffinity }} + {{- if hasKey . "preferredDuringSchedulingIgnoredDuringExecution" }} + {{- toYaml .preferredDuringSchedulingIgnoredDuringExecution | nindent 10 }} + {{- end }} + {{- end }} + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: app + operator: In + values: + - {{ $.Values.name }}-sensor + topologyKey: topology.kubernetes.io/zone + weight: 100 + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: app + operator: In + values: + - {{ $.Values.name }}-sensor + topologyKey: kubernetes.io/hostname + weight: 99 + + dependencies: + {{- range $element := .Values.eventsensor.dependencies }} + - name: {{ $element.dependencyName }} + eventSourceName: {{ $.Values.name }} + eventName: {{ $element.eventName }} + {{- if $element.filter }} + filter: + {{ toYaml $element.filter }} + {{- end }} + {{- end }} + + triggers: + {{- range $element := .Values.eventsensor.triggers }} + - template: + name: {{ $element.name }} + {{- if eq $element.type "http" }} + {{- template "trigger.http" $element }} + {{- end }} + {{- with .retryStrategy -}} + retryStrategy: + steps: {{- .retryStrategy.steps | default 1 -}} + duration: {{- .retryStrategy.duration | default "1s" -}} + {{- end -}} + {{- end }} \ No newline at end of file diff --git a/argo-event/values.yaml b/argo-event/values.yaml new file mode 100644 index 0000000..e4ba7af --- /dev/null +++ b/argo-event/values.yaml @@ -0,0 +1,241 @@ + +# Name, required +# example +# name: use-case-1 + +# Labels for eventbus, event source and sensor, optional +labels: {} + +# For event bus +eventbus: + config: + # version of jetstream, default "latest" + version: 2.9.11 + + replicas: 3 + + # persistence, optional + # persistence: {} + + # example + # persistence: + # storageClassName: storage-1 + # accessMode: ReadWriteOnce + # volumeSize: 10Gi + + # affinity, optional + affinity: + # nodeAffinity, optional + nodeAffinity: {} + # example + # nodeAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # nodeSelectorTerms: + # - matchExpressions: + # - key: app + # operator: In + # values: + # - some-value + + # podAffinity, optional + podAffinity: {} + # example + # podAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # - labelSelector: + # matchExpressions: + # - key: app + # operator: In + # values: + # - some-value + + # podAntiAffinity, optional + # if you set .podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution,you will combined with default setting. + # default: prefer difference az(weight:100) and node(weight:99) + podAntiAffinity: {} + # example + # podAntiAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # - labelSelector: + # matchExpressions: + # - key: app + # operator: In + # values: + # - some-value + + # maxAge, optional, the oldest message store in jetstream + # immutable, need reinstall after change + # maxAge: 0 + + # duplicates, optional, the deduplication window in jetstream + # immutable, need reinstall after change + # duplicates: 2m + + # maxFileStore, optional, the maximum file storage used for storing events + maxFileStore: 1GB + +eventsource: + config: + # servicePort, optional, default 12051 + # define which port exported for eventsource's pod + servicePort: 12051 + + # webhookPort, optional, default 12051 + # define which port that the svc will connect to webhook pod + webhookPort: 12051 + + # replicas: optional, default 1 + # number of replicas for source pod + replicas: 1 + + # affinity, optional + affinity: + # nodeAffinity, optional + nodeAffinity: {} + # example + # nodeAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # nodeSelectorTerms: + # - matchExpressions: + # - key: app + # operator: In + # values: + # - some-value + + # podAffinity, optional + podAffinity: {} + # example + # podAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # - labelSelector: + # matchExpressions: + # - key: app + # operator: In + # values: + # - some-value + + # podAntiAffinity, optional + # if you set .podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution,you will combined with default setting. + # default: prefer difference az(weight:100) and node(weight:99) + podAntiAffinity: {} + # example + # podAntiAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # - labelSelector: + # matchExpressions: + # - key: app + # operator: In + # values: + # - some-value + + # source(array), reuqired + # only webhook is supported at this moment + source: [] + # common field + # eventName(string): the name for this event + # type(string): requrird, the type of source + + # webhook: + # endpoint(string): requried, the endpoint to trigger this event + # method(string): requried, the method to trigger this event + + # Example: + # - eventName: use-case-eventsource-1 + # type: webhook + # endpoint: /webhook + # method: POST + + +eventsensor: + config: + # replicas: optional, default 1 + # number of replicas for source pod + replicas: 1 + + affinity: + # nodeAffinity, optional + nodeAffinity: {} + # example + # nodeAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # nodeSelectorTerms: + # - matchExpressions: + # - key: app + # operator: In + # values: + # - some-value + + # podAffinity, optional + podAffinity: {} + # example + # podAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # - labelSelector: + # matchExpressions: + # - key: app + # operator: In + # values: + # - some-value + + # podAntiAffinity, optional + # if you set .podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution,you will combined with default setting. + # default: prefer difference az(weight:100) and node(weight:99) + podAntiAffinity: {} + # example + # podAntiAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # - labelSelector: + # matchExpressions: + # - key: app + # operator: In + # values: + # - some-value + + # deplendcies(array), the event use in this sensor + deplendencies: [] + # Example + # - dependencyName: use-case-eventsource-1 + # eventName: use-case-eventsource-1 + + # triggers(array): required, the trigger for the sensor + triggers: [] + # common field + # name(string): name for the trigger + # type(string): type for the trigger, only http supported at this moment + # payload(object): payload for trigger, for more detail, follow official doc of argo-event + # link: https://github.com/argoproj/argo-events/blob/master/api/sensor.md + + # http: + # url(string): required, url to call + # method(string): method to call + + # Example + # - name: http-trigger + # type: http + # url: http://testing/com + # method: POST + # payload: + # - src: + # dependencyName: use-case-eventsource-1 + # dataKey: body + # useRawData: true + # dest: body + + +ingress: + # Annotations (mapping object) + annotations: {} + + tls: {} + # Allow using TLS for this ingress + # Example + # tls: + # host: + # - testing.com + # secretName: secretname + + # host(string): host domain for this ingress + # Example + # host: testing.com + + # path(string): path for this ingress \ No newline at end of file