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

組合

本頁說明一個概念,也就是以比單一元件更大的部分來建立應用程式,而不是可執行的工作區。模組邊界路由——把整個子模組放入邊界會在你建置的工作區中展示它;請用下列命令把它寫入你自己的資料夾:

Terminal window
aggrega draft --example module-boundary-routing

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

Terminal window
cd module-boundary-routing
aggrega build --release release.yaml --auto-pull

模組:被另一個匯入的 Aggregate

Aggregate 可以在 aggregates: 之下,把另一個 Aggregate 作為模組匯入。模組組成它自己的元件並連接它自己的邊,因此它的內部沒有任何東西會出現在匯入它的 Aggregate 中。範例從標準程式庫目錄匯入兩個模組,取自 aggregate.yaml:

spec:
aggregates:
metrics:
type: core/thanos
documents:
type: core/ferretdb

模組的 exportedComponents 區塊是它的公開介面:模組之外的東西可以連接的元件,每個以它匯出時的名稱呈現。core/ferretdb 把它的 proxy 元件匯出為 mongo,因此匯入的 Aggregate 的某個元件,以點分隔路徑 documents.mongo 觸及它:

uses:
database:
main:
target: documents.mongo

模組可以宣告自己的參數,由匯入的 Aggregate 在匯入的 parameters: 上滿足。

放置模組

Release 以鍵為模組名稱的 aggregates: 項目,把整個模組放入某個邊界,而模組所含的每個元件都隨之而去。它也可以設定模組的元件,各依它在模組內的名稱。取自 release.yaml,已省略註解:

spec:
boundaries:
observability:
directory: observability
annotations:
aggrega.ai/namespace: observability
aggregates:
metrics:
components:
query:
infra:
compute:
cpu: 500m
memory: 1Gi
data:
directory: data
annotations:
aggrega.ai/namespace: data
aggregates:
documents: {}

模組自己的註記會觸及它自己的元件,和 Aggregate 的註記觸及它自己的元件完全一樣,因此模組可以把它的元件放入它所宣告的命名空間。匯入的 Aggregate 不宣告任何觸及模組內部的內容;Release 會,而在相同的鍵上,它的值勝出。

建置不佈建的服務

已經存在的伺服器仍是圖的一個節點:它參與連線、原則,以及它的使用端所收到的內容,而不為它佈建任何東西。它的 Manifest 繫結一個什麼都不佈建的 Recipe,而由 Release 給出位址。在一個契約,三種實現方式中,manifest-external.yaml Manifest 把 core/datastore/postgres 繫結到 helm/postgres-external,它只發出一個 ExternalName Service,而 Release 提供位址,取自 release-external.yaml:

db:
infra:
overrides:
host: postgres.data.example.net

位址是指標字串:建置直接傳遞它而不解析它,而應用程式執行時在該名稱上回應的是什麼,應用程式就觸及什麼。對範例的三個 Releases,Aggregate 是同一個檔案。

子系統:在一個 Aggregate 內分組

子系統在 Aggregate 之內把元件分組。在它上面宣告的註記會觸及它所容納的每個元件,而附加到它的 Feature 會附加到其中每一個:

spec:
subsystems:
billing:
annotations:
team.aggrega.ai/owner: billing-squad
aggrega.ai/namespace: billing
features:
metrics:
type: core/prometheus-exporter
components:
invoice-api:
type: core/compute/server
payment-worker:
type: core/compute/worker

建置會攤平子系統樹:invoice-api 與 payment-worker 各自帶有 metrics 附加項目與兩個註記,Recipe 將它們讀作 {{ index .context.annotations.aggregate "team.aggrega.ai/owner" }}。aggrega.ai/namespace 是提供者註記,因此它也把兩個元件都放入 billing 命名空間。Release 在每個元件的項目之下,依子系統給它的名稱,設定附加項目的 infra,而 Release 所設定的命名空間會覆寫子系統為它所涵蓋的元件設定的命名空間。

連接到自己某個東西的附加項目

附加項目可以帶有自己的 uses: 區塊,從附加項目而不是它所在的元件畫出邊。在每個目標上都備份的資料存放區中,操作員把 core/backup 附加到資料庫,並把附加項目連接到備份要送往的儲存貯體,取自 release-helm-velero.yaml:

spec:
components:
db:
features:
backup:
type: core/backup
infra:
schedule: "30 2 * * *"
retention_days: 14
uses:
store:
bucket:
target: backups

資料庫自己的連線不變:通往 backups 的邊屬於附加項目,被記錄為由它所畫,並且和任何其他邊一樣由原則檢查。運作面 Feature 與認證 Feature 以同樣的方式附加,而其中任一個都可以帶有 uses: 區塊。