使用argocd-notifications通知Tekton触发api-test

安装argocd-notifications

下载helm chart

helm repo add argo https://argoproj.github.io/argo-helm
helm pull argo/argocd-notifications

创建values.yaml

argocdUrl: https://argo-argocd-server.cicd.svc
image:
  # build image by https://github.com/paradeum-team/argocd-notifications/tree/jyliu
  # fix: repo.GetAppDetails().Helm.parameters not get argocd override value 
  repository: quay.io/netwarps/argocd-notifications
  tag: v1.2.1.1
secret:
  items:
    webhooks-tekton-api-test-token: "xxxxxxxxxx"
    email-username: cicd@example.com
    email-password: xxxxxxxxx
logLevel: info
extraArgs:
  - --argocd-repo-server=argo-argocd-repo-server:8081

notifiers:
  service.email: |
    host: smtp.exmail.qq.com
    port: 587
    from: $email-username
    username: $email-username
    password: $email-password
  service.webhook.tekton-api-test: |
    url: http://el-github-listener.tekton-pipelines.svc:8080
    headers:
      - name: X-Github-Token
        value: $webhooks-tekton-api-test-token
      - name: content-type
        value: "application/json"
subscriptions:
  - recipients:
    - webhook.tekton-api-test:""
    - email:liujinye@example.com
    triggers:
    - app-sync-succeeded
templates:
  template.app-sync-succeeded: |
    email:
      subject: Application {{.app.metadata.name}} has been successfully synced.
    message: |
      {{if eq .serviceType "slack"}}:white_check_mark:{{end}} Application {{.app.metadata.name}} has been successfully synced at {{.app.status.operationState.finishedAt}}.
      Sync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true .
    webhook:
      tekton-api-test:
        method: POST
        path: /
        body: |
          {
            "project": "{{.app.spec.project}}",
            "name": "{{.app.metadata.name}}",
            "envs": "{{ (call .repo.GetAppDetails).Helm.GetParameterValueByName "test.envs" }}",
            "imageurl": "{{ (call .repo.GetAppDetails).Helm.GetParameterValueByName "test.image.repository" }}",
            "imagetag": "{{ (call .repo.GetAppDetails).Helm.GetParameterValueByName "test.image.tag"}}",
            "command": "{{ (call .repo.GetAppDetails).Helm.GetParameterValueByName "test.command[0]"}}"
          }
triggers:
  trigger.on-sync-succeeded: |
    - description: Application syncing has succeeded
      send:
      - app-sync-succeeded
      when: app.status.operationState.phase in ['Succeeded']
defaultTriggers: |
  - on-sync-succeeded

安装argocd-notifications

需要集成api test 的项目增加api test 相关服务及配置

需要集成api test 的项目(示例wine) helm chart 增加 test 相关默认变量

argocd wine项目中 修改 PARAMETERS 变量 test.envs 值

argocd 项目中添加注解订阅通知,在sync 成功时触发webhook tekton-api-test

wine-api-test 项目集成Tekton

  1. wine-api-test 代码添加tekton webhook 集成

  2. 推送Tag push event 触发Tekton pipeline 制作 wine-api-test 镜像

  3. Tekton pipeline 自动修改 wine-api helm chart 中 test.image.tag

参考:https://liujinye.gitbook.io/kubernetes-docs/cicd/shi-yong-tekton-gou-jian-ci-liu-cheng

Tekton 配置 envs job webhook pipline 接收argocd-notifications 通知

负责接收argocd-notifications 的通知及触发执行api test pipeline

参考:

https://liujinye.gitbook.io/kubernetes-docs/cicd/shi-yong-tekton-gou-jian-ci-liu-cheng

https://github.com/paradeum-team/tekton-catalog

参考:

https://argocd-notifications.readthedocs.io/en/stable/

https://argocd-notifications.readthedocs.io/en/stable/templates/

https://github.com/argoproj/argo-helm/tree/master/charts/argocd-notifications

https://liujinye.gitbook.io/kubernetes-docs/cicd/shi-yong-tekton-gou-jian-ci-liu-cheng

Last updated