2.5. NotificationsConfiguration カスタムリソースプロパティー
NotificationsConfiguration リソースは、Kubernetes クラスター内の通知を管理する Kubernetes カスタムリソース (CR) です。Red Hat OpenShift GitOps では、NotificationsConfiguration CR を使用して、テンプレート、トリガー、サービス、サブスクリプションリソースを Argo CD Notifications config map に追加できます。
通知を有効にして Red Hat OpenShift GitOps でクラスターを作成すると、デフォルトで default-notifications-configuration という名前の NotificationsConfiguration CR が作成されます。
NotificationsConfiguration CR の既存の設定に加えられた変更は、Argo CD Notifications config map に複製されます。たとえば、ユーザーが NotificationsConfiguration リソースにトリガー設定を追加すると、この設定は Argo CD Notifications config map 内で読み取られ、処理され、更新されます。
設定の変更はすべて、default-notifications-configuration CR で更新する必要があります。NotificationsConfiguration リソース用にユーザーが作成したカスタムリソースはサポートされていません。
Argo CD argocd-notifications-cm config map への変更は、NotificationsConfiguration CR で行われた変更によって上書きされます。
| Properties | Default | 説明 |
|---|---|---|
| テンプレート |
| テンプレートは、通知テンプレートメッセージを生成するために使用されます。 |
| トリガー |
| トリガーは、ユーザーに通知が送信される条件と、メッセージを生成するために必要なテンプレートのリストを定義するために使用されます。 |
| サービス |
| サービスはメッセージを配信するために使用されます。 |
| サブスクリプション |
| サブスクリプションには、集中管理されたグローバルアプリケーションサブスクリプションが含まれます。 |
次の例では、default-notifications-configuration カスタムリソースを使用して、テンプレート、トリガー、サービス、およびサブスクリプションリソースを Argo CD argocd-notification-cm config map に追加する方法を定義します。
templates の例
apiVersion: argoproj.io/v1alpha1
kind: NotificationsConfiguration
metadata:
name: default-notifications-configuration
spec:
templates:
template.my-custom-template: |
message: |
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
triggers の例
apiVersion: argoproj.io/v1alpha1
kind: NotificationsConfiguration
metadata:
name: default-notifications-configuration
spec:
triggers:
trigger.on-sync-status-unknown: |
- when: app.status.sync.status == 'Unknown'
send: [my-custom-template]
services の例
apiVersion: argoproj.io/v1alpha1
kind: NotificationsConfiguration
metadata:
name: default-notifications-configuration
spec:
services:
service.slack: |
token: $slack-token
username: <override-username> # optional username
icon: <override-icon> # optional icon for the message (supports both emoji and url notation)
subscriptions の例
apiVersion: argoproj.io/v1alpha1
kind: NotificationsConfiguration
metadata:
name: default-notifications-configuration
spec:
subscriptions:
subscriptions: |
# subscription for on-sync-status-unknown trigger notifications
- recipients:
- slack:test2
- email:test@gmail.com
triggers:
- on-sync-status-unknown
# subscription restricted to applications with matching labels only
- recipients:
- slack:test3
selector: test=true
triggers:
- on-sync-status-unknown
OpenShift Container Platform Web コンソールまたは CLI (oc) を使用して NotificationsConfiguration CR を設定できます。
2.5.1. Web コンソールを使用した NotificationsConfiguration CR の設定 リンクのコピーリンクがクリップボードにコピーされました!
Web コンソールを使用して、NotificationsConfiguration カスタムリソース (CR) を設定できます。
前提条件
-
cluster-admin権限で OpenShift Container Platform クラスターにアクセスでき、Web コンソールにログインしている。 - Red Hat OpenShift GitOps Operator がクラスターにインストールされている。
- Argo CD インスタンスの通知が有効になっている。詳細は、「Argo CD インスタンスでの通知の有効化」を参照してください。
手順
-
OpenShift Container Platform Web コンソールの Administrator パースペクティブで、Operators
Installed Operators を展開します。 - Installed Operators のリストから Red Hat OpenShift GitOps Operator を選択し、NotificationsConfiguration タブをクリックします。
-
NotificationsConfigurations ページで、
default-notifications-configurationをクリックします。 default-notifications-configuration ページで、YAML をクリックし、
templates、triggers、services、subscriptionsなどのサポートされているリソースの設定を追加します。たとえば、コード内のtemplatesの下に、次のサンプル設定を追加します。テンプレート設定の例
template.my-custom-template: | message: | Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.- Save をクリックします。
NotificationsConfigurationCR で行われた設定変更がargocd-notifications-cmconfig map に反映されていることを確認します。-
Workloads
ConfigMaps に移動します。 - argocd-notifications-cm をクリックし、YAML タブを選択します。
- YAML タブのページをスクロールして、サポートされているリソースに追加されたサンプル設定を確認します。
-
Workloads
2.5.2. CLI を使用した NotificationsConfiguration CR の設定 リンクのコピーリンクがクリップボードにコピーされました!
CLI (oc) を使用して NotificationsConfiguration カスタムリソース (CR) を設定できます。
前提条件
-
cluster-admin権限を使用して OpenShift Container Platform クラスターにアクセスできる。 - Red Hat OpenShift GitOps Operator がクラスターにインストールされている。
- Argo CD インスタンスの通知が有効になっている。詳細は、「Argo CD インスタンスでの通知の有効化」を参照してください。
手順
次のコマンドを実行して、クラスター内のデフォルトの
NotificationsConfigurationCR を編集します。$ oc edit notificationsconfiguration default-notifications-configuration -n <namespace>ここでは、以下のようになります。
default-notifications-configuration-
デフォルトの
NotificationsConfigurationCR の名前を指定します。 <namespace>- namespace の名前を指定します。
CR の
templatesセクションで、次の例のような設定を追加します。テンプレート設定の例
template.my-custom-template: | message: | Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.次のコマンドを実行して、
argocd-notifications-cmconfig map の内容を確認します。$ oc edit cm argocd-notifications-cm -n <namespace>NotificationsConfigurationCR の既存の設定に加えられた変更は、argocd-notifications-cmconfig map に反映されます。