-
[ArgoCD] 작업내용 슬랙 알림DevOps/ArgoCD 2023. 10. 31. 14:56
1. 슬랙에서 앱 설정
공식 문서
https://argo-cd.readthedocs.io/en/stable/operator-manual/notifications/services/slack/
Slack - Argo CD - Declarative GitOps CD for Kubernetes
Slack If you want to send message using incoming webhook, you can use webhook. Parameters The Slack notification service configuration includes following settings: token - the app token apiURL - optional, the server url, e.g. https://example.com/api userna
argo-cd.readthedocs.io
https://api.slack.com/apps?new_app=1
Slack API: Applications | Slack
Your Apps Don't see an app you're looking for? Sign in to another workspace.
api.slack.com
위 링크로 앱 생성 페이지 이동 -> Create an app -> From scratch

Create App 생성 1 App Name : 앱이름 설정
Pick a workspace to develop your app in : 워크 스페이스 선택
작성 후 Create App 클릭

Create App 생성 2 작성 완료되면 자동으로 앱 Basic Information화면으로 이동됨
좌측 네비게이션 페이지 -> OAuth & Permissions 클릭

앱생성후 이동된 페이지 하단에 Scopes 탭으로 이동 -> Add an OAuth Scope 클릭 -> chat:write, chat:write.customize 등록

scopes 설정 스크롤 상단으로 이동 -> Install App to Workspace 버튼 클릭

Install App to Workspace 클릭 Bot User OAuth Token 복사

OAuth 토큰 복사 슬랙 -> 워크스페이스 이동 -> 채널 생성

채널 생성 슬랙 -> 워크 스페이스 -> Apps에 ArgoCD -> ArgoCD 클릭 -> Add this app to a channel -> 메시지 전달 받을 채널 등록

채널에 앱 등록 2. argoCD 설정
Helm으로 설치했는데 이미 Notifications이 설치 되어있으므로 0번은 스킵한다.

notification 있는 경우 0. Notifications 설치
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-notifications/release-1.0/manifests/install.yaml1. trigger & template 설정
(argocd-notifications-cm에서 기본 트리거와 기본 템플릿 설정)
어떤트리거에 어떤식으로 알림이 날아갈지 포맷을 정하는 부분
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-notifications/release-1.0/catalog/install.yaml트리거 8가지 에대한 설명과 템플릿 형태
https://argo-cd.readthedocs.io/en/stable/operator-manual/notifications/catalog/#triggers
Triggers and Templates Catalog - Argo CD - Declarative GitOps CD for Kubernetes
on-deployed Application is synced and healthy. Triggered once per commit. app-deployed
argo-cd.readthedocs.io
템플릿 커스텀 미리 볼수있는 링크
https://app.slack.com/block-kit-builder/
Slack
nav.top { position: relative; } #page_contents > h1 { width: 920px; margin-right: auto; margin-left: auto; } h2, .align_margin { padding-left: 50px; } .card { width: 920px; margin: 0 auto; .card { width: 880px; } } .linux_col { display: none; } .platform_i
app.slack.com
slack-token : OAuth2 토큰 정보 붙여넣기
# k edit secret argocd-notifications-secret apiVersion: v1 kind: Secret metadata: name: <secret-name> stringData: slack-token: <Oauth-access-token>configMap에 토큰 정보 참조
# k edit configmap argocd-notifications-cm apiVersion: v1 kind: ConfigMap metadata: name: <config-map-name> data: service.slack: | token: $slack-tokenk get app 으로 arogoCD 앱 목록을 확인한다.

2. 앱 이름, 트리거, 채널 설정
kubectl patch app <my-app> -n argocd -p '{"metadata": {"annotations": {"notifications.argoproj.io/subscribe.on-sync-succeeded.slack":"<my-channel>"}}}' --type merge3. 앱에 알림 설정 여부 확인
반영이 되었는지 확인하는 방법 1 )
cli에서 확인

반영이 되었는지 확인하는 방법 2 )
argoCD -> Application -> App 선택 -> APP DETAILS -> SUMMARY -> EDIT 아래 정보 확인

3. 슬랙에서 알림 확인
실제로 어플리케이션 배포를 진행한다.

트리거를 sync success에만 걸었기때문에 성공알림만 받을 수 있다.

트러블 슈팅
알림이 오지않는 경우
1. argo-notificaion pod 로그를 확인한다.
2. 토큰을 재복사하여 붙여넣는다.
3. auth 오류나는경우 secret에 $token 참조 대신 configmap에 토큰값을 그대로 넣어본다.
4. auth 에러가 아닌 경우 pod log에 오류가 없는경우 트리거가 잘 설정 되었는지 확인해본다.