GitOps - 为 OpenShift GitOps 配置邮件通知

89 篇文章 3 订阅
13 篇文章 1 订阅

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/

  • 12
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值