From b28e5dd27a72bec9b865546049eff03f648e00ac Mon Sep 17 00:00:00 2001 From: emelinda Date: Mon, 3 Aug 2026 16:02:35 +0300 Subject: [PATCH] feat(fluxcd): introduce multi-layer infrastructure setup with kustomize and CRD dependency handling in aero environment --- clusters/aero/configs/kustomization.yaml | 8 ++++ clusters/aero/controllers/kustomization.yaml | 18 ++++++++ clusters/aero/infrastructure.yaml | 41 +++++++++++++++++++ clusters/aero/kustomization.yaml | 7 ++++ .../aero/{ => configs}/clusterissuer-ca.yaml | 0 .../aero/configs/kustomization.yaml | 7 ++++ .../cert-manager/aero/kustomization.yaml | 11 +++-- .../istio-config/aero/istio-config.yaml | 13 ++++++ 8 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 clusters/aero/configs/kustomization.yaml create mode 100644 clusters/aero/controllers/kustomization.yaml create mode 100644 clusters/aero/infrastructure.yaml create mode 100644 clusters/aero/kustomization.yaml rename infrastructure/cert-manager/aero/{ => configs}/clusterissuer-ca.yaml (100%) create mode 100644 infrastructure/cert-manager/aero/configs/kustomization.yaml diff --git a/clusters/aero/configs/kustomization.yaml b/clusters/aero/configs/kustomization.yaml new file mode 100644 index 0000000..4edfaf2 --- /dev/null +++ b/clusters/aero/configs/kustomization.yaml @@ -0,0 +1,8 @@ +# Слой 2: ресурсы, которым нужны CRD из слоя controllers. +# Применяется только после того, как infra-controllers дошёл до Ready +# (dependsOn в clusters/aero/infrastructure.yaml). +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + # Внутренний удостоверяющий центр контура: selfsigned → корневой CA → издатель. + - ../../../infrastructure/cert-manager/aero/configs diff --git a/clusters/aero/controllers/kustomization.yaml b/clusters/aero/controllers/kustomization.yaml new file mode 100644 index 0000000..a6b1aef --- /dev/null +++ b/clusters/aero/controllers/kustomization.yaml @@ -0,0 +1,18 @@ +# Слой 1: чарты инфраструктуры. Только HelmRelease и Namespace — никаких +# ресурсов, чьи CRD ставятся этими же чартами (см. clusters/aero/infrastructure.yaml). +# +# Порядок внутри слоя обеспечивают dependsOn в самих HelmRelease: +# istiod и ingressgateway ждут istio-base, istio-config ждёт всех троих. +# +# local-path-provisioner намеренно НЕ подключён: в k3s он встроен и уже +# обслуживает StorageClass local-path (по умолчанию). Чарт из репозитория +# создал бы второй провижинер с тем же именем класса. +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../../infrastructure/cert-manager/aero + - ../../../infrastructure/istio-base/aero + - ../../../infrastructure/istio-pilot/aero + - ../../../infrastructure/istio-gateway/aero + - ../../../infrastructure/istio-config/aero + - ../../../infrastructure/dashboard/aero diff --git a/clusters/aero/infrastructure.yaml b/clusters/aero/infrastructure.yaml new file mode 100644 index 0000000..d88c549 --- /dev/null +++ b/clusters/aero/infrastructure.yaml @@ -0,0 +1,41 @@ +# Инфраструктура разделена на два слоя, и это не косметика. +# +# Flux делает dry-run всей Kustomization целиком перед применением. Если +# положить cert-manager (который СТАВИТ CRD) и ClusterIssuer/Certificate +# (которые ЭТИ CRD используют) в один слой, dry-run падает с +# no matches for kind "Certificate" in version "cert-manager.io/v1" +# и не применяется НИЧЕГО — включая сам cert-manager. Дедлок: CRD никогда не +# появятся, потому что слой не может пройти проверку. +# +# Поэтому: controllers ставят чарты (и CRD), configs применяются после них +# через dependsOn и содержат только пользовательские ресурсы. +--- +apiVersion: kustomize.toolkit.fluxcd.io/v1 +kind: Kustomization +metadata: + name: infra-controllers + namespace: flux-system +spec: + interval: 10m0s + path: ./clusters/aero/controllers + prune: true + wait: true + timeout: 10m0s + sourceRef: + kind: GitRepository + name: flux-system +--- +apiVersion: kustomize.toolkit.fluxcd.io/v1 +kind: Kustomization +metadata: + name: infra-configs + namespace: flux-system +spec: + interval: 10m0s + path: ./clusters/aero/configs + prune: true + dependsOn: + - name: infra-controllers + sourceRef: + kind: GitRepository + name: flux-system diff --git a/clusters/aero/kustomization.yaml b/clusters/aero/kustomization.yaml new file mode 100644 index 0000000..faafdb0 --- /dev/null +++ b/clusters/aero/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ./flux-system + - ./helm-repositories.yaml + # Два слоя инфраструктуры с dependsOn — см. комментарий внутри файла. + - ./infrastructure.yaml diff --git a/infrastructure/cert-manager/aero/clusterissuer-ca.yaml b/infrastructure/cert-manager/aero/configs/clusterissuer-ca.yaml similarity index 100% rename from infrastructure/cert-manager/aero/clusterissuer-ca.yaml rename to infrastructure/cert-manager/aero/configs/clusterissuer-ca.yaml diff --git a/infrastructure/cert-manager/aero/configs/kustomization.yaml b/infrastructure/cert-manager/aero/configs/kustomization.yaml new file mode 100644 index 0000000..506d22e --- /dev/null +++ b/infrastructure/cert-manager/aero/configs/kustomization.yaml @@ -0,0 +1,7 @@ +# Пользовательские ресурсы cert-manager: применяются слоем infra-configs, +# после того как чарт из слоя infra-controllers поставил CRD. +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - clusterissuer-ca.yaml diff --git a/infrastructure/cert-manager/aero/kustomization.yaml b/infrastructure/cert-manager/aero/kustomization.yaml index 3b0d9aa..6e2bd92 100644 --- a/infrastructure/cert-manager/aero/kustomization.yaml +++ b/infrastructure/cert-manager/aero/kustomization.yaml @@ -3,11 +3,14 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - ../base - # Внутренний CA вместо ACME: контур закрытый, до Let's Encrypt не достучаться. - - clusterissuer-ca.yaml -# ACME-издатели из base выключены удалением, а не форком base: так overlay -# остаётся патчем и не расходится с остальными кластерами при обновлении base. +# Здесь только чарт и namespace. Корневой CA (clusterissuer-ca.yaml) лежит +# рядом, но подключается СЛОЕМ ВЫШЕ — из clusters/aero/configs: его ресурсы +# требуют CRD, которые ставит этот же чарт. +# +# ACME-издатели из base выключены удалением, а не форком base: overlay +# остаётся патчем и не расходится при обновлении base. Плюс без этого они +# ломали бы dry-run слоя controllers — их CRD тоже ещё не существует. patches: - target: kind: ClusterIssuer diff --git a/infrastructure/istio-config/aero/istio-config.yaml b/infrastructure/istio-config/aero/istio-config.yaml index 930ab80..ba32b26 100644 --- a/infrastructure/istio-config/aero/istio-config.yaml +++ b/infrastructure/istio-config/aero/istio-config.yaml @@ -6,6 +6,19 @@ metadata: spec: interval: 5m timeout: 10m + # Список продублирован из base целиком: для CRD kustomize заменяет списки, + # а не сливает, поэтому частичный патч потерял бы зависимости от istio. + # cert-manager добавлен сверх base — чарт istio-config рендерит Certificate, + # и без готовых CRD установка падает. + dependsOn: + - name: istio-base + namespace: istio-system + - name: istiod + namespace: istio-system + - name: ingressgateway + namespace: istio-system + - name: cert-manager + namespace: cert-manager values: global: env: aero