# Notification slack

{% embed url="<https://argocd-notifications.readthedocs.io/en/stable/>" %}

## slack 설정

<https://argocd-notifications.readthedocs.io/en/stable/services/slack/>

slack에서 add apps ==> app directory ==> build ==> create custom app

![](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-01.png)

![app directory](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-02.png)

![build](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-03.png)

![create custom app](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-04.png)

create an app from scratch

![create an app from scratch](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-05.png)

![create app](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-06.png)

oauth & permission

![](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-07%20\(1\)%20\(1\).png)

bot token scope ==> add an oauth scope ==>

![add an oauth scope](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-08.png)

chat:write추가

chat:write:customize는 메세지를 커스터 마이즈하려면 추가

Install App to Workspace

![](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-10.png)

allow

토큰이 생성이 되면 복사해둔다.

![](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-11.png)

argocd 채널에 application추가

채널에서 Add apps >> channel detail >> integration >> argocd-notifications

![Add apps](https://3379277180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MaoWGMVdC3ztoOAzHPq%2Fuploads%2Fgit-blob-37a5e473a51cc67048348da044da1effd44c85c2%2F2021-11-23-15-15-53.png?alt=media\&token=5ea24c57-6889-4a35-9158-5b5d5127968b)

![Add apps](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-12.png)

![Add apps](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/argocd-notifications-13.png)

## argocd에 설치하기

```bash
mkdir -p core/argocd-notifications
cd core/argocd-notifications
```

{% tabs %}
{% tab title="kustomization.yaml" %}

```yaml
apiVersion: kustomize.config.k8s.io/v1beta1

kind: Kustomization

resources:
  - https://raw.githubusercontent.com/argoproj-labs/argocd-notifications/v1.1.1/manifests/install.yaml

patches:
  - path: https://raw.githubusercontent.com/argoproj-labs/argocd-notifications/v1.1.1/catalog/install.yaml
    target:
      kind: ConfigMap
      name: argocd-notifications-cm
  - path: slack-secret.yml
    target:
      kind: Secret
      name: argocd-notifications-secret

patchesStrategicMerge:
  - slack-configmap.yml
```

{% endtab %}

{% tab title="slack-configmap.yml" %}

```yaml
apiVersion: v1
data:
  service.slack: |
    token: $slack-token
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
```

{% endtab %}

{% tab title="slack-secret.yml" %}

```yaml
apiVersion: v1
kind: Secret
metadata:
  name: argocd-notifications-secret
stringData:
  slack-token: YOUR-TOKEN
type: Opaque
```

{% endtab %}
{% endtabs %}

argocd에서 앱을 추가하자.

{% code title="add-apps/argocd-notifications.yml" %}

```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: argocd-notifications
spec:
  destination:
    name: ''
    namespace: argocd
    server: 'https://kubernetes.default.svc'
  source:
    path: apps/core/argocd-notifications
    repoURL: 'git@github.com:xxxxx/xxxx.git'
    targetRevision: HEAD
  project: default
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true
```

{% endcode %}

```bash
kubectl apply -f add-apps/argocd-notifications.yml
```

## subscribe trigger

### Application

Application에 annotations 을 추가해주면된다.

```bash
kubectl edit application AAA -n argocd
```

```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  # 여기만 추가
  annotations:
    notifications.argoproj.io/subscribe.on-sync-succeeded.slack: my_channel
```

이러면 알림을 받을수 있다.

### Project

Project 단위에 다 보내려면 프로젝트설정에 annotations 을 추가해주면 된다.

```bash
kubectl get AppProjects -n argocd
```

![](https://github.com/teamsmiley/gitbook/blob/master/kubernetes/.gitbook/assets/2021-06-03-06-03-20.png)

```bash
kubectl edit appProject default -n argocd
```

```yaml
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  # 여기만 추가
  annotations:
    notifications.argoproj.io/subscribe.on-sync-succeeded.slack: my-channel1;my-channel2
```

### command line으로

{% code title="trigger.yaml" %}

```yaml
metadata:
  annotations:
    notifications.argoproj.io/subscribe.on-sync-succeeded.slack: argocd
```

{% endcode %}

```bash
kubectl patch AppProjects default -n argocd --patch "$(cat trigger.yaml)" --type=merge
```
