访次: AmazingCounters.com 次

argocd 同步 部署 状态集成钉钉通知

在使用gitop 过程中需要明确知道 每个环节的具体情况,此文在argocd 环节进行了 钉钉集成具体方法如下

1、在 argocd 安装文件 install.yaml 文件里的 argocd-notifications-cm 部分进行相关配置

首先在在PC端安装部署 钉钉PC版  创建群聊 添加自定义机器人 然后获取机器的webhook地址

 往下拉找到机器人部分

 添加机器人

 

 

 

这里 可以设置安装方式 有三种方式 我这里使用的是关键字 

也可以选择使用标签,如果使用标签的方式 请参考这篇文章  https://www.cnblogs.com/nb-blog/p/18071093

 

 在群聊里添加机器人后就可以配置 argocd 的 install.yaml 文件了

修改 install.yaml 文件的argocd-notifications-cm 相关配置信息

由于文件比较大我整理到gitee 了

https://gitee.com/stud_1/install_argocd/blob/master/new_install.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
data:
  service.webhook.dingtalk: |
    url: https://oapi.dingtalk.com/robot/send?access_token=9a632a742960d1dd0943ebf21948140340354b4a2d06eb4399cab72984475de8
    headers:
      - name: Content-Type
        value: application/json
  context: |
    argocdUrl: https://101.43.196.155:32329
  template.app-sync-change: |
    webhook:
      dingtalk:
        method: POST
        body: |
          {
                "msgtype": "markdown",
                "markdown": {
                    "title":"ArgoCD应用状态",
                    "text": "### ArgoCD应用状态\n> - 应用名称111111: {{.app.metadata.name}}\n> - 同步状态: {{ .app.status.operationState.phase}}\n> - 时间:{{.app.status.operationState.finishedAt}}\n> - 应用URL: [点击跳转]({{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true) \n"
                }
          }
  template.app-sync-status-unknown: |
    webhook:
      dingtalk:
        method: POST
        body: |
          {
                "msgtype": "markdown",
                "markdown": {
                    "title":"ArgoCD应用Unknown",
                    "text": "### ArgoCD应用Unknown\n> - <font color=\"warning\">应用名称</font>: {{.app.metadata.name}}\n> - <font color=\"warning\">应用同步状态</font>: {{.app.status.sync.status}}\n> - <font color=\"warning\">应用健康状态</font>: {{.app.status.health.status}}\n> - <font color=\"warning\">时间</font>: {{.app.status.operationState.startedAt}}\n> - <font color=\"warning\">应用URL</font>: [点击跳转ArgoCD UI]({{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true)"
                }
          }
  template.app-sync-failed: |
    webhook:
      dingtalk:
        method: POST
        body: |
          {
                "msgtype": "markdown",
                "markdown": {
                    "title":"ArgoCD应用发布失败",
                    "text": "### ArgoCD应用发布失败\n> - <font color=\"danger\">应用名称</font>: {{.app.metadata.name}}\n> - <font color=\"danger\">应用同步状态</font>: {{.app.status.operationState.phase}}\n> - <font color=\"danger\">应用健康状态</font>: {{.app.status.health.status}}\n> - <font color=\"danger\">时间</font>: {{.app.status.operationState.startedAt}}\n> - <font color=\"danger\">应用URL</font>: [点击跳转ArgoCD UI]({{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true)"
                }
          }
  trigger.on-deployed: |
    - description: Application is synced and healthy. Triggered once per commit.
      oncePer: app.status.sync.revision
      send: [app-sync-change]
      # trigger condition
      when: app.status.operationState.phase in ['Succeeded'] and app.status.health.status == 'Healthy'
  trigger.on-health-degraded: |
    - description: Application has degraded
      send: [app-sync-change]
      when: app.status.health.status == 'Degraded'
  trigger.on-sync-failed: |
    - description: Application syncing has failed
      send: [app-sync-failed]
      when: app.status.operationState != nil and app.status.operationState.phase in ['Error','Failed']
  trigger.on-sync-status-unknown: |
    - description: Application status is 'Unknown'
      send: [app-sync-status-unknown]
      when: app.status.sync.status == 'Unknown'
  trigger.on-sync-running: |
    - description: Application is being synced
      send: [app-sync-change]
      when: app.status.operationState != nil and app.status.operationState.phase in ['Running']
  trigger.on-sync-succeeded: |
    - description: Application syncing has succeeded
      send: [app-sync-change]
      when: app.status.operationState != nil and app.status.operationState.phase in ['Succeeded']
  subscriptions: |
    - recipients: [dingtalk]
      triggers: [on-sync-failed, on-sync-succeeded, on-sync-status-unknown,on-deployed,on-health-degraded]
---
apiVersion: v1
data:
  policy.csv: |
    g, admin@example.com, role:admin
  policy.default: role:readonly
  scopes: '[email, group]'
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/name: argocd-rbac-cm
    app.kubernetes.io/part-of: argocd
  name: argocd-rbac-cm
argocd-notifications-cm argocd-rbac-cm

 

posted @ 2024-03-15 16:44  IT老登  阅读(101)  评论(0编辑  收藏  举报
访次: AmazingCounters.com 次