Cluster Decision Resource Generator
Cluster Decision Resource Generator
이 generator는 duck-typing을 이용해 참조하는 Kubernetes 리소스의 전체 형태를 알지 못해도 Argo CD 클러스터 목록을 생성해요. 커스텀 리소스의 status 리스트(예: open-cluster-management의 Placement rule)를 읽어 어느 클러스터에 배포할지 결정해요.
출처: 문서
본문
cluster decision resource generator는 duck-typing을 사용해 Argo CD 클러스터 목록(list)을 생성해요. 이 방식은 참조하는 Kubernetes 리소스의 전체 형태를 알 필요가 없어요. 다음은 cluster-decision-resource 기반 ApplicationSet generator의 예시예요.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: guestbook
namespace: argocd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- clusterDecisionResource:
# ConfigMap with GVK information for the duck type resource
configMapRef: my-configmap
name: quak # Choose either "name" of the resource or "labelSelector"
labelSelector:
matchLabels: # OPTIONAL
duck: spotted
matchExpressions: # OPTIONAL
- key: duck
operator: In
values:
- "spotted"
- "canvasback"
# OPTIONAL: Checks for changes every 60sec (default 3min)
requeueAfterSeconds: 60
template:
metadata:
name: '{{.name}}-guestbook'
spec:
project: "default"
source:
repoURL: https://github.com/argoproj/argocd-example-apps/
targetRevision: HEAD
path: guestbook
destination:
server: '{{.clusterName}}' # 'server' field of the secret
namespace: guestbook
ApplicationSet clusterDecisionResource generator가 참조하는 quak 리소스:
apiVersion: mallard.io/v1beta1
kind: Duck
metadata:
name: quak
spec: {}
status:
# Duck-typing ignores all other aspects of the resource except
# the "decisions" list
decisions:
- clusterName: cluster-01
- clusterName: cluster-02
ApplicationSet 리소스는 이 duck-typing에서 사용할 리소스를 정의하는 ConfigMap을 참조해요. 리소스를 식별하는 데 ArgoCD 인스턴스당 ConfigMap 하나만 필요해요. 여러 리소스 타입을 지원하려면 각각에 대해 ConfigMap을 만들면 돼요.
apiVersion: v1
kind: ConfigMap
metadata:
name: my-configmap
data:
# apiVersion of the target resource
apiVersion: mallard.io/v1beta1
# kind of the target resource
kind: ducks
# status key name that holds the list of Argo CD clusters
statusListKey: decisions
# The key in the status list whose value is the cluster name found in Argo CD
matchKey: clusterName
(전체 예시)
이 예시는 open-cluster-management.io 커뮤니티의 클러스터 관리 기능을 활용해요. open-cluster-management.io Placement rule용 GVK로 ConfigMap을 만들면, ApplicationSet이 여러 클러스터에 다양한 방식으로 프로비저닝할 수 있어요. 한 예시로, ApplicationSet이 3개 이상의 클러스터에 걸쳐 Argo CD Application 딱 두 개만 유지하게 할 수 있어요. 그러면 유지보수나 장애가 발생해도 ApplicationSet이 항상 두 개의 Application을 유지하며, Placement rule의 지시에 따라 애플리케이션을 사용 가능한 클러스터로 옮겨요.
어떻게 동작하나요 (How it works)
ApplicationSet은 Argo CD 네임스페이스에 생성되어야 하며, ConfigMap을 같은 네임스페이스에 두면 ClusterDecisionResource generator가 그것을 읽을 수 있어요. ConfigMap은 GVK 정보와 status 키 정의를 저장해요. open-cluster-management 예시에서 ApplicationSet generator는 apps.open-cluster-management.io/v1 apiVersion을 가진 placementrules kind를 읽어요. decisions 키에서 클러스터 목록을 추출하고, Argo CD에 정의된 실제 클러스터 이름을 목록의 각 요소에서 clusterName 키의 값과 대조해 검증해요.
ClusterDecisionResource generator는 duck-type 리소스 status 목록의 'name', 'server' 및 기타 key/value를 파라미터로 ApplicationSet 템플릿에 전달해요. 이 예시에서 decision 배열에는 추가 키 clusterName이 있었고, 이제 이를 ApplicationSet 템플릿에서 사용할 수 있어요.
참고 — Status.Decisions에 나열된 클러스터는 Argo CD에 미리 정의되어 있어야 해요
Status.Decisions에 나열된 클러스터 이름은 이 값들에 대해 애플리케이션을 생성하려면 Argo CD 안에 정의되어 있어야 해요. ApplicationSet 컨트롤러는 Argo CD 안에서 클러스터를 만들지 않아요.
기본 Cluster 목록 키는 clusters예요.
더 알아보기 (Learn more)
- Cluster generator — Argo CD 클러스터 목록 기반 생성.
- applicationset-specification — ApplicationSet 스펙 참고.