---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: sample-pipeline
  namespace: jk
spec:
  tasks:
    - name: sample-task
      taskSpec:
        params:
          - name: app-name
            type: string
            default: no-data
          - name: data-json-array-string
            type: string
            default: '["no-data"]'
          - name: data-json-array-object
            type: string
            default: '[{"data": "no-data"}]'
          - name: data-json-object
            type: string
            default: '{"data": "nodata"}'
        steps:
          - name: echo-step
            image: alpine:3.17.3
            script: |
              echo "App name: $(params.app-name)"
              echo "data-json-array-string: $(params.data-json-array-string)"
              echo "data-json-array-object: $(params.data-json-array-object)"
              echo "data-json-object: $(params.data-json-object)"

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: tekton-triggers-example-sa
  namespace: jk

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: triggers-example-eventlistener-binding
subjects:
- kind: ServiceAccount
  name: tekton-triggers-example-sa
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: tekton-triggers-eventlistener-roles

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: triggers-example-eventlistener-clusterbinding
subjects:
- kind: ServiceAccount
  name: tekton-triggers-example-sa
  namespace: jk
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: tekton-triggers-eventlistener-clusterroles

---
apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
  name: generic-el-test
  namespace: jk
spec:
  serviceAccountName: tekton-triggers-example-sa
  triggers:
    - name: trigger-1
      interceptors:
        - name: "CEL interceptor"
          ref:
            name: "cel"
          params:
          - name: "overlays"
            value:
            - key: array_string_data
              expression: "body.array_string_data.marshalJSON()"
            - key: array_object_data
              expression: "body.array_object_data.marshalJSON()"
            - key: object_data
              expression: "body.object_data.marshalJSON()"
      bindings:
        - name: app-name
          value: $(body.app_name)
        - name: data-json-array-string
          value: $(extensions.array_string_data)
        - name: data-json-array-object
          value: $(extensions.array_object_data)
        - name: data-json-object
          value: $(extensions.object_data)
      template:
        ref: trigger-template-test

---
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
  name: trigger-template-test
  namespace: jk
spec:
  params:
  - name: app-name
  - name: data-json-array-string
  - name: data-json-array-object
  - name: data-json-object
  resourcetemplates:
  - apiVersion: tekton.dev/v1beta1
    kind: PipelineRun
    metadata:
      generateName: simple-pipeline-run-
    spec:
      pipelineRef:
        name: sample-pipeline
      params:
        - name: app-name
          value: $(tt.params.app-name)
        - name: data-json-array-string
          value: $(tt.params.data-json-array-string)
        - name: data-json-array-object
          value: $(tt.params.data-json-array-object)
        - name: data-json-object
          value: $(tt.params.data-json-object)

---
kind: Route
apiVersion: route.openshift.io/v1
metadata:
  name: el-test
  namespace: jk
spec:
  to:
    kind: Service
    name: el-generic-el-test
  port:
    targetPort: http-listener
