นโยบายที่แนบ Features ที่ไม่มีใครเขียน: คำอธิบายประกอบที่แทรกที่ `annotation-transform`
นโยบาย
นโยบายannotation-transform หนึ่ง
สิ่งที่ตัวอย่างนี้บิลด์
| อินสแตนซ์ | Component ของ | สิ่งrelease.yaml |
|---|---|---|
api | example/compute/service | ไม่ |
worker | example/compute/service | ไม่ |
gateway | example/compute/service | คำ |
ทั้งdist/shop/helm/ example/compute/service เป็น Component สาธิตcore/prometheus-exporter ซึ่ง
การผูกคำอธิบายประกอบทั้งสอง
manifest.yaml ให้
features: type: core/prometheus-exporter: helm/prometheus-exporter:1.0.0 core/aws-irsa: helm/aws-irsa:1.0.0 annotations: feature.aggrega.ai/monitoring: feature: core/prometheus-exporter maps: infra: - interval - port - path aws-role: feature: core/aws-irsa maps: infra: - role_arnการfeature.aggrega.ai/monitoring รับ {interval: …, port: …, path: …} การaws-role รับ ARN ของcore/aws-irsa ตั้ง
การแนบนโยบาย
.aggrega-config.yaml ระบุ hub เป็น--config คือ governance-rego.yaml สำหรับgovernance-cel.yaml สำหรับ
plugins: governance: - uri: governance/rego:0.9.0 role: annotation-transform with: sources: - policies/platform-defaults.rego--config ระบุ.aggrega-config.yaml ของ
0.9.0 คือaggrega ของaggrega ที่
สิ่งที่นโยบาย annotation-transform อ่าน
นโยบายannotation-transform อ่าน
input.targetsระบุทุก ส่วน ประกอบ ที่ นโยบาย อาจ ใส่ คำ อธิบาย ประกอบ แต่ละ เป้า หมาย มี boundary_path,component_nameและannotationsที่ Release เขียนบน ส่วน ประกอบ นั้น โดย แต่ละ ค่า ตาม ที่ เขียน input.binding_keysระบุคีย์ คำ อธิบาย ประกอบ ที่ Manifest ผูก ไว้
aggrega build --release <release> --dry-run --policy-input <dir> เขียน<dir> และrelease.yaml เติม
aggrega build --release release.yaml --config governance-rego.yaml --dry-run --policy-input payloadsjq -c '.binding_keys' payloads/annotation-transform.json# ["feature.aggrega.ai/monitoring","aws-role"]jq -c '.targets[]' payloads/annotation-transform.json# {"boundary_path":"shop","component_name":"api","annotations":{}}# {"boundary_path":"shop","component_name":"worker","annotations":{}}# {"boundary_path":"shop","component_name":"gateway","annotations":{"feature.aggrega.ai/monitoring":{"interval":"10s","port":"metrics","path":"/metrics"}}}annotations ของaggrega.ai/namespace ของ
นโยบาย
policies/platform-defaults.rego รวบรวมannotations การ
annotations contains { "boundary_path": t.boundary_path, "component_name": t.component_name, "annotation_key": monitoring, "annotation_value": {"interval": "30s", "port": "metrics", "path": "/metrics"},} if { monitoring in input.binding_keys some t in input.targets not monitoring in object.keys(t.annotations)}
annotations contains { "boundary_path": t.boundary_path, "component_name": t.component_name, "annotation_key": role, "annotation_value": sprintf("arn:aws:iam::123456789012:role/shop-%v", [t.component_name]),} if { role in input.binding_keys some t in input.targets not role in object.keys(t.annotations)}แต่ละinput.binding_keys นโยบายgateway จะ
policies/platform-defaults.cel ระบุ+ คีย์in แทน object.keys และ ARN ของ+ เพราะsprintf ส่วน
+ input.targets .filter(t, "aws-role" in input.binding_keys && !("aws-role" in t.annotations)) .map(t, { "boundary_path": t.boundary_path, "component_name": t.component_name, "annotation_key": "aws-role", "annotation_value": "arn:aws:iam::123456789012:role/shop-" + t.component_name, }),สิ่งที่บิลด์เรนเดอร์
aggrega build --release release.yaml --config governance-rego.yaml --auto-pullเขียนdist/shop/helm/ ได้แก่ Deployment และ Service สำหรับaws-role ขยายspec ของ ServiceMonitor ของ api จาก
spec: selector: matchLabels: app.kubernetes.io/name: api endpoints: - port: metrics interval: 30s path: /metricsของ gateway มี interval: 10s ซึ่งapi รันaws-role ที่
apiVersion: v1kind: ServiceAccountmetadata: name: api-aws-role namespace: shop annotations: eks.amazonaws.com/role-arn: "arn:aws:iam::123456789012:role/shop-api" aggrega.ai/boundary-path: shop aggrega.ai/recipe-uri: "aws-irsa:1.0.0" [… omitted: the labels, which carry the version of the aggrega binary that built the file]แทรกเข้ามาหรือเขียนด้วยมือ: ได้ไฟล์เดียวกัน
release-by-hand.yaml คือ release.yaml ที่
aggrega build --release release-by-hand.yaml --auto-pullจะrelease.yaml ที่check.sh เปรียบ
บิลด์
ตำแหน่งที่บันทึกการแทรก
กราฟ--ir-graph พิมพ์aggrega.ai/injected-by ซึ่งaggrega build --release release.yaml --config governance-rego.yaml --auto-pull --ir-graph แล้ว api อ่าน
"release_annotations": { "aggrega.ai/namespace": "shop", "aws-role": "arn:aws:iam::123456789012:role/shop-api", "aggrega.ai/injected-by": "governance/rego"},บันทึกgateway ก็มีaws-role ของ"origin": "annotation" ใน
เป้าaggrega.ai/injected-by และapi อ่าน
warning: node "api" (provider "helm"): target "helm" does not support annotation aggrega.ai/injected-by on synthesized input and ignored it--no-unsupported-field-warnings ปิด
บทบาทนี้เพิ่มเพียงคำอธิบายประกอบ และไม่เพิ่มอะไรอื่น
การ
การnull จะnull คือ
สตริงในที่ที่การผูกกำหนดเส้นทางให้คีย์ย่อยสามคีย์
governance-monitoring-as-string.yaml แนบ policies/monitoring-as-string.rego ซึ่ง"30s" ไว้
aggrega build --release release.yaml --config governance-monitoring-as-string.yaml --auto-pullจะ1 และdist/ นโยบายapi และ worker และ
[… omitted: a warning that the attachment is in the global configuration named with --config][OPS_ERROR E0367] .spec.boundaries.shop.components.api.annotations a scalar annotation value does not route to exactly one path of its binding (Release shop-production, at .spec.boundaries.shop.components.api.annotations, "feature.aggrega.ai/monitoring", carrying the bare value "30s", whose binding routes "interval, port, path", whose value plugin "governance/rego" injected at governance role "annotation-transform")---[OPS_ERROR E0367] .spec.boundaries.shop.components.worker.annotations a scalar annotation value does not route to exactly one path of its binding (Release shop-production, at .spec.boundaries.shop.components.worker.annotations, "feature.aggrega.ai/monitoring", carrying the bare value "30s", whose binding routes "interval, port, path", whose value plugin "governance/rego" injected at governance role "annotation-transform")เมื่อไม่มีนโยบาย
release.yaml ที่
aggrega build --release release.yaml --auto-pullจะcore/prometheus-exporter และapi หรือ worker:
[DEVELOPER_ERROR E0162] aggregate.yaml at .spec.components.api missing required feature: attach a Feature of the required type to the component ("core/prometheus-exporter", required by component type "example/compute/service", under the requirement label "monitoring")---[DEVELOPER_ERROR E0162] aggregate.yaml at .spec.components.worker missing required feature: attach a Feature of the required type to the component ("core/prometheus-exporter", required by component type "example/compute/service", under the requirement label "monitoring")ไม่มีgateway เพราะ
สิ่งที่ไฟล์ล็อกบันทึก
การannotation-transform เปลี่ยนrelease.lock จะmutators: พร้อม
mutators: - plugin: governance/rego role: annotation-transform sources: - content: | [… omitted: the policy file, as written] digest: sha256:9779faf366fc131b1a56ea68ccbae811173e3642943909f8d4ca63c00df8781b path: platform-defaults.regoไฟล์plugins: ด้วย:
plugins: - uri: governance/rego [… omitted: the artifact digest, which depends on the aggrega binary that built it, recorded twice] referenced_from: - governance/rego:0.9.0การaggrega ของ
ร่างตัวอย่าง
คุณ
เขียน
aggrega draft --example policy-annotation-transformจาก
cd policy-annotation-transformบิลด์
aggrega build --release release.yaml --config governance-rego.yaml --auto-pullaggrega build --release release.yaml --config governance-cel.yaml --auto-pullaggrega build --release release-by-hand.yaml --auto-pullแค็ตตาล็อกhub.aggrega.ai ซึ่ง.aggrega-config.yaml ระบุ เมื่อ--catalog จะ--auto-pull เติม
กับผู้ช่วย AI
ผู้
ใช้เครื่องมือของ Aggrega เท่านั้น และไม่สร้างโฟลเดอร์เอง หากโฟลเดอร์พื้นที่ทำงานยังไม่มีโฟลเดอร์ `policy-annotation-transform` เรียกเครื่องมือ `draft` หนึ่งครั้งโดยตั้ง `example` เป็น `policy-annotation-transform` และไม่ระบุ `dir`: เครื่องมือจะเขียนตัวอย่างลงในโฟลเดอร์ `policy-annotation-transform` ใหม่ จากนั้นเรียกเครื่องมือ `cli-build` ซึ่งรัน `aggrega build` และรับแฟล็ก `--config` โดยตั้ง `workspace_root` เป็น `policy-annotation-transform` ตั้ง `release` เป็น `release.yaml` ตั้ง `auto_pull` เป็น true และตั้ง `config` เป็น `governance-rego.yaml` แล้วเรียกอีกครั้งในแบบเดียวกันโดยตั้ง `config` เป็น `governance-cel.yaml` สุดท้ายเรียกเครื่องมือ `build` โดยตั้ง `workspace_root` เป็น `policy-annotation-transform` ตั้ง `release` เป็น `release-by-hand.yaml` ตั้ง `auto_pull` เป็น true และตั้ง `write` เป็น true แจ้งฉันว่าแต่ละบิลด์เขียนไฟล์ใดบ้าง ไฟล์เหล่านั้นอยู่ใต้ `policy-annotation-transform/dist/`การตรวจสอบทุกบิลด์
การaggrega draft --example เขียน
./check.shcheck.sh ทำการ
release-by-hand.yamlที่ไม่มี นโยบาย เป็น ฐาน อ้างอิง ต้อง เรนเดอร์ ไฟล์ หก ไฟล์ ที่ คำ อธิบาย ประกอบ ขยาย เป็น release.yamlที่ไม่มี นโยบาย ต้อง หยุด ด้วย E0162สำหรับapiและworkerและไม่ หยุด สำหรับ ส่วน ประกอบ อื่น release.yamlที่มี นโยบาย บิลด์ หนึ่ง รอบ บน แต่ละ เอนจิน แต่ละ บิลด์ ต้อง เขียน ไฟล์ ของ ฐาน อ้างอิง ทุก ไบต์ ปัก หมุด ปลั๊กอิน ใน ไฟล์ ล็อก และ บันทึก ว่า ส่วน ประกอบ ทั้ง สาม รายการ ถูก แทรก โดย ปลั๊กอิน นั้น release.yamlที่มี สตริง ที่ ฝัง ไว้ ต้อง หยุด ด้วย การ ปฏิเสธ ข้าง ต้น
พิมพ์
POLICY RELEASE EXIT EXPECTED VERDICT----------------------------------------------------------------------------------------------------none release-by-hand.yaml 0 reference OK: the six attachments' filesnone release.yaml 1 halt OK: E0162 for api and workerrego release.yaml 0 pass OK: byte-identical to the build by hand; pinned; injectedcel release.yaml 0 pass OK: byte-identical to the build by hand; pinned; injectedstring release.yaml 1 halt OK: refused, naming the plugin and its role
files the two annotation bindings rendered, release.yaml with governance-rego.yaml: shop/helm/api--aws-role--api-serviceaccount-shop-api-aws-role.yaml shop/helm/api--feature-zdaggrega-zdai-zsmonitoring--api-servicemonitor-shop-api-scrape.yaml shop/helm/gateway--aws-role--gateway-serviceaccount-shop-gateway-aws-role.yaml shop/helm/gateway--feature-zdaggrega-zdai-zsmonitoring--gateway-servicemonitor-shop-gateway-scrape.yaml shop/helm/worker--aws-role--worker-serviceaccount-shop-worker-aws-role.yaml shop/helm/worker--feature-zdaggrega-zdai-zsmonitoring--worker-servicemonitor-shop-worker-scrape.yaml
check: every build ended as expected.แต่ละ.aggrega-config.yaml ของAGGREGA_BIN กำหนด-- ส่ง
ตำแหน่งที่คอมไพเลอร์ไม่ตีความ
คอมไพเลอร์
ไฟล์
aggregate.yaml— บริการสาม รายการ โดย ไม่มี คำ อธิบาย ประกอบ manifest.yaml— ผูกชนิด ของ ส่วน ประกอบ และ Features ทั้ง สอง เข้า กับ Recipes ของ Helm และ ผูก คีย์ คำ อธิบาย ประกอบ สอง คีย์ เข้า กับ Features ทั้ง สอง release.yaml— Release ที่นโยบาย ใส่ คำ อธิบาย ประกอบ ให้ มี เพียง gatewayที่เขียน คำ อธิบาย ประกอบ release-by-hand.yaml— กลุ่มควบคุม: คำ อธิบาย ประกอบ ทุก รายการ เขียน ด้วย มือ .aggrega-config.yaml— รีจิสทรีเริ่ม ต้น ไม่มี การ แนบ ด้าน การ กำกับ ดูแล governance-rego.yaml,governance-cel.yaml— นโยบายที่ แนบ ที่ annotation-transformผ่านแต่ละ เอนจิน โดย แต่ละ ไฟล์ ระบุ ด้วย --configgovernance-monitoring-as-string.yaml— ข้อผิด พลาด ที่ ฝัง ไว้ ระบุ ด้วย --configpolicies/platform-defaults.rego,policies/platform-defaults.cel— นโยบาย หนึ่งไฟล์ ต่อ เอนจิน policies/monitoring-as-string.rego— ข้อผิด พลาด ที่ ฝัง ไว้ build-release.sh— บิลด์ Release หนึ่งรายการ พร้อม พิมพ์ คำ สั่ง aggrega buildที่เทียบ เท่า ออก มา check.sh— ทำการบิลด์ ห้า รอบ และ ตรวจ สอบ ผล ของ แต่ละ รอบ