본문 바로가기

개발관련

Argo CD Notification

반응형

Overview

Argo CD에서 Slack 혹은 Email로 Notification 작업을 할 수 있는 라이브러리를 스터디한다.

선행 작업 :

  • 쿠버네티스 클러스터가 구성되어있어야 한다.
  • 쿠버네티스 클러스터에 Argo CD가 세팅되어 있어야 한다.

순서(요약) :

 

    • Slack App 생성
      • 링크 : https://api.slack.fom/apps?new_app=1 
      • App 생성
      • 왼쪽 메뉴에서 OAuth & Permissions 들어가기
      • Scope 설정(chat:write:bot)
      • Slack App Install
      • OAuth token 확인
    • k8s 클러스터에 아래 명령어를 통해 notification에 필요한 manifest 적용
    • kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-notifications/stable/manifests/install.yaml
    • 아래 명령어를 통해 secret 내용 변경
    • kubectl apply -f - << EOF apiVersion: v1 kind: Secret metadata: name: argocd-notifications-secret stringData: notifiers.yaml: | slack: token: <위에서 생성했던 Slack app의 OAuth token 입력> type: Opaque EOF
    • Argo CD Sync 시 알림 오도록 설정하기 위해 아래 명령어를 통해 ConfigMap 내용 변경
    • kubectl apply -f - << EOF apiVersion: v1 kind: ConfigMap metadata: name: argocd-notifications-cm data: config.yaml: | triggers: - name: on-sync-succeeded enabled: true EOF
    • argo cd notification을 적용하기 위해 적용할 argo cd app 조회
    • $ kubectl get app -n argocd NAME AGE test-app 1h ...
    • 아래 명령어를 통해 test-app에 argo cd notification 적용을 위한 annotation 추가
    • kubectl patch app test-app -n argocd -p '{"metadata":{"annotations":{"recipients.argocd-notifications.argoproj.io":"slack:<내 슬랙 채널명>"}}}' --type merge

 


Slack App 생성

우선 https://api.slack.com/apps?new_app=1 에 접속한다.

그럼 아래와 같은 화면을 볼 수 있다.

 

 

 

Argo CD전용 Slack App을 생성하기 위해 'Create New App' 버튼을 클릭한다.

버튼을 클릭하면 아래와 같은 창을 볼 수 있다.

 

 

 

 

'App Name'에는 생성하려는 App의 이름을 입력한다. 추후 변경하고 싶다면 변경할 수 있으니 걱정하지 않아도 된다.

'Development Slack Workspace'에는 Slack App을 세팅할 Slack Workspace를 지정한다.

필자는 아래와 같이 세팅하였다.

 

 

 

 

모두 정확히 입력했다면, 'Create App' 버튼을 클릭하여 Slack App을 생성한다.

 

Slack App을 생성하고나면 아래 화면과 같이 리다이렉트 된다.

이 화면에서 왼쪽 메뉴바에 위치해있는 'OAuth & Permissions' 메뉴를 클릭한다.

 

 

 

페이지가 이동되면 스크롤을 좀 내려본다.

내리다보면 Scopes가 있는데 여기서 Slack App의 OAuth Token을 통해 어떤 권한을 사용할 수 있게 할건지 결정할 수 있다.

 

 

 

OAuth Token의 권한 설정을 위해 'Add an OAuth Scope' 버튼을 클릭한다.

우리는 특정 Slack 채널에 notification을 위한 역할을 하는 App을 만들 것이므로 chat:write:bot 이라는 권한을 선택한다.

 

 

chat:write:bot은 Slack Workspace에 bot 계정을 생성해서 이 bot 계정을 통해 Slack 채널에 메시지를 입력할 수 있게끔 권한을 부여하는 것이다.

이제 다시 스크롤을 맨 위로 올려보면 'Install App to Workspace' 버튼이 초록색으로 변해서 클릭할 수 있도록 활성화 된 것을 볼 수 있다.

 

 

'Install App to Workspace' 버튼을 클릭하면 아래 화면을 볼 수 있다.

 

 

Slack 채널에 우리의 App을 설치하는 것이다.

우리가 부여한 권한이 맞는지 확인한 후 'Allow' 버튼을 클릭한다.

 

Slack App을 설치하면 아래와 같이 OAuth Access Token을 확인할 수 있다.

 

이 Token은 추후에 Argo CD Notification의 Secret에 사용될 것이다.

 

 


쿠버네티스 클러스터에 Argo CD Notification 설정

설정은 아래 문서를 참고하여 따라한다.

Argo CD Notifications

 

Argo CD Notifications

 Overview Argo CD Notifications continuously monitors Argo CD applications and provides a flexible way to notify users about important changes in the application state. Using flexible mechanism of triggers and templates you can configure when the notifica

argoproj-labs.github.io

 

먼저 클러스터에 아래 명령어를 통해 Argo CD Notification에 필요한 manifest들을 적용한다.

$ kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-notifications/stable/manifests/install.yaml

 

 

그 다음, security manifest 내용을 수정해주기 위해 아래 명령어를 실행한다.

여기서 우리가 만들었던 Slack App의 token을 사용한다.

kubectl apply -f - << EOF
apiVersion: v1
kind: Secret
metadata:
  name: argocd-notifications-secret
stringData:
  notifiers.yaml: |
    slack:
      token: xoxp-blah-blah-lorem-ipsum-foo-bar
type: Opaque
EOF

 

그리고 Argo CD의 Sync 성공을 트리거로 잡아서 Slack 채널에 알림을 주기 위해 아래 명령어를 통해 ConfigMap manifest 내용을 수정해준다.

kubectl apply -f - << EOF
apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
data:
  config.yaml: |
    triggers:
      - name: on-sync-succeeded
        enabled: true
EOF

 

 

마지막으로 Argo CD로 배포한 어플리케이션 중에서 notification을 적용할 어플리케이션의 manifest 내용에 metadata를 수정해주어야한다.

notification을 적용할 어플리케이션을 찾으려면 아래 명령어를 통해 가능하다.

$ kubectl get app -n argocd
NAME                     AGE
test-app                  1h
...

 

 

명령어를 통해 test-app이라는 어플리케이션을 찾았다.

이 어플리케이션에 argo cd notification을 적용해보자.

아래 명령어를 실행한다. 알림을 전달할 Slack 채널은 general으로 지정하겠다.

kubectl patch app test-app -n argocd -p '{"metadata":{"annotations":{"recipients.argocd-notifications.argoproj.io":"slack:general"}}}' --type merge

 

 


Notification 동작 확인

자 이제 test-app을 Sync하여 실제 Slack의 general 채널에 알림이 오는지 확인해보자.

 

Sync를 하면 아래와 같이 우리가 생성했던 Slack App이 알림을 보내주는것을 확인할 수 있다.

 

 

 


참고

Argo CD Notifications

I have a question about setting up slack in argocd-notifications-secret's notifiers.yaml. · Issue #11 · argoproj-labs/argocd-notifications

반응형