Flux Schema CLI로 커스텀 카탈로그 유지하기
플럭스 공식 CLI 플러그인 문서입니다. 카탈로그(catalog)는 flux schema validate가 매니페스트의 apiVersion과 kind에서 스키마를 해석할 수 있도록 배치된 JSON Schema의 디렉터리 트리예요. 내장 Flux Schema 카탈로그는 Kubernetes, OpenShift, Gateway API, 그리고 Flux 생태계에 대한 스키마를 제공해요. 커스텀 카탈로그를 사용하면 내부 CRD를 다루고, 특정 업스트림 버전을 고정하고, 도구에 맞는 배치를 조립할 수 있어요.
직접 추출하고 싶지 않은 타사 CRD의 경우, 호스팅된 생태계 카탈로그를 --schema-location ecosystem으로 사용할 수 있어요.
출처: 문서
본문
배치 (Layout)
기본 해석 템플릿은 다음과 같아요:
{{ .Group }}/{{ .Kind }}_{{ .Version }}.json
예를 들어 apiVersion: source.toolkit.fluxcd.io/v1, kind: GitRepository는 source.toolkit.fluxcd.io/GitRepository_v1.json으로 해석돼요.
모든 템플릿 변수는 렌더링 시점에 소문자로 변환되므로, apiVersion/kind가 혼합 대소문자여도 디스크의 파일 이름은 소문자예요.
다른 배치가 필요하다면(예: kubeconform/kubeval 평면 형태) --schema-location에 전체 템플릿을 전달하세요:
flux schema validate ./manifests \
--schema-location './my-catalog/{{.Kind}}-{{.GroupPrefix}}-{{.Version}}.json'
지원되는 템플릿 변수:
| Variable | Example | | .Group | source.toolkit.fluxcd.io | | .GroupPrefix | source | | .Kind | gitrepository | | .Version | v1 |
빈 .Group(Kubernetes 코어 API, 예: apiVersion: v1)은 core로 정규화되고, .GroupPrefix는 .Group에서 설정되지 않았을 때 파생돼요. 따라서 코어 Pod는 기본 템플릿으로 core/pod_v1.json으로 렌더링되고, validate가 그 스키마를 조회할 때 같은 경로로 해석돼요.
아래에 설명되는 extract 명령어는 모두 같은 기본 템플릿과 -f, --output-format 플래그를 공유하므로, 단일 --schema-location이 생성하는 모든 것을 해석해요.
카탈로그 채우기 (Populating a catalog)
flux schema extract 명령어는 기본적으로 위의 배치를 사용해 kind마다 하나의 JSON Schema 파일을 작성해요. 이 명령어를 섞어 사용해 Kubernetes 코어 API, OpenShift 리소스, 매니페스트가 의존하는 모든 CRD를 다룰 수 있어요.
Kubernetes CRDs
flux schema extract crd [files...]
베어 CRD, CRD의 List, 또는 다중 문서 YAML 스트림을 읽고 CRD 버전마다 스키마 파일 하나를 출력해요.
| Flag | Description | | -d, --output-dir | Directory to write JSON Schema files to (mutually exclusive with --output-archive). | | -a, --output-archive | Path to write a gzipped tar archive of JSON Schema files to. | | -f, --output-format | Go template for output file paths (default: {{ .Group }}/{{ .Kind }}_{{ .Version }}.json). | | --index-source | Source name and version recorded in field index headers, overriding auto-detection. | | --strip-description | Drop description fields from the generated schemas to reduce their size. | | --with-field-index | Also write a .fields.txt field index next to each schema. | | --with-explain-type-metadata | Keep JSON-only explain type hints, without writing explain lookup files. | | --with-explain-metadata | Include JSON type hints, alias redirects, and .explain/ lookup shards for custom catalogs used by flux schema explain. |
클러스터에 설치된 모든 CRD에 대한 스키마를 생성해요:
kubectl get crds -o yaml | flux schema extract crd -d ./my-catalog
또는 오퍼레이터의 CRD 번들에 대한 kustomize 빌드에서:
kustomize build ./config/crd | flux schema extract crd -d ./my-catalog
출력은 kubeconform과 kubeval과도 호환되므로, extract crd는 kubeconform의 openapi2jsonschema.py 스크립트의 드롭인 대체물이에요.
Kubernetes APIs
flux schema extract k8s [swagger-file]
Kubernetes OpenAPI v2 swagger 문서를 읽고 x-kubernetes-group-version-kind 아래 나열된 kind마다 파일 하나를 출력해요. 헬퍼 타입(예: PodSpec, ObjectMeta)은 이를 참조하는 kind에 인라인되며, 독립 파일로 작성되지 않아요.
| Flag | Description | | --version X.Y.Z | Fetch the swagger from github.com/kubernetes/kubernetes for the given release tag (mutually exclusive with a swagger file). | | -d, --output-dir | Directory to write JSON Schema files to. | | -f, --output-format | Go template for output file paths (default: {{ .Group }}/{{ .Kind }}_{{ .Version }}.json). | | --index-source | Source name and version recorded in field index headers, overriding auto-detection. | | --strip-description | Drop description fields from the generated schemas to reduce their size. | | --with-field-index | Also write a .fields.txt field index next to each schema. | | --with-explain-type-metadata | Keep JSON-only explain type hints, without writing explain lookup files. | | --with-explain-metadata | Include JSON type hints, alias redirects, and .explain/ lookup shards for custom catalogs used by flux schema explain. |
카탈로그를 특정 Kubernetes 릴리스로 고정해요:
flux schema extract k8s --version 1.35.0 -d ./my-catalog
또는 라이브 클러스터에서 추출해요:
kubectl get --raw /openapi/v2 | flux schema extract k8s -d ./my-catalog
코어 API kind(apiVersion: v1)는 core/ 그룹 디렉터리 아래 렌더링돼요.
OpenShift APIs
flux schema extract openshift [swagger-file]
openshift/api OpenAPI v2 swagger 문서를 읽고 OpenShift 리소스마다 파일 하나를 출력해요. openshift 네임스페이스의 정의만 출력되며, 포함된 업스트림 Kubernetes 타입(예: Pod)은 인라인돼요.
| Flag | Description | | --ref REF | Fetch the swagger from github.com/openshift/api at the given git ref (e.g. release-4.20); mutually exclusive with a swagger file. | | -d, --output-dir | Directory to write JSON Schema files to. | | -f, --output-format | Go template for output file paths (default: {{ .Group }}/{{ .Kind }}_{{ .Version }}.json). | | --index-source | Source name and version recorded in field index headers, overriding auto-detection. | | --strip-description | Drop description fields from the generated schemas to reduce their size. | | --with-field-index | Also write a .fields.txt field index next to each schema. | | --with-explain-type-metadata | Keep JSON-only explain type hints, without writing explain lookup files. | | --with-explain-metadata | Include JSON type hints, alias redirects, and .explain/ lookup shards for custom catalogs used by flux schema explain. |
OpenShift 릴리스 브랜치로 고정해요:
flux schema extract openshift --ref release-4.20 -d ./my-catalog
또는 다운로드한 swagger를 입력으로 넣어요:
curl -sL https://raw.githubusercontent.com/openshift/api/release-4.20/openapi/openapi.json | \
flux schema extract openshift -d ./my-catalog
전형적인 갱신 스크립트 (A typical refresh script)
단일 스크립트로 필요한 모든 것이 담긴 카탈로그를 채울 수 있어요 — 기본 -f 템플릿 덕분에 출력이 같은 루트 아래 나란히 배치되고 하나의 --schema-location으로 해석돼요:
#!/usr/bin/env bash
set -euo pipefail
CATALOG=./my-catalog
mkdir -p "$CATALOG"
# Kubernetes core + built-ins
flux schema extract k8s --version 1.35.0 --strip-description -d "$CATALOG"
# Vendor CRDs at a pinned version
kubectl kustomize \
https://github.com/external-secrets/external-secrets/config/crds/bases?ref=v2.3.0 | \
flux schema extract crd --strip-description -d "$CATALOG"
카탈로그를 작게 유지하려면 모든 생성기에 --strip-description을 전달하세요 — 공식 카탈로그는 모든 곳에서 이를 사용하며 네이티브 Kubernetes 스키마에서 약 54% 크기 감소를 얻어요.
공식 카탈로그의 scripts/ 아래 생성기 스크립트는 작업 참조입니다: gen-k8s-schemas.sh, gen-flux-schemas.sh, gen-crd-schemas.sh, gen-openshift-schemas.sh.
스키마 출력 (Schema output)
모든 extract 명령어는 standalone-strict JSON Schema 변형을 출력하므로, 카탈로그의 스키마는 단독으로 사용 가능하며 Kubernetes API 서버가 강제하는 제약을 재현해요:
- 모든
$ref가 인라인되므로 각 스키마에는 교차 파일 의존성이 없어요. - 속성이 있는 객체는
x-kubernetes-preserve-unknown-fields: true로 표시된 노드 아래를 제외하고additionalProperties: false로 닫혀요. 그 노드는 열린 채로 남아 자유 형식 지도가 올바르게 검증돼요. - 매니페스트 검증에 영향을 주는 Kubernetes admission 검증 확장은 보존돼요: x-kubernetes-embedded-resource, x-kubernetes-list-type, x-kubernetes-list-map-keys, x-kubernetes-map-type, x-kubernetes-preserve-unknown-fields, x-kubernetes-validations. Merge/patch 전용 확장은 제거돼요.
- 정수-또는-문자열 필드는
oneOf: [{type: string}, {type: integer}]로 다시 작성돼요. 레거시format: int-or-string과 구조적x-kubernetes-int-or-string: true형식이 모두 인식돼요. - 선택적 필드는 nullable(
type: [<t>, "null"])로 표시되어, 설정되지 않은 선택값에 null을 수락하는 API 서버의 동작과 일치해요. apiVersion과kind가 모든 kind의 속성과 required 목록에 주입돼요.x-flux-schema-*explain 어노테이션은 기본적으로 생략돼요. 이는 문서 전용이며 JSON Schema 검증에 영향을 주지 않아요.
Explain 메타데이터
extract는 flux schema explain이 사용하는 두 계층의 메타데이터를 작성할 수 있어요. 이는 옵트인(opt-in)이므로 검증 전용 카탈로그는 기본적으로 커지지 않아요.
스키마 로컬 타입 메타데이터는 각 JSON Schema 안에 저장돼요. OpenAPI $ref 정의가 인라인될 때 달리 손실되는 필드 렌더링 힌트(명명된 중첩 타입 Container, Quantity, IntOrString, 참조된 타입 설명)를 보존해요. 다른 인덱스가 리소스 조회와 리소스 이름 완성을 제공할 때 --with-explain-type-metadata를 전달하세요. 생태계 카탈로그는 --schema-location ecosystem과 함께 이 메타데이터 수준을 사용하는데, 여기서 explain은 https://schemas.fluxoperator.dev/index.json에서 리소스를 해석하고 로드된 JSON 스키마를 kubectl 스타일 필드 출력과 필드 경로 완성에 사용해요.
커스텀 카탈로그 explain 메타데이터에는 스키마 로컬 타입 메타데이터에 더해 별도의 생태계 인덱스가 없을 때 필요한 조회 파일(별칭 리다이렉트 JSON 파일, .explain/refs/, .explain/completion/)이 포함돼요. 자체적으로 flux schema explain 리소스 참조와 리소스 이름 셸 완성을 지원해야 하는 커스텀 카탈로그에는 --with-explain-metadata를 전달하세요. 필드 경로 완성은 해석된 JSON Schema에서 파생돼요. 이 플래그는 --with-explain-type-metadata의 상위 집합이에요.
--with-field-index는 별개예요. 검색, 에이전트, 기타 카탈로그 소비자를 위해 .fields.txt 사이드카를 작성해요. explain은 리소스 조회, 완성, 필드 렌더링, 타입 이름 또는 설명에 필드 인덱스를 사용하지 않아요. JSON explain 메타데이터가 없을 때 루트 apiVersion과 kind를 복구하는 호환성 폴백으로만 .fields.txt를 읽을 수 있어요.
--strip-description으로 생성된 카탈로그는 여전히 리소스를 검증하고 필드를 해석하지만, 설명과 explain 타입 설명이 제거되었기 때문에 kubectl의 설명 출력을 바이트 단위로 재현할 수 없어요.
필드 인덱스 (Field indexes)
extract 명령어에 --with-field-index를 전달하면 추출된 스키마 옆에 greppable(검색 가능)하고 LLM 친화적인 필드 인덱스를 작성해요: 스키마마다 .fields.txt 파일 하나, 필드마다 자기 완결적인 줄 하나. 파일 명명, 줄 문법, 어노테이션은 필드 인덱스 참조를 참고하세요. 필드 인덱스는 explain 메타데이터와 독립적이에요.
호스팅 (Hosting)
카탈로그는 단지 파일 트리예요. 검증기의 로더는 각 렌더링된 위치를 http/https 또는 로컬 파일시스템에서 가져와요. 일반적인 옵션:
- 파일시스템: 카탈로그를 매니페스트와 같은 리포지토리에 벤더링하거나 릴리스 artifact / OCI artifact로 게시해 CI에서 풀어내기.
- HTTP(S): 모든 정적 호스트(GitHub raw, S3, GitHub Pages 등)에서 카탈로그를 제공하고 기본 URL을 --schema-location에 전달하기. 로더는 기본 템플릿으로 베어 URL을 확장해요.
주어진 apiVersion/kind에 대한 404 또는 ENOENT는 다음 --schema-location으로 넘어가므로, 내장 카탈로그 위에 카탈로그를 겹쳐 쌓을 수 있어요:
flux schema validate ./manifests \
--schema-location ./my-catalog \
--schema-location default
순서가 중요해요 — 첫 번째 일치가 이기므로, 오버라이드를 default보다 앞에 두세요.
갱신 (Refreshing)
업스트림 버전이 이동하면서 커스텀 카탈로그는 오래돼요. 공식 카탈로그가 .github/workflows/update-catalog.yaml으로 갱신되는 것과 같은 방식으로, 갱신 스크립트를 CI(크론 워크플로우, 예약 파이프라인 등)에 예약하고 결과를 다시 커밋하세요.