GitOps - 为 OpenShift GitOps 配置邮件通知

OpenShift 4.x HOL教程汇总
说明:本文已经 在OpenShift 4.15 + OpenShift GitOps 1.11.2 环境中验证

说明:先根据《OpenShift 4 之 GitOps(1)通过OpenShift GitOps Operator 安装 ArgoCD》完成安装,然后在 ArgoCD 中创建 spring-petclinic 应用。

ArgoCD 的 Notification 功能简介

ArgoCD 在更新完应用后可以根据更新的状态触发相关事件,例如:on-sync-succeeded,on-sync-running,on-sync-failed 等。针对这些事件,可以通过不同的渠道(例如:Email、Slack、Grafna、Webhook)发送给指定通知方。

启动 OpenShift GitOps 的 Notification 功能

  1. 执行以下命令,启动 Notification 功能。
$ oc patch argocd openshift-gitops -n openshift-gitops --type merge --patch '{"spec": {"notifications": {"enabled": true}}}'
  1. 完成后可以查看 openshift-gitops 拓扑中会新增名为 openshift-gitops-notification-controller 的部署。
    在这里插入图片描述
  2. 执行以下命令,确认 GitOps Operator 已经自动创建 NotificationsConfiguration 对象。而和通知相关的对象还有 argocd-notifications-cm 和 argocd-notifications-secret。
$ oc get notificationsconfiguration -n openshift-gitops
NAME                                  AGE
default-notifications-configuration   21m
 
$ oc get cm argocd-notifications-cm -n openshift-gitops
NAME                      DATA   AGE
argocd-notifications-cm   16     35m
 
$ oc get secret argocd-notifications-secret -n openshift-gitops
NAME                          TYPE     DATA   AGE
argocd-notifications-secret   Opaque   0      37m
  1. argocd-notifications-cm 中是触发通知的 trigger 和通知内的 template。由于 argocd-notifications-cm 是由 NotificationsConfiguration CRD 生成的,因此无法直接修改 argocd-notifications-cm,而只能修改 NotificationsConfiguration。
    在这里插入图片描述

配置邮件通知

  1. 创建将在邮件 serveice 中使用的 Secret。
$ oc apply -n argocd -f - << EOF
apiVersion: v1
kind: Secret
metadata:
  name: argocd-notifications-secret
stringData:
  email-username: xxx@gmail.com
  email-password: xxxxxxxxxxxxx
type: Opaque
EOF
  1. 在 default-notifications-configuration 对象中增加以下 services 的内容,通过该邮件 serveice 发送通知邮件。
apiVersion: argoproj.io/v1alpha1
kind: NotificationsConfiguration
  name: default-notifications-configuration
  namespace: openshift-gitops
spec:
  services:
    service.email.gmail: |
      host: smtp.gmail.com
      port: 465
      username: $email-username
      password: $email-password
      from: $email-username
。。。
  1. 向 spring-petclinic 的 ArgoCD 应用添加注释,注释内容为 notifications.argoproj.io/subscribe.<trigger>.<service>: <recipient>,其定义了该应用接收 ArgoCD 的 trigger 类型(即 subscribe.on-sync-succeeded),使用的发送 service (即 gmail)和邮件的接受者(即 user@sina.com;user@sohu.com)。
$ oc annotate application spring-petclinic -n openshift-gitops notifications.argoproj.io/subscribe.on-sync-succeeded.gmail='user@sina.com;user@sohu.com'

验证

  1. 进入 spring-petclinic 应用用到的 Git Repo,调整 openshift-gitops-getting-started/app/deployment.yaml 文件的 replicas。
  2. 确认 ArgoCD 可以自动更新最新的 deployment。
  3. 确认可以收到邮件。
    在这里插入图片描述

参考

https://blog.argoproj.io/notifications-for-argo-bb7338231604
https://github.com/redhat-developer/gitops-operator/blob/master/docs/OpenShift%20GitOps%20Usage%20Guide.md
https://developers.redhat.com/articles/2023/01/17/how-openshift-gitops-notifications-can-trigger-pipelines
https://argo-cd.readthedocs.io/en/stable/operator-manual/notifications/
https://argo-cd.readthedocs.io/en/latest/operator-manual/notifications/subscriptions/
https://github.com/argoproj/argo-cd/discussions/9655
https://wearenotch.com/email-notifications-and-github-webhooks-with-argo-cd/

相关推荐

  1. spring boot admin服务端配置邮件通知、钉钉通知

    2024-04-03 10:40:05       12 阅读
  2. SpringBootAdmin设置邮件通知

    2024-04-03 10:40:05       34 阅读
  3. 如何 Git 配置邮箱地址

    2024-04-03 10:40:05       20 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-03 10:40:05       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-03 10:40:05       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-03 10:40:05       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-03 10:40:05       18 阅读

热门阅读

  1. Python访问mysql与sqlite3数据库

    2024-04-03 10:40:05       18 阅读
  2. Mysql函数

    2024-04-03 10:40:05       15 阅读
  3. Android Studio 通过 WIFI 调试手机 app

    2024-04-03 10:40:05       16 阅读
  4. leetcode2810--故障键盘

    2024-04-03 10:40:05       18 阅读
  5. CSS基础语法-黑马跟课笔记-供记录与查询

    2024-04-03 10:40:05       14 阅读
  6. PyTorch学习之:深入理解神经网络

    2024-04-03 10:40:05       11 阅读