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

Argo Rollouts 플러그인 만들기 (Creating an Argo Rollouts Plugin)

원문 보기 위키 갱신

Argo Rollouts 플러그인을 처음부터 만드는 방법을 설명해 드릴게요. hashicorp의 go-plugin 라이브러리 기반이어서 플러그인을 독립 실행 바이너리로 컴파일하고 컨트롤러가 런타임에 로드하는 구조예요. 플러그인 이름 규칙부터 인터페이스 구현까지 옆에서 차근차근 설명할게요.

출처: 문서

본문

높은 수준의 개요 (High Level Overview)

Argo Rollouts 플러그인은 hashicorp의 go-plugin 라이브러리에 의존해요. 이 라이브러리는 플러그인을 독립 실행 바이너리로 컴파일한 뒤 rollouts 컨트롤러가 런타임에 로드할 수 있게 해 줘요. 이는 플러그인 실행 파일이 rpc 서버 역할을 하고 rollouts 컨트롤러가 클라이언트 역할을 하는 방식으로 동작해요. 플러그인 실행 파일은 rollouts 컨트롤러가 시작하고, rollouts 컨트롤러가 unix 소켓으로 연결하는 장수명(long-lived) 프로세스예요.

플러그인이 로드되는 방식의 개요는 다음과 같아요:

통신 프로토콜은 golang 내장 net/rpc 라이브러리를 사용하므로 플러그인은 golang으로 작성해야 해요.

플러그인 리포지토리 (Plugin Repository)

메인 argo rollouts 문서에 플러그인을 등재하려면 플러그인 리포지토리가 argoproj-labs 조직 아래에 생성되기를 요청해요. argo-rollouts 아래에 issue를 열어서 리포지토리를 요청하세요. 그러면 admin 접근 권한을 받게 될 거예요.

또한 configmap 등록에 사용되는 플러그인 이름과, rollout 또는 analysis 리소스에서 플러그인이 자기 특정 구성을 찾는 데 사용하는 이름에 대한 표준 명명 규칙이 있어요. 이름은 <namespace>/<name> 형식이어야 하고, 두 부분 모두 GitHub의 username/org과 repository name에 대한 요구사항과 일치하는 정규식 검사를 거쳐요. 이 요구사항은 <org1>/nginx와 <org2>/nginx처럼 같은 플러그인 유형의 여러 제작자가 존재할 수 있도록 돕기 위한 것이에요. 이 이름은 argoproj-labs/rollouts-plugin-metric-sample-prometheus처럼 리포지토리 이름에 기반할 수도 있지만, 필수는 아니에요.

또한 argoproj-labs 아래의 리포지토리 명명은 rollouts-plugin-<type>-<tool> 형식의 표준이 있을 거예요. 여기서 <type>은 metric, step, trafficrouter 중 하나이고 <tool>은 플러그인이 대상으로 하는 소프트웨어(예: nginx)예요.

플러그인 이름 (Plugin Name)

이제 플러그인 명명과 리포지토리 표준에 대한 아이디어가 생겼으니, 이 문서의 나머지에서 쓸 이름을 골라 우리 플러그인을 argoproj-labs/nginx라고 부를게요.

이 이름은 몇 군데에서 사용돼요. 첫 번째는 플러그인 사용자가 구성해야 할 config map이에요. 아래와 같이 생겼어요.

kind: ConfigMap
metadata:
  name: argo-rollouts-config
data:
  metricProviderPlugins: |-
    - name: "argoproj-labs/metrics"
      location: "file:///tmp/argo-rollouts/metric-plugin"
      args:
        - "--log-level"
        - "debug"
  trafficRouterPlugins: |-
    - name: "argoproj-labs/nginx"
      location: "file:///tmp/argo-rollouts/traffic-plugin"
      args:
        - "--log-level"
        - "debug"
  stepPlugins: |-
    - name: "argoproj-labs/canary-step"
      location: "file:///tmp/argo-rollouts/canary-step-plugin"
      disabled: false
      args:
        - "--log-level"
        - "debug"

보시다시피 각 플러그인 유형 아래에 name:이라고 하는 필드가 있어요. 이것이 최종 사용자가 플러그인 이름을 구성해야 하는 첫 번째 자리예요. 두 번째 location은 rollout 객체나 analysis template에 있는데, 아래 예시에서 확인할 수 있어요. 세 번째 args는 플러그인의 명령줄 인자를 담아요.

구성 예시 (Configuration Examples)

AnalysisTemplate

analysis template의 spec.metrics[].provider.plugin 아래에 플러그인 이름을 사용하는 걸 볼 수 있어요.

플러그인 작성자로서 필요한 구성은 argoproj-labs/metrics 아래에 넣을 수 있고, 플러그인 이름 키를 통해 플러그인 안에서 그 구성을 조회할 수 있어요. 또한 플러그인이 지원하는 구성 옵션을 문서화해 두는 것도 좋아요.

apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: success-rate
spec:
  metrics:
    - name: success-rate
      ...
      provider:
        plugin:
          argoproj-labs/metrics:
            address: http://prometheus.local

Traffic Router

traffic router의 spec.strategy.canary.trafficRouting.plugins 아래에 플러그인 이름을 사용하는 걸 볼 수 있어요.

플러그인 작성자로서 필요한 구성은 argoproj-labs/nginx 아래에 넣을 수 있고, 플러그인 이름 키를 통해 플러그인 안에서 그 구성을 조회할 수 있어요. 또한 플러그인이 지원하는 구성 옵션을 문서화해 두는 것도 좋아요.

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: example-plugin-ro
spec:
  strategy:
    canary:
      canaryService: example-plugin-ro-canary-analysis
      stableService: example-plugin-ro-stable-analysis
      trafficRouting:
        plugins:
          argoproj-labs/nginx:
            stableIngress: canary-demo

Step Plugin

canary step의 spec.strategy.canary.steps[].plugin.name 아래에 플러그인 이름을 사용하는 걸 볼 수 있어요.

플러그인 작성자로서 config 속성 아래의 plugin 객체에 필요한 구성을 넣을 수 있고, 플러그인이 호출될 때 인자로 받게 돼요. 또한 플러그인이 지원하는 구성 옵션을 문서화해 두는 것도 좋아요.

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: example-plugin-ro
spec:
  strategy:
    canary:
      steps:
        - plugin:
            name: argoproj-labs/step-exec
            config:
              command: echo "hello world"

플러그인 인터페이스 (Plugin Interfaces)

Argo Rollouts는 현재 세 가지 플러그인 시스템을 지원해요. 플러그인 작성자로서 최종 목표는 이 인터페이스 중 적어도 하나를 hashicorp go-plugin으로 구현하는 것이에요. 각각에 해당하는 인터페이스는 MetricsPlugin, TrafficRouterPlugin, StepPlugin이에요:

type MetricProviderPlugin interface {
  // InitPlugin initializes the traffic router plugin. This gets called once when the plugin is loaded.
  InitPlugin() RpcError
  // Run start a new external system call for a measurement
  // Should be idempotent and do nothing if a call has already been started
  Run(*v1alpha1.AnalysisRun, v1alpha1.Metric) v1alpha1.Measurement
  // Resume Checks if the external system call is finished and returns the current measurement
  Resume(*v1alpha1.AnalysisRun, v1alpha1.Metric, v1alpha1.Measurement) v1alpha1.Measurement
  // Terminate will terminate an in-progress measurement
  Terminate(*v1alpha1.AnalysisRun, v1alpha1.Metric, v1alpha1.Measurement) v1alpha1.Measurement
  // GarbageCollect is used to garbage collect completed measurements to the specified limit
  GarbageCollect(*v1alpha1.AnalysisRun, v1alpha1.Metric, int) RpcError
  // Type gets the provider type
  Type() string
  // GetMetadata returns any additional metadata which providers need to store/display as part
  // of the metric result. For example, Prometheus uses is to store the final resolved queries.
  GetMetadata(metric v1alpha1.Metric) map[string]string
}

type TrafficRouterPlugin interface {
  // InitPlugin initializes the traffic router plugin. This gets called once when the plugin is loaded.
  InitPlugin() RpcError
  // UpdateHash informs a traffic routing reconciler about new canary, stable, and additionalDestination(s) pod hashes
  UpdateHash(rollout *v1alpha1.Rollout, canaryHash, stableHash string, additionalDestinations []v1alpha1.WeightDestination) RpcError
  // SetWeight sets the canary weight to the desired weight
  SetWeight(rollout *v1alpha1.Rollout, desiredWeight int32, additionalDestinations []v1alpha1.WeightDestination) RpcError
  // SetHeaderRoute sets the header routing step
  SetHeaderRoute(rollout *v1alpha1.Rollout, setHeaderRoute *v1alpha1.SetHeaderRoute) RpcError
  // SetMirrorRoute sets up the traffic router to mirror traffic to a service
  SetMirrorRoute(rollout *v1alpha1.Rollout, setMirrorRoute *v1alpha1.SetMirrorRoute) RpcError
  // VerifyWeight returns true if the canary is at the desired weight and additionalDestinations are at the weights specified
  // Returns nil if weight verification is not supported or not applicable
  VerifyWeight(rollout *v1alpha1.Rollout, desiredWeight int32, additionalDestinations []v1alpha1.WeightDestination) (RpcVerified, RpcError)
  // RemoveManagedRoutes Removes all routes that are managed by rollouts by looking at spec.strategy.canary.trafficRouting.managedRoutes
  RemoveManagedRoutes(ro *v1alpha1.Rollout) RpcError
  // Type returns the type of the traffic routing reconciler
  Type() string
}

type StepPlugin interface {
  // InitPlugin initializes the canary step plugin. This gets called once when the plugin is loaded.
  InitPlugin() RpcError
    // Run executes a step plugin for the RpcStepContext and returns the result to the controller or an RpcError for unexpected failures
    Run(*v1alpha1.Rollout, *RpcStepContext) (RpcStepResult, RpcError)
    // Terminate stops an uncompleted operation started by the Run operation
    Terminate(*v1alpha1.Rollout, *RpcStepContext) (RpcStepResult, RpcError)
    // Abort reverts the actions performed during the Run operation if necessary
    Abort(*v1alpha1.Rollout, *RpcStepContext) (RpcStepResult, RpcError)
    // Type returns the type of the step plugin
    Type() string
}

플러그인 Init 함수

각 플러그인 인터페이스에는 InitPlugin 함수가 있고, 이 함수는 플러그인이 처음 시작될 때 호출되며 시작당 한 번만 호출돼요. InitPlugin 함수는 플러그인을 초기화하는 수단으로 사용돼요. 플러그인 작성자에게 특정 메트릭 프로바이더용 클라이언트를 설정하거나, traffic router의 경우 kubernetes api용 클라이언트나 informer를 구성할 수 있는 능력을 주는 거예요. 여기서 알아둘 점은 이 호출이 RPC를 통해 일어나기 때문에, 플러그인 작성자는 플러그인 구조체에 상태가 저장되는 것에 의존하면 안 된다는 거예요. 호출 간에 유지(persist)되지 않기 때문이에요.

Kubernetes RBAC

플러그인은 rollouts 컨트롤러의 자식 프로세스로 실행되므로 컨트롤러와 같은 RBAC 권한을 상속해요. 즉 rollouts 컨트롤러의 service account가 플러그인이 동작하도록 올바른 권한을 가져야 해요. 이는 사용자에게 표준 rollouts service account에 대한 role과 role binding을 만들어 플러그인이 쓰도록 안내해야 할 수도 있음을 의미해요. 이것은 metric 플러그인보다 traffic router 플러그인에 더 영향을 줄 가능성이 높아요.

샘플 플러그인 (Sample Plugins)

argo-rollouts 리포지토리 안에 자신만의 플러그인을 만드는 참조로 사용할 수 있는 샘플 플러그인들이 있어요.

  • Metrics Plugin Sample

  • Traffic Router Plugin Sample

  • Step Plugin Sample

더 알아보기 (Learn more)