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

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

원문 보기 위키 갱신

Argo Rollouts는 해시코프(HashiCorp)의 go-plugin 라이브러리를 기반으로 플러그인 시스템을 제공합니다. 플러그인을 독립 실행형 실행 파일로 컴파일한 뒤 런타임에 rollouts 컨트롤러가 이를 로드하는 방식입니다. 본 문서는 메트릭(Metric), 트래픽 라우터(Traffic Router), 스텝(Step) 플러그인을 만드는 방법을 안내합니다.

출처: Argo Rollouts 문서

본문

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

Argo Rollouts 플러그인은 hashicorp의 go-plugin 라이브러리에 의존합니다. 이 라이브러리는 플러그인이 독립 실행형 실행 파일로 컴파일된 뒤, 런타임에 rollouts 컨트롤러에 의해 로드될 수 있는 방법을 제공합니다.

이는 플러그인 실행 파일이 rpc 서버 역할을 하고 rollouts 컨트롤러가 클라이언트 역할을 하는 방식으로 동작합니다. 플러그인 실행 파일은 rollouts 컨트롤러에 의해 시작되며, 컨트롤러가 unix 소켓을 통해 연결하는 장수명(long-lived) 프로세스입니다. 플러그인이 로드되는 방식의 개요는 다음과 같습니다.

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

플러그인 저장소 (Plugin Repository)

플러그인이 주요 argo rollouts 문서에 나열되게 하려면, 플러그인 저장소가 argoproj-labs 조직 아래에 생성되어야 합니다. 관리자 접근 권한을 부여받을 저장소를 요청하는 issue를 argo-rollouts 아래에 열어 주세요.

또한 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

트래픽 라우터의 경우 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 함수 (Plugin Init Function)

각 플러그인 인터페이스에는 InitPlugin 함수가 있습니다. 이 함수는 플러그인이 처음 시작될 때 호출되며 시작당 한 번만 호출됩니다. InitPlugin 함수는 플러그인을 초기화하는 수단으로 사용되며, 플러그인 작성자가 특정 메트릭 제공자에 대한 클라이언트를 설정하거나, 트래픽 라우터의 경우 kubernetes api에 대한 클라이언트나 인포머를 구성할 수 있게 합니다. 한 가지 유의할 점은 이러한 호출이 RPC를 통해 발생하기 때문에 플러그인 작성자는 플러그인 구조체에 state가 저장될 것이라고 의존해서는 안 된다는 것입니다. 호출 간에 유지되지 않기 때문입니다.

Kubernetes RBAC

플러그인은 rollouts 컨트롤러의 자식 프로세스로 실행되므로 컨트롤러와 동일한 RBAC 권한을 상속합니다. 이는 rollouts 컨트롤러의 service account에 플러그인이 동작하도록 올바른 권한이 필요함을 의미합니다. 사용자에게 플러그인이 사용하도록 표준 rollouts service account에 대한 role과 role binding을 만들도록 안내해야 할 수도 있습니다. 이는 메트릭 플러그인보다 트래픽 라우터 플러그인에 더 영향을 줄 수 있습니다.

샘플 플러그인 (Sample Plugins)

argo-rollouts 저장소에는 자체 플러그인을 만들 때 참조로 사용할 수 있는 샘플 플러그인이 있습니다.

  • Metrics Plugin Sample
  • Traffic Router Plugin Sample
  • Step Plugin Sample

더 알아보기 (Learn more)