跳到內容
AggregaAggregaAggregaAggrega
選擇語言: 繁體中文
本頁為機器翻譯。閱讀英文原文。

資料模型

本頁說明一個概念,也就是誰撰寫關於元件的哪些資料,而不是可執行的工作區。一個契約,三種實現方式會在你建置的工作區中展示它;請用下列命令把它寫入你自己的資料夾:

Terminal window
aggrega draft --example postgres-three-realizations

接著它會印出要執行的下一批命令:

Terminal window
cd postgres-three-realizations
aggrega build --release release-selfhosted.yaml --auto-pull
aggrega build --release release-managed.yaml --auto-pull
aggrega build --release release-managed-dns.yaml --auto-pull
aggrega build --release release-external.yaml --auto-pull

values 與 infra:兩個命名空間,兩位作者

Component 宣告兩組各自獨立的設定。它的 values 屬於開發者,撰寫在 Aggregate 中:應用程式需要的內容,在每個環境中都相同。它的 infra 屬於操作員,撰寫在 Release 中:規模與位置,在不同環境之間有所不同。結構描述使兩者各自分開——Aggregate 結構描述在元件上沒有 infra,而 Release 結構描述沒有 values——因此任何一位作者都無法設定另一位的欄位。Recipe 會收到兩者,作為兩個各自獨立的物件,.values 與 .infra。

在範例中,開發者為資料庫及其登入角色命名,取自 aggregate.yaml:

spec:
components:
db:
type: core/datastore/postgres
values:
database: appdb
user: appuser

而建置受管理執行個體的 Release 為它指定規模,取自 release-managed.yaml,已省略其註解:

spec:
boundaries:
stack:
directory: stack
components:
db:
infra:
engine_version: "16"
storage:
size: 100Gi
type: gp3
ha:
enabled: true
read_replicas: 0

範例的另外兩個 Releases 會對同一個 Aggregate,分別在叢集中以及針對已存在的伺服器建置,各自有自己的 infra;Aggregate 不變。

仍應隨環境而異的值會被提升:Aggregate 宣告一個參數,把它寫入該值,而每個 Release 滿足該參數(請見建置的檔案)。

一個 Release 建立在另一個之上

Release 可以用 extends: 指名另一個 Release 作為它的基底,並只更改不同之處。子項繼承基底的邊界、它的位置與它的參數,而在 extends: 旁宣告 aggregate: 會被 Release 結構描述拒絕,因為子項必須建置與其基底相同的 Aggregate。它可以指名自己的 Manifest,或省略 manifest: 而繼承基底的。

# release-prod.yaml: the base gives every other setting
spec:
extends: ./release-base.yaml
boundaries:
stack:
components:
db:
infra:
storage:
size: 500Gi

邊界的 directory: 和任何其他設定一樣會被繼承,因此繼承了字面目錄的子項,會渲染到與其基底相同的位置。把目錄寫成針對參數,才會使每個 Release 的輸出送到各自的位置;請見複合 Release 與 extends 繼承。

一個 Manifest 建立在另一個之上

Manifest 可以用同樣的方式擴充另一個,而它的項目會取代基底中相同鍵的項目。開發用的 Manifest 可以保留正式環境 Manifest 的每一個繫結,只更改認證的實現方式:這裡,core/referenced-secret 附加項目在正式環境中是從機密儲存區擷取,而在開發中是依作者提供的值寫入 Secret。

manifest-prod.yaml
spec:
mappings:
components:
type:
core/datastore/postgres:1.0.0: helm/postgres:1.0.0
features:
type:
core/referenced-secret:1.0.0: helm/k8s-external-secret:1.0.0
---
# manifest-dev.yaml
spec:
extends: ./manifest-prod.yaml
mappings:
features:
type:
core/referenced-secret:1.0.0: helm/k8s-secret-from-parameter:1.0.0

這兩種實現方式以相同的方式發布 Secret 的名稱,因此讀取認證的元件在任一個 Manifest 之下,都會渲染出相同的參照;一個開發者意圖,兩種認證傳遞形狀會建置兩者並加以比較。

兩個標籤:型別與類別

每個 Component 在保留的 component.aggrega.ai/type 標籤上都帶有封閉集合中的一個值:server,長時間執行的端點;worker,背景使用端;stateful-server,保有自己持久資料的東西;task,執行到完成;function,事件驅動的函式;以及 resource,不自行執行任何運算的受管理雲端資源。這個值位於目錄實體上,絕不在 Aggregate 中的實例上。

型別說明基礎架構必須如何對待元件,而不是元件的用途。保有自己磁碟的訊息代理程式是 stateful-server,和資料庫一樣:core/messaging/kafka 與 core/datastore/postgres 帶有相同的型別。讀者據以瀏覽的是另一個標籤 component.aggrega.ai/category——代理程式是 messaging,資料庫是 datastore——它同時也是該實體所在的目錄資料夾。針對其中一個標籤撰寫的選擇器,絕不會比對到另一個標籤。