본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Webhook 알림 서비스

원문 보기 위키 갱신

Webhook 알림 서비스는 템플릿화된 요청 본문과 URL로 일반적인 HTTP 요청을 보낼 수 있게 해줍니다. Webhook을 사용해 Jenkins 작업을 트리거하거나 GitHub 커밋 상태를 업데이트할 수 있습니다. 파라미터, 재시도 동작, 구성 단계, 예시를 정리해 볼게요.

출처: Argo Rollouts 문서

본문

Webhook 알림 서비스는 템플릿화된 요청 본문과 URL을 사용해 일반적인 HTTP 요청을 보낼 수 있게 해줍니다. Webhook을 사용하면 Jenkins 작업을 트리거하거나 GitHub 커밋 상태를 업데이트할 수 있습니다.

파라미터 (Parameters)

Webhook 알림 서비스 구성에는 다음 설정이 포함됩니다:

  • url - webhook을 보낼 URL입니다.
  • headers - 선택 사항으로, webhook과 함께 전달할 헤더입니다.
  • basicAuth - 선택 사항으로, webhook과 함께 전달할 기본 인증 정보입니다.
  • insecureSkipVerify - 선택 사항 bool 값이며 true 또는 false입니다.
  • retryWaitMin - 선택 사항으로, 재시도 사이의 최소 대기 시간입니다. 기본값: 1s.
  • retryWaitMax - 선택 사항으로, 재시도 사이의 최대 대기 시간입니다. 기본값: 5s.
  • retryMax - 선택 사항으로, 최대 재시도 횟수입니다. 기본값: 3.
  • maxIdleConns - 선택 사항으로, 모든 호스트에 걸친 최대 유휴(keep-alive) 연결 수입니다.
  • maxIdleConnsPerHost - 선택 사항으로, 호스트당 최대 유휴(keep-alive) 연결 수입니다.
  • maxConnsPerHost - 선택 사항으로, 호스트당 최대 총 연결 수입니다.
  • idleConnTimeout - 선택 사항으로, 유휴(keep-alive) 연결이 닫히기 전에 열려 있는 최대 시간입니다(예: '90s').

재시도 동작 (Retry Behavior)

webhook 서비스는 네트워크 오류나 서버가 5xx 상태 코드를 반환할 때 요청을 자동으로 재시도합니다. 재시도 횟수와 재시도 사이의 대기 시간은 retryMax, retryWaitMin, retryWaitMax 파라미터로 구성할 수 있습니다.

재시도 사이의 대기 시간은 retryWaitMin과 retryWaitMax 사이입니다. 모든 재시도가 실패하면 Send 메서드는 오류를 반환합니다.

구성 (Configuration)

다음 단계로 webhook을 구성합니다:

  1. argo-rollouts-notification-configmap ConfigMap에 webhook을 등록합니다:
apiVersion: v1
kind: ConfigMap
metadata:
  name: argo-rollouts-notification-configmap
data:
  service.webhook.<webhook-name>: |
    url: https://<hostname>/<optional-path>
    headers: #optional headers
    - name: <header-name>
      value: <header-value>
    basicAuth: #optional username password
      username: <username>
      password: <api-key>
    insecureSkipVerify: true #optional bool
  1. webhook 요청 메서드, 경로, 본문을 커스터마이즈하는 템플릿을 정의합니다:
apiVersion: v1
kind: ConfigMap
metadata:
  name: argo-rollouts-notification-configmap
data:
  template.github-commit-status: |
    webhook:
      <webhook-name>:
        method: POST # one of: GET, POST, PUT, PATCH. Default value: GET 
        path: <optional-path-template>
        body: |
          <optional-body-template>
  trigger.<trigger-name>: |
    - when: app.status.operationState.phase in ['Succeeded']
      send: [github-commit-status]
  1. webhook 통합을 위한 구독(subscription)을 생성합니다:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  annotations:
    notifications.argoproj.io/subscribe.<trigger-name>.<webhook-name>: ""
  • TLS 구성 (선택 사항) webhook 서버가 커스텀 TLS 인증서를 사용한다면, 아래와 같이 argocd-tls-certs-cm ConfigMap에 인증서를 추가해 알림 서비스가 이를 신뢰하도록 구성할 수 있습니다:
apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-tls-certs-cm
data:
  <hostname>: |
    -----BEGIN CERTIFICATE-----
    <TLS DATA>
    -----END CERTIFICATE-----

참고 (NOTE): 커스텀 인증서를 신뢰하지 않으면 Put \"https://...\": x509: certificate signed by unknown authority 같은 오류가 발생할 수 있습니다. 서버의 인증서를 argocd-tls-certs-cm에 추가하면 이 문제가 해결됩니다.

예시 (Examples)

GitHub 커밋 상태 설정 (Set GitHub commit status)

apiVersion: v1
kind: ConfigMap
metadata:
  name: argo-rollouts-notification-configmap
data:
  service.webhook.github: |
    url: https://api.github.com
    headers: #optional headers
    - name: Authorization
      value: token $github-token
  1. webhook 요청 메서드, 경로, 본문을 커스터마이즈하는 템플릿을 정의합니다:
apiVersion: v1
kind: ConfigMap
metadata:
  name: argo-rollouts-notification-configmap
data:
  service.webhook.github: |
    url: https://api.github.com
    headers: #optional headers
    - name: Authorization
      value: token $github-token

  template.github-commit-status: |
    webhook:
      github:
        method: POST
        path: /repos/{{call .repo.FullNameByRepoURL .app.spec.source.repoURL}}/statuses/{{.app.status.operationState.operation.sync.revision}}
        body: |
          {
            {{if eq .app.status.operationState.phase "Running"}} "state": "pending"{{end}}
            {{if eq .app.status.operationState.phase "Succeeded"}} "state": "success"{{end}}
            {{if eq .app.status.operationState.phase "Error"}} "state": "error"{{end}}
            {{if eq .app.status.operationState.phase "Failed"}} "state": "error"{{end}},
            "description": "ArgoCD",
            "target_url": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
            "context": "continuous-delivery/{{.app.metadata.name}}"
          }

Jenkins 작업 시작 (Start Jenkins Job)

apiVersion: v1
kind: ConfigMap
metadata:
  name: argo-rollouts-notification-configmap
data:
  service.webhook.jenkins: |
    url: http://<jenkins-host>/job/<job-name>/build?token=<job-secret>
    basicAuth:
      username: <username>
      password: <api-key>

type: Opaque

form-data 전송 (Send form-data)

apiVersion: v1
kind: ConfigMap
metadata:
  name: argo-rollouts-notification-configmap
data:
  service.webhook.form: |
    url: https://form.example.com
    headers:
    - name: Content-Type
      value: application/x-www-form-urlencoded

  template.form-data: |
    webhook:
      form:
        method: POST
        body: key1=value1&key2=value2

Slack 전송 (Send Slack)

apiVersion: v1
kind: ConfigMap
metadata:
  name: argo-rollouts-notification-configmap
data:
  service.webhook.slack_webhook: |
    url: https://hooks.slack.com/services/xxxxx
    headers:
    - name: Content-Type
      value: application/json

  template.send-slack: |
    webhook:
      slack_webhook:
        method: POST
        body: |
          {
            "attachments": [{
              "title": "{{.app.metadata.name}}",
              "title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
              "color": "#18be52",
              "fields": [{
                "title": "Sync Status",
                "value": "{{.app.status.sync.status}}",
                "short": true
              }, {
                "title": "Repository",
                "value": "{{.app.spec.source.repoURL}}",
                "short": true
              }]
            }]
          }

더 알아보기 (Learn more)

  • Argo Rollouts 알림(Notifications) 시스템 이해하기
  • 트리거(trigger) 조건 작성법
  • 다른 알림 서비스(pagerduty, gcppubsub) 구성
  • 템플릿 변수(template variable) 활용법