automatiko-io / automatiko-approval-task

Tekton Pipeline Custom task implementation to add approval capabilities into the pipelines
Apache License 2.0
46 stars 14 forks source link

Duplicate Approval E-Mail Sending Issue #11

Closed phenomrascalov closed 1 year ago

phenomrascalov commented 1 year ago

Hello, The approval mails comes as much as the number of recipients. For example, if the number of recipients is 2, it sends 2 e-mails . Could you help with this problem. Thank you for your support. Kind regards,

mswiderski commented 1 year ago

it should send an email to each assignee but only one email per assignee. if this is not what happens you could provide more details about the setup used for the approval task in your pipeline and what is exactly received by assignees.

phenomrascalov commented 1 year ago

In pipeline.yaml, if we write 2 addresses in - name: approvers value: , application send 2 mail for each addresses when the pipeline triggered. If we write 1 address, it send 1 mail. There is no problem.

Automatiko yaml:

---
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app.kubernetes.io/version: 0.7.0
    app.kubernetes.io/name: automatiko-approval-task
  name: automatiko-approval-task
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: automatiko-approval-task
    app.kubernetes.io/version: 0.7.0
  name: automatiko-approval-task
spec:
  ports:
    - name: http
      port: 80
      targetPort: 8080
  selector:
    app.kubernetes.io/name: automatiko-approval-task
    app.kubernetes.io/version: 0.7.0
  type: ClusterIP
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: automatiko-approval-task-view
roleRef:
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
  name: view
subjects:
  - kind: ServiceAccount
    name: automatiko-approval-task
    namespace: tekton
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: approvals-cluster-role
rules:
  - apiGroups:
      - tekton.automatiko.io
    resources:
      - approvaltasks
      - approvaltasks/status
      - approvaltasks/finalizers
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: josdk-crd-validating-cluster-role
rules:
  - apiGroups:
      - apiextensions.k8s.io
    resources:
      - customresourcedefinitions
    verbs:
      - get
      - list
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: customruns-cluster-role
rules:
  - apiGroups:
      - tekton.dev
    resources:
      - customruns
      - customruns/status
      - customruns/finalizers
    verbs:
      - get
      - list
      - watch
      - patch
      - update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: approvals-cluster-role-binding
roleRef:
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
  name: approvals-cluster-role
subjects:
  - kind: ServiceAccount
    name: automatiko-approval-task
    namespace: tekton
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: approvals-crd-validating-role-binding
roleRef:
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
  name: josdk-crd-validating-cluster-role
subjects:
  - kind: ServiceAccount
    name: automatiko-approval-task
    namespace: tekton
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: customruns-cluster-role-binding
roleRef:
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
  name: customruns-cluster-role
subjects:
  - kind: ServiceAccount
    name: automatiko-approval-task
    namespace: tekton
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: runs-crd-validating-role-binding
roleRef:
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
  name: josdk-crd-validating-cluster-role
subjects:
  - kind: ServiceAccount
    name: automatiko-approval-task
    namespace: tekton
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: approvaltask-pv-claim
spec:
  storageClassName: local-storage
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: automatiko-approval-task
    app.kubernetes.io/version: 0.7.0
  name: automatiko-approval-task
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: automatiko-approval-task
      app.kubernetes.io/version: 0.7.0
  template:
    metadata:
      labels:
        app.kubernetes.io/name: automatiko-approval-task
        app.kubernetes.io/version: 0.7.0
    spec:
      volumes:
       - name: approvaltask-pv-storage
         persistentVolumeClaim:
           claimName: approvaltask-pv-claim
       - name: templates-volume
         configMap:        
           name: approval-task-templates
      containers:
        - env:
            - name: KUBERNETES_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: QUARKUS_OPERATOR_SDK_NAMESPACES
              value: tekton
            - name: QUARKUS_AUTOMATIKO_SERVICE_URL
              value: http://approve.zzz.com.tr
            - name: QUARKUS_AUTOMATIKO_PERSISTENCE_FILESYSTEM_PATH
              value: /data/processes
            - name: QUARKUS_AUTOMATIKO_JOBS_FILESYSTEM_PATH
              value: /data/jobs
            - name: QUARKUS_MAILER_FROM
              value: tekton@zzz.com.tr
            - name: QUARKUS_MAILER_HOST
              value: xxx
            - name: QUARKUS_MAILER_PORT
              value: "10"
            - name: QUARKUS_PROFILE
              value: withemail
            - name: QUARKUS_MAILER_START_TLS
              value: DISABLED
            - name: QUARKUS_AUTOMATIKO_TEMPLATES_FOLDER
              value: "/templates"
          image: 10.10.10.10:1010/automatiko/automatiko-approval-task:0.7.0
          imagePullPolicy: Always
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /q/health/live
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 0
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 10
          name: automatiko-approval-task
          ports:
            - containerPort: 8080
              name: http
              protocol: TCP
          volumeMounts:
           - mountPath: "/data"
             name: approvaltask-pv-storage
           - name: templates-volume
             mountPath: "/templates"
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /q/health/ready
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 0
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 10
      serviceAccountName: automatiko-approval-task

pipeline.yaml:

apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
  name: deploy-approval-pipeline
spec:
  params:
  - name: name
  - name: version
  tasks:
  - name: approval
    taskRef:
      apiVersion: tekton.automatiko.io/v1beta1
      kind: ApprovalTask
      name: approvaltask
    params:
    - name: pipeline
      value: "$(context.pipelineRun.name).
    - name: description
      value: "deployment approval."
    - name: approvers
      value:
      - "xxx@zzz.com.tr"
      - "yyy@zzz.com.tr"
  - name: approved
    when:
    - input: $(tasks.approval.results.decision)
      operator: in
      values: [ "true" ]
    taskRef:
      name: decision-deploy-approval
    runAfter:
    - approval
    params:
    - name: decision
      value: "APPROVED"
    - name: comment
      value: $(tasks.approval.results.comment)
  - name: rejected
    when:
    - input: $(tasks.approval.results.decision)
      operator: in
      values: [ "false" ]
    taskRef:
      name: decision-deploy-approval
    runAfter:
    - approval
    params:
    - name: decision
      value: "REJECTED"
    - name: comment
      value: $(tasks.approval.results.comment)
mswiderski commented 1 year ago

thanks for details, you are right that there is an issue with the notification component and I logged an issue to fix it: https://github.com/automatiko-io/automatiko-engine/issues/344

will need to make a release of automatiko and then of approval task.

phenomrascalov commented 1 year ago

Thanks for your help. We will follow the issue you created for Automatiko Engine.

mswiderski commented 1 year ago

just made a quick fix and built the approval task locally, if you would like to give it a try please use this image mswiderski/automatiko-approval-task:0.8.0

phenomrascalov commented 1 year ago

It is fixed now. Thank you very much.

mswiderski commented 1 year ago

excellent, thanks for confirmation, will work on the release and let you know when it is ready so you can move to the official image

mswiderski commented 1 year ago

this has been fixed with https://github.com/automatiko-io/automatiko-approval-task/commit/59a506b00cbbe30836cc35abff7765f0e36a8b56 and 0.8.0 version was released.