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

CEL 치트시트

원문 보기 위키 갱신

커스텀 리소스의 건강 상태를 확인하기 위한 CEL(Common Expression Language) 표현식 모음이에요.

출처: 문서

본문

About

Kustomization과 HelmRelease API는 .spec.healthCheckExprs 필드를 통해 커스텀 리소스에 대한 건강 상태 검사를 수행하는 커스텀 로직을 정의하는 것을 지원해요. 자세한 내용은 Kustomization과 HelmRelease 문서를 참고하세요. 이 필드는 CEL(Common Expression Language) 표현식 집합을 받아요.

여기에서 인기 있는 커스텀 리소스에 대한 커뮤니티 관리 CEL 표현식 세트를 찾을 수 있어요.

기여하기 (Contributing)

이 라이브러리에 기여하려면 이 파일을 변경하는 pull request를 여세요:

https://github.com/fluxcd/website/blob/main/content/en/flux/cheatsheets/cel-healthchecks.md

표현식을 테스트하고 정확성 증거를 pull request에 게시해 주세요. 즉 Kustomization으로 표현식을 구성하고 예상대로 작동하는지 검증한 다음 로그나 스크린샷을 pull request에 게시해 주세요.

CEL Playground는 표현식 테스트에 유용한 리소스예요. 각 표현식에 전달되는 입력은 커스텀 리소스 객체 자체예요.

FAQ

CEL 매크로 (CEL Macros)

CEL은 건강 검사 표현식을 계산하는 데 사용할 다양한 매크로를 제공해요. 이는 CEL-spec 언어 정의에 문서화되어 있어요.

has(...) CEL 매크로를 사용해 누락된 필드 처리하기

진행 중인 커스텀 리소스로 작업할 때 커스텀 리소스에 아직 존재하지 않는 필드를 참조하는 것이 흔해요. has 매크로로 CEL 표현식을 안전하게 보호할 수 있는데, 속성에 접근하기 전에 속성 존재 여부를 확인하는 거예요. 예를 들어 다음 CEL 표현식은 status.attribute.ready가 리소스에 없으면 false를 반환해요.

has(status.attribute) && status.attribute.ready

다만 has는 status나 data 같은 최상위 속성의 존재를 확인할 수 없다는 점에 유의하세요.

그룹의 모든 kind에 하나의 표현식 적용하기

kind 필드는 선택적이에요. 생략하면 항목이 apiVersion의 그룹 아래 제공되는 모든 kind에 적용되며, 이는 단일 프로젝트가 동일한 status 규약(예: Ready condition)을 공유하는 여러 CRD를 노출할 때 유용해요. 특정 kind가 있는 항목은 같은 kind에 대해 그룹 전용 항목보다 우선하므로, 그룹 전체 기본값을 정의하고 필요한 곳에서 kind별로 덮어쓸 수 있어요.

참고로 apiVersion의 그룹 부분만 일치에 사용돼요 — 버전은 무시되므로, 동일한 항목이 리소스의 모든 제공 버전에 적용돼요.

healthCheckExprs:
  # Applies to Flux Operator's FluxInstance, ResourceSet and ResourceSetInputProvider.
  - apiVersion: fluxcd.controlplane.io/v1
    failed: status.conditions.exists(e, e.type == 'Stalled' && e.status == 'True' && e.observedGeneration == metadata.generation)
    current: status.conditions.filter(e, e.type == 'Ready').all(e, e.status == 'True' && e.observedGeneration == metadata.generation)

라이브러리 (Library)

이 라이브러리의 항목은 알파벳순으로 정렬돼 있어요.

CephCluster

이 예제의 CephCluster 리소스는 rook-ceph-cluster Flux HelmRelease에 의해 생성돼요.

healthChecks:
  - apiVersion: helm.toolkit.fluxcd.io/v2
    kind: HelmRelease
    name: rook-ceph-cluster
    namespace: rook-ceph
  - apiVersion: ceph.rook.io/v1
    kind: CephCluster
    name: rook-ceph
    namespace: rook-ceph
healthCheckExprs:
  - apiVersion: ceph.rook.io/v1
    kind: CephCluster
    failed: status.ceph.health == 'HEALTH_ERR'
    current: status.ceph.health == 'HEALTH_OK'

Cluster

healthCheckExprs:
  - apiVersion: cluster.x-k8s.io/v1beta1
    kind: Cluster
    failed: status.conditions.filter(e, e.type == 'Ready').all(e, e.status == 'False')
    current: status.conditions.filter(e, e.type == 'Ready').all(e, e.status == 'True')

ClusterIssuer

healthCheckExprs:
  - apiVersion: cert-manager.io/v1
    kind: ClusterIssuer
    failed: status.conditions.filter(e, e.type == 'Ready').all(e, e.status == 'False')
    current: status.conditions.filter(e, e.type == 'Ready').all(e, e.status == 'True')

ClusterSecretStore

healthCheckExprs:
  - apiVersion: external-secrets.io/v1beta1
    kind: ClusterSecretStore
    failed: status.conditions.filter(e, e.type == 'Ready').all(e, e.status == 'False')
    current: status.conditions.filter(e, e.type == 'Ready').all(e, e.status == 'True')

Crossplane

healthCheckExprs:
  - apiVersion: pkg.crossplane.io/v1
    kind: Provider
    failed: status.conditions.filter(e, e.type == 'Healthy').all(e, e.status == 'False')
    current: status.conditions.filter(e, e.type == 'Healthy').all(e, e.status == 'True')
  - apiVersion: iam.aws.crossplane.io/v1beta1
    kind: Role
    failed: status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'False' && e.reason == 'ReconcileError')
    current: status.conditions.filter(e, e.type == 'Ready').all(e, e.status == 'True')

ScaledObject

healthCheckExprs:
  - apiVersion: keda.sh/v1alpha1
    kind: ScaledObject
    failed: status.conditions.filter(e, e.type == 'Ready').all(e, e.status == 'False')
    current: status.conditions.filter(e, e.type == 'Ready').all(e, e.status == 'True')

SealedSecret

healthCheckExprs:
  - apiVersion: bitnami.com/v1alpha1
    kind: SealedSecret
    failed: status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'False')
    current: status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'True')

더 알아보기 (Learn more)