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

익스큐터 플러그인 (Executor Plugins)

원문 보기 위키 갱신

Executor Plugin은 워크플로 실행 도중에 커스텀 로직을 수행하는 HTTP 서버 기반 확장이에요. 이 문서에서는 플러그인 활성화 방법과, 실제 동작하는 간단한 Python 플러그인을 만드는 과정을 단계별로 안내합니다.

출처: Argo Workflows 문서

본문

설정(Configuration)

Executor Plugin은 기본적으로 비활성화되어 있어요. Workflow Controller ConfigMap을 통해 전역으로 활성화하거나, 워크플로별로 활성화할 수 있습니다. 해당하는 플래그를 사용해서 켜세요:

  • ARGO_EXECUTOR_PLUGINS=true는 컨트롤러 ConfigMap에 전역으로 정의된 Executor Plugin의 사용을 활성화합니다.
  • ARGO_WORKFLOW_LEVEL_EXECUTOR_PLUGINS=true는 워크플로 스펙에 직접 지정된 Executor Plugin 설정의 사용을 허용합니다. 이 설정은 전역 설정보다 우선합니다.

이 두 옵션은 서로 독립적이에요. 전역 플러그인만 켜거나, 워크플로 레벨 플러그인만 켜거나, 둘 다 동시에 켤 수도 있습니다.

워크플로 레벨 executor 플러그인 예제는 workflow-level-executor-plugin.yaml을 참고하세요.

예를 들어 Workflow Controller 디플로이먼트에서 두 모드를 모두 활성화하려면:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: workflow-controller
spec:
  template:
    spec:
      containers:
        - name: workflow-controller
          env:
            - name: ARGO_EXECUTOR_PLUGINS
              value: "true"
            - name: ARGO_WORKFLOW_LEVEL_EXECUTOR_PLUGINS
              value: "true"

Helm 차트를 사용한다면 values.yaml에 다음을 추가하세요:

controller:
  extraEnv:
    - name: ARGO_EXECUTOR_PLUGINS
      value: "true"
    - name: ARGO_WORKFLOW_LEVEL_EXECUTOR_PLUGINS
      value: "true"

예제: 간단한 Python 플러그인

워크플로가 조작될 때마다 "hello"를 출력하는 Python Executor Plugin을 만들어 볼게요.

필요한 것은 다음과 같습니다:

  1. Workflow Controller에서 Executor Plugin 활성화(configuration 참고).
  2. Agent Pod를 실행하고 관리하기 위한 추가 RBAC 권한.
  3. main 컨테이너의 사이드카로 실행되어 executor의 RPC HTTP 요청에 이 API 계약에 따라 응답하는 HTTP 서버.
  4. plugin.yaml 설정 파일. ConfigMap으로 변환되어 컨트롤러가 플러그인을 발견(discover)할 수 있게 해 줍니다.

템플릿 Executor Plugin은 /api/v1/template.execute로 HTTP POST 요청을 서비스합니다:

curl http://localhost:4355/api/v1/template.execute -d \
'{
  "workflow": {
    "metadata": {
      "name": "my-wf"
    }
  },
  "template": {
    "name": "my-tmpl",
    "inputs": {},
    "outputs": {},
    "plugin": {
      "hello": {}
    }
  }
}'
# ...
HTTP/1.1 200 OK
{
  "node": {
    "phase": "Succeeded",
    "message": "Hello template!"
  }
}

팁: 포트 번호는 아무 것이나 되지만, 다른 Executor Plugin과 충돌해서는 안 돼요. 80, 443, 8080, 8081, 8443 같은 흔한 포트는 쓰지 마세요. 플러그인을 공개 출판할 계획이라면 10000 미만의 임의 포트 번호를 골라서 플러그인 추가 PR을 만드세요. 그렇지 않다면 10000보다 큰 포트 번호를 사용하세요.

HTTP 서버를 시작하는 스크립트를 만들어야 해요. 다음을 server.py로 저장하세요:

import json
from http.server import BaseHTTPRequestHandler, HTTPServer

with open("/var/run/argo/token") as f:
    token = f.read().strip()


class Plugin(BaseHTTPRequestHandler):

    def args(self):
        return json.loads(self.rfile.read(int(self.headers.get('Content-Length'))))

    def reply(self, reply):
        self.send_response(200)
        self.end_headers()
        self.wfile.write(json.dumps(reply).encode("UTF-8"))

    def forbidden(self):
        self.send_response(403)
        self.end_headers()

    def unsupported(self):
        self.send_response(404)
        self.end_headers()

    def do_POST(self):
        if self.headers.get("Authorization") != "Bearer " + token:
            self.forbidden()
        elif self.path == '/api/v1/template.execute':
            args = self.args()
            if 'hello' in args['template'].get('plugin', {}):
                self.reply(
                    {'node': {'phase': 'Succeeded', 'message': 'Hello template!',
                              'outputs': {'parameters': [{'name': 'foo', 'value': 'bar'}]}}})
            else:
                self.reply({})
        else:
            self.unsupported()


if __name__ == '__main__':
    httpd = HTTPServer(('', 4355), Plugin)
    httpd.serve_forever()

팁: Executor Plugin은 컨테이너로 실행할 수 있는 어떤 언어로든 작성할 수 있어요. Python이 편한 이유는 스크립트를 컨테이너에 포함(embed)시킬 수 있기 때문입니다.

여기서 짚어 둘 점들:

  • 필요한 호출만 구현하면 돼요. 404를 반환하면 다시 호출되지 않습니다.
  • 경로(path)가 곧 RPC 메서드 이름이에요.
  • Authorization 헤더가 /var/run/argo/token과 같은 값을 담고 있는지 확인해야 합니다. 아니면 403을 반환하세요.
  • 요청 본문에는 템플릿의 입력 파라미터가 담겨 있어요.
  • 응답 본문에는 노드의 결과가 담길 수 있습니다. 페이즈(phase, 예: "Succeeded" 또는 "Failed")와 메시지를 포함해서요.
  • 응답이 {}라면, Executor Plugin이 해당 Plugin 템플릿을 실행할 수 없다고 말하는 것입니다. 예를 들어 Slack Plugin인데 템플릿은 Tekton job인 경우죠.
  • 상태 코드가 404라면 Executor Plugin은 다시 호출되지 않아요.
  • 파일을 server.*로 저장하면 사이드카 컨테이너의 args 필드로 복사됩니다. 이 덕분에 Python이나 Node.JS 같은 스크립팅 언어로 자기완결적인(self-contained) Executor Plugin을 만들기가 쉬워요.

다음으로 plugin.yaml이라는 매니페스트를 만드세요:

apiVersion: argoproj.io/v1alpha1
kind: ExecutorPlugin
metadata:
  name: hello
spec:
  sidecar:
    container:
      command:
        - python
        - -u # disables output buffering
        - -c
      image: python:alpine3.23
      name: hello-executor-plugin
      ports:
        - containerPort: 4355
      securityContext:
        runAsNonRoot: true
        runAsUser: 65534 # nobody
      resources:
        requests:
          memory: "64Mi"
          cpu: "250m"
        limits:
          memory: "128Mi"
          cpu: "500m"

다음과 같이 빌드하고 설치하세요:

argo executor-plugin build .
kubectl -n argo apply -f hello-executor-plugin-configmap.yaml

컨트롤러 로그를 확인해 보세요:

level=info msg="Executor plugin added" name=hello-controller-plugin

이 워크플로를 실행해 보세요.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: hello-
spec:
  entrypoint: main
  templates:
    - name: main
      plugin:
        hello: { }

워크플로가 성공적으로 완료되는 걸 볼 수 있을 거예요.

발견(Discovery)

워크플로가 실행되면 Executor Plugin은 다음 위치에서 로드됩니다:

  • 워크플로의 네임스페이스.
  • Argo 설치 네임스페이스(보통 argo).

두 Executor Plugin의 이름이 같다면, 워크플로의 네임스페이스에 있는 것만 로드돼요.

시크릿(Secrets)

서드파티 시스템과 상호작용한다면 시크릿 접근이 필요할 거예요. plugin.yaml에 넣지 마세요. 시크릿을 사용하세요:

spec:
  sidecar:
    container:
      env:
        - name: URL
          valueFrom:
            secretKeyRef:
              name: slack-executor-plugin
              key: URL

시크릿 모범 사례와 보안 고려 사항은 Kubernetes Secret 문서를 참고하세요.

리소스, 시큐리티 컨텍스트(Resources, Security Context)

이 항목들을 필수로 만든 이유는, 누구도 비합리적으로 많은 메모리를 쓰는 Executor Plugin을 만들거나 의도하지 않는 한 root로 실행되지 않도록 하기 위해서예요:

spec:
  sidecar:
    container:
      resources:
        requests:
          cpu: 100m
          memory: 32Mi
        limits:
          cpu: 200m
          memory: 64Mi
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000

실패(Failure)

Executor Plugin은 다음과 같이 실패할 수 있습니다:

  • 연결/소켓 에러 - 일시적(transient)으로 간주됩니다.
  • 타임아웃 - 일시적으로 간주돼요.
  • 404 에러 - Executor Plugin이 지원하지 않는 메서드라는 뜻이며, 그 결과 그 메서드는 (같은 워크플로 내에서) 다시 호출되지 않습니다.
  • 503 에러 - 일시적으로 간주돼요.
  • 그 외의 4xx/5xx 에러 - 치명적(fatal)으로 간주됩니다.

일시적 에러는 재시도되고, 그 외의 모든 에러는 치명적으로 취급돼요.

치명적 에러는 스텝 실패로 이어집니다.

재큐(Re-Queue)

Executor Plugin이 곧바로 끝내지 못할 수도 있어요. 예를 들어 오래 걸리는 태스크를 시작한 경우죠. 그럴 때는 "Pending"이나 "Running"과 재큐 시간을 반환합니다:

{
  "node": {
    "phase": "Running",
    "message": "Long-running task started"
  },
  "requeue": "2m"
}

이 예제에서는 태스크가 재큐되고, 2분 뒤에 template.execute가 다시 호출돼요.

디버깅(Debugging)

Executor Plugin의 로그는 Agent Pod의 사이드카에서 찾을 수 있어요. 예를 들면:

kubectl -n argo logs ${agentPodName} -c hello-executor-plugin

Executor Plugin 나열하기

Executor Plugin은 그저 ConfigMap일 뿐이므로, kubectl로 나열할 수 있어요:

kubectl get cm -l workflows.argoproj.io/configmap-type=ExecutorPlugin

예제 및 커뮤니티 기여 Executor Plugin

플러그인 디렉터리

여러분의 Executor Plugin 출판하기

여러분의 Executor Plugin을 출판하고 공유하고 싶다면(꼭 그러길 바라요!), 위의 디렉터리에 추가하는 Pull Request를 제출하세요.

더 알아보기 (Learn more)

  • Executor Plugin은 컨테이너로 실행할 수 있는 어떤 언어로든 만들 수 있지만, server.* 파일을 사이드카에 자동 복사해 주는 스크립팅 언어가 가장 간편해요.
  • 일시적 에러(연결 오류, 타임아웃, 503)는 재시도되고 404는 재호출되지 않으며, 나머지 4xx/5xx는 치명적으로 취급됩니다.
  • 플러그인을 공개할 계획이라면 10000 미만의 포트를 골라 플러그인 디렉터리에 추가하는 PR을 제출하세요.