บล็อก `assertions:`
Component, Feature, Recipe และ FeatureRecipe มีspec.assertions: ซึ่งassertions: ไม่ใช่
สำหรับschema: สำหรับ predicate แบบvalidate: ของwhen: ฟิลด์ assertions: เสริม
ตำแหน่งที่ฟิลด์ปรากฏ
เอนทิตีassertions::
- Component — ข้อ
คงที่ เชิง สถาปัตยกรรม ของ สัญญา ของ Component - Feature — ข้อ
คงที่ เชิง สถาปัตยกรรม ของ สัญญา ของ Feature - Recipe — ข้อ
คงที่ ใน การ อิมพลีเมนต์ ของ chart หรือ โมดูล ที่ อยู่ เบื้อง หลัง Recipe - FeatureRecipe — ข้อ
คงที่ ใน การ อิมพลีเมนต์ ของ กลไก ที่ อยู่ เบื้อง หลัง FeatureRecipe
ฟิลด์
เวลาที่ assertions รัน
ช่วง
- การ
หา ค่า: การ ตรวจ สอบ ความ ถูก ต้อง ของ พารามิเตอร์ และ การ แทน ค่า จาก นั้น การ ตรวจ สอบ ความ ถูก ต้อง ของ สคีมา เทียบ กับ schema:/usesSchema:/featuresSchema: - การ
สร้าง โทโพโลยี และ การ สรุป กราฟ: ประกอบ กราฟ - การ
วิเคราะห์ แบบ สถิต: ตรวจ ตัว คัด เลือก ของ ซ็อกเก็ต uses:แต่ละตัว เทียบ กับ ป้าย กำกับ ของ ส่วน ประกอบ ที่ การ เชื่อม ต่อ ของ ซ็อกเก็ต นั้น ไป ถึง - assertions ของ Component / Feature ประเมิน
ค่า เทียบ กับ แต่ละ อินสแตนซ์ - การ
ผูก Recipe - assertions ของ Recipe / FeatureRecipe ประเมิน
ค่า เทียบ กับ อินสแตนซ์ ที่ ผูก แล้ว - การ
เรนเดอร์: ประเมิน ค่า เทมเพลต การ แมป สร้าง เอาต์พุต
ช่วงprovides ของ Recipe อาจ
การ
บริบทเทมเพลต
สำหรับ assertions: ของ Component และ Feature บริบท
.values— เนื้อหาvaluesของนัก พัฒนา .infra— เนื้อหาinfraของฝ่าย ปฏิบัติ การ (จาก Aggregate หรือ Release) .uses— การเชื่อม ต่อ uses:ที่หา ชื่อค่า แล้ว ซึ่ง แต่ละ รายการ ผ่าน การ ตรวจ กับ ตัว คัด เลือก ของ ซ็อกเก็ต แล้ว ใน รูป ทรง ที่ ผู้ เขียน เขียน ไว้ โดย ใช้ ซ็อกเก็ต เป็นคีย์ และ นามแฝง ของภาย ใต้ แต่ละ ซ็อกเก็ต ใช้ ทุก การ เชื่อม ต่อ บน ซ็อกเก็ต นั้น เป็น คีย์ คือ ชื่อ ที่ ผู้ เขียน ตั้ง ให้การ เชื่อม ต่อ ภาย ใต้ ซ็อกเก็ต หรือ สำหรับ การ เชื่อม ต่อ ที่ เขียน เป็น หนึ่ง รายการ ใน รายการ คือ เป้า หมาย ของ การ เชื่อม ต่อ นั้น รายการ ของ แต่ละ การ เชื่อม ต่อ อธิบาย การ เชื่อม ต่อ นั้น และ ไม่มี สิ่ง ใด ที่ เป้า หมาย เผย แพร่ เลย targetคือ id ของอินสแตนซ์ ของ เป้า หมาย ที่ หา ค่า แล้ว aliasซ้ำชื่อ ที่ ใช้ เป็น คีย์ และ origin_featureมีอยู่ เมื่อ การ แนบ Feature เป็น ผู้ ทำให้ เกิด การ เชื่อม ต่อ นั้น ข้าง กัน มี ข้อ เท็จ จริง สาม ข้อ ภาย ใต้ ชื่อ ที่ เทมเพลต ของ Recipe ใช้ อ่าน ใน รายการ .context.uses.<alias>ของการ template-context-contract.md อธิบายเชื่อม ต่อ เดียวกัน ซึ่ง ว่า แต่ละ ข้อ เก็บ อะไร: labels— ป้ายกำกับ เป้าของ หมาย ไม่ใช่ป้าย กำกับ ของ ส่วน ประกอบ ที่ assertion ทำงาน อยู่ เลย — valuesคือค่าที่ เขียน บน การ เชื่อม ต่อ และ featuresคือการ แนบ ที่ เขียน บน การ เชื่อม ต่อ โดย ใช้ สล็อต ที่ แต่ละ การ แนบ เติม เป็น คีย์ ทั้ง สาม ข้อ มี อยู่ ใน ทุก การ เชื่อม ต่อ และ ว่าง เมื่อ การ เชื่อม ต่อ ไม่มี ส่วน การ แนบ ภาย ใต้ featuresมีรูป ทรง เดียว กับ ที่ .featuresให้ไว้ ด้าน ล่าง ดัง นั้น .uses.<socket>.<alias>.targetอ่านเป้า หมาย ที่ หา ค่า แล้ว ของ การ เชื่อม ต่อ หนึ่ง รายการ .uses.<socket>.<alias>.labelsอ่านป้าย กำกับ ของ เป้า หมาย นั้น ซ็อกเก็ต ที่ มี หลาย การ เชื่อม ต่อ มี รายการ สำหรับ แต่ละ การ เชื่อม ต่อ และ การ อ้างอิง ที่ ผ่าน แมป นี้ ไป ยัง ค่าที่ เป้า หมาย เผย แพร่ จะ หยุด บิลด์ เพราะ รายการ ไม่มี ฟิลด์ ดัง กล่าว .features— การแนบ ที่ หา ค่า แล้ว โดย ใช้ ชื่อ อินสแตนซ์ ที่ ผู้ เขียน ตั้ง ให้ แต่ละ รายการ เป็น คีย์ แต่ละ รายการ มี type(URI ในแค็ตตาล็อก ของ Feature ที่ แนบ) resolved_version(เวอร์ชันที่ ผูก สำหรับ การ บิลด์ นี้) และ values(เนื้อหาเจตนา ของ นัก พัฒนา ที่ เป็น ของ การ แนบ นั้น เอง) การ แนบ ที่ เขียน บน การ เชื่อม ต่อ ของ ส่วน ประกอบ จะ ไม่ อยู่ ใน นี้ เช่น เดียว กับ ที่ ไม่ อยู่ ใน .featuresของเทมเพลต Recipe แต่ อ่าน ได้ ภาย ใต้ การ เชื่อม ต่อ ของ การ แนบ นั้น ที่ .uses.<socket>.<alias>.features.<slot>ในรูป ทรง เดียวกัน นี้ .metadata— อินสแตนซ์ที่ กำลัง ประเมิน ค่า ได้แก่ instance_idชนิดcomponentและresolved_versionboundary_pathและaggregate_name,aggregate_versionและrelease_versionของการ บิลด์
สำหรับ assertions: ของ Recipe และ FeatureRecipe บริบท
.provides— ค่าprovides:ที่หา เป้าค่า แล้ว ของ ส่วน ประกอบ ที่ กำลัง ประเมิน ค่า ซึ่ง คำนวณ เสร็จ แล้ว ก่อน ที่ assertion จะ ทำงาน ค่าที่ หมาย เผยแพร่ ไม่ อยู่ บน พื้น ผิว นี้ แต่ ไป ถึง ผู้ เรียก ใน บริบท การ เรนเดอร์ แทน .locals— locals ของ Recipe.recipe.metadata—nameและversionของ Recipe และcapabilityของ Recipe.recipe.source— ตัวชี้ ซอร์ส ของ Recipe
การ.values.architecture, .uses.databases.primary.target) โครงสร้าง{{ fail "message" }} ตาม
พื้นmissingkey=error การ
การ
uses: models: local: { target: llama } fast: { target: turbo }assertions เหล่า
assertions: # The socket's presence: the socket key alone, however many connections it holds. models-wired: | {{- if not (hasKey .uses "models") -}} {{- fail "wire at least one model to the models socket" -}} {{- end -}} # Every connection on the socket: a range visits each one. every-model-distinct: | {{- $seen := list -}} {{- range $alias, $connection := (optional .uses "models" dict) -}} {{- if has $connection.target $seen -}} {{- fail (printf "connection %s points at %s, which another models connection already points at" $alias $connection.target) -}} {{- end -}} {{- $seen = append $seen $connection.target -}} {{- end -}} # One connection, by the alias it was written under; guarded, because the # connection is optional. fast-is-not-local: | {{- with (optional .uses "models" dict) -}} {{- if and (hasKey . "fast") (hasKey . "local") (eq .fast.target .local.target) -}} {{- fail (printf "the fast and local connections both point at %s" .local.target) -}} {{- end -}} {{- end -}}การfast มาlocal — ไม่ใช่.uses.models.local.target อ่านllama ไม่fast จะ.uses.models.target ไม่
ทุกlocal ของlocal ของ
การmodels ประกาศunauthenticated และcredential ปฏิเสธ
assertions: hosted-model-needs-a-credential: | {{- range $alias, $connection := (optional .uses "models" dict) -}} {{- $hosted := eq (optional $connection.labels "component.aggrega.ai/hosting" "") "managed" -}} {{- $optedOut := optional $connection.values "unauthenticated" false -}} {{- if and $hosted (not (hasKey $connection.features "credential")) (not $optedOut) -}} {{- fail (printf "the models connection %s reaches a hosted model with no credential: attach one under credential, or set unauthenticated: true on the connection" $alias) -}} {{- end -}} {{- end -}}ป้ายlabels ซึ่งvalues ของfeatures ของoptional หรือ hasKey เพราะ
.uses ของ assertion ไม่ใช่ .context.uses ของprovides — เทมเพลต Recipe จึง.context.uses.<alias>.provides.<name> ใน.uses.<socket>.<alias>.target ข้อ.context.uses.<alias>.labels และ .uses.<socket>.<alias>.labels คือvalues กับ features ก็provides
สำหรับ
ตัวเลขบนพื้นผิวนี้
assertion อ่าน
- การ
เปรียบ การเทียบ เปรียบ เทียบ ทั้ง หก แบบ อ่าน ตัวเลข สอง ตัว ตาม ค่า ไม่ ว่า แต่ละ ตัว จะ เป็น ประเภท ใด lt .values.replicas 1.5และeq .values.replicas 3.0ให้ผล ที่ นี่ เหมือน กับ บน เทมเพลต ค่า 0.1ที่ผู้ เขียน เขียน ไว้ ถือว่า eqกับ0.1ที่เขียน ใน assertion และ การ เปรียบ เทียบ ตัวเลข กับ ข้อความ ที่ อยู่ ใน เครื่องหมาย อัญประกาศ จะ หยุด ด้วย ถ้อยคำ เดียวกัน - ความ
ว่าง เปล่า 0ที่ผู้ เขียน เขียน ไว้ ถือว่า ว่าง เป็น เท็จ สำหรับ ifและwithเป็นจริง สำหรับ emptyและถูก แทนที่ ด้วย defaultกฎที่ ถาม ว่า ผู้ เขียน เขียน ค่า ไว้ หรือ ไม่ — รวม ถึง 0— ถามด้วย ตัว ช่วย ตรวจ การ มี อยู่ สำหรับ 0ที่ผู้ เขียน เขียน ไว้ hasKey .values "replicas"เป็นจริง และ optional .values "replicas" 1คืนค่า 0กฎที่ ถาม ว่า ค่า เป็น ศูนย์ หรือ ไม่ ใช้ การ เปรียบ เทียบ eq .values.replicas 0การมี วางอยู่ และ ความ ว่าง เปล่า สอง คำถาม นี้ เทียบ กัน ไว้ - การ
พิมพ์ ตัวเลขที่ ข้อความ failพิมพ์ออก มา อ่าน ได้ เหมือน ใน เอาต์พุต ของ เทมเพลต ค่า จำนวนเต็ม พิมพ์ เป็น จำนวนเต็ม ดัง นั้น printf "%d"จึงพิมพ์ ตัวเลข ทุก หลัก ของ จำนวน นั้น และ ตัวเลข อื่น พิมพ์ ใน รูป ทศนิยม ที่ สั้น ที่สุด ที่ ตรง ทุก ประการ ดัง นั้น 0.0000001ที่ผู้ เขียน เขียน ไว้ จึง อ่าน เป็น 0.0000001
assertions ของ Component / Feature — ข้อคงที่เชิงสถาปัตยกรรม
สิ่ง
apiVersion: aggrega.ai/v1beta1kind: Componentmetadata: name: core/datastore/mariadb version: 1.0.0 labels: component.aggrega.ai/type: stateful-server component.aggrega.ai/category: datastorespec: schema: values: architecture: { type: string, enum: [standalone, replication], default: standalone } primary: replicaCount: { type: integer, min: 1, max: 9, default: 1 } secondary: replicaCount: { type: integer, min: 0, max: 9, default: 0 }
assertions: # Replication mode requires at least 2 secondary replicas. replication-needs-two-secondaries: | {{- if eq .values.architecture "replication" -}} {{- if lt .values.secondary.replicaCount 2 -}} {{- fail "architecture=replication requires secondary.replicaCount >= 2" -}} {{- end -}} {{- end -}}
# Total node count limit for safe replication coordination. total-node-count-within-cap: | {{- $total := add .values.primary.replicaCount .values.secondary.replicaCount -}} {{- if gt $total 9 -}} {{- fail (printf "total node count must not exceed 9; got %d" $total) -}} {{- end -}}ทั้ง
การ{{- ... -}} มี{{ fail }} การ
assertions ของ Recipe / FeatureRecipe — ข้อคงที่เชิงการอิมพลีเมนต์
สิ่ง
apiVersion: aggrega.ai/v1beta1kind: Recipemetadata: name: bitnami/datastore/mariadb/k8s version: 1.0.0spec: capability: helm implements: core/datastore/mariadb:^1.0.0 source: # Keys this provider defines for itself; a source the build fetches is written as { kind, url, version } instead. chart: oci://registry-1.docker.io/bitnamicharts/mariadb version: "20.0.0"
valuesMapping: $import: BitnamiHelpers#/mappings/MariaDBBitnamiCore
assertions: # Bitnami chart 20.x requires an explicit ServiceMonitor namespace when # replication and metrics scraping are both enabled. service-monitor-namespace-required: | {{- if and (eq .values.architecture "replication") .values.metrics.serviceMonitor.enabled -}} {{- if not .values.metrics.serviceMonitor.namespace -}} {{- fail "Bitnami MariaDB 20.x requires metrics.serviceMonitor.namespace when architecture=replication and metrics.serviceMonitor.enabled=true" -}} {{- end -}} {{- end -}}
# ARM-node incompatibility. arm-rejects-hard-anti-affinity: | {{- if and (eq .values.primary.podAntiAffinityPreset "hard") (eq .infra.cpu_arch "arm64") -}} {{- fail "Bitnami MariaDB 20.x is incompatible with ARM nodes when podAntiAffinityPreset=hard; use 'soft' or omit" -}} {{- end -}}แต่ละreplication-needs-two-secondaries, total-node-count-within-cap) ยัง
เหตุใด assertions ของ Component และ Recipe จึงแยกจากกัน
สอง{{ fail }} เพื่อ
- assertions ของ Component เป็น
ส่วน เมื่อหนึ่ง ของ สัญญา นัก พัฒนา เขียน architecture: replicationร่วมกับ secondary.replicaCount: 1การบิลด์ จะ ปฏิเสธ ไม่ ว่า Recipe ใด จะ ผูก Recipe ทาง เลือก ใน อนาคต ไม่ เปลี่ยน สิ่ง นี้ - assertions ของ Recipe เป็น
ส่วน เมื่อหนึ่ง ของ การ อิมพลีเมนต์ สถาปนิก เลือก chart ของ Bitnami 20.x เป็น Recipe chart นั้น มี ลักษณะ เฉพาะ ตัว (ข้อ กำหนด serviceMonitor.namespaceและบั๊ก ของ โหนด ARM) สิ่ง เหล่า นี้ ไม่ ใช้ กับ chart อื่น
การE0033 โดย
ธรรมเนียมข้อความ fail
อาร์กิวเมนต์{{ fail "..." }} คือ
- ระบุ
ข้อ — “architecture=replication requires secondary.replicaCount >= 2”จำกัด - ระบุ
ค่า — “total node count must not exceed 9; got 12”เมื่อ เกี่ยวข้อง - เสนอ
วิธี — “use ‘soft’ or omit the field”แก้ เมื่อ เป็น ไป ได้ - หลีก
เลี่ยง — ผู้ศัพท์ เฉพาะ อ่าน คือ นัก พัฒนา ที่ เขียน Aggregate ไม่ใช่ สถาปนิก ที่ เขียน assertion
สำหรับprintf:
{{- fail (printf "field %s exceeds limit: got %d, max is %d" .field .value .max) -}}คอมไพเลอร์
ค่าที่sensitive: true จะ<redacted> ในvocabulary/compact-form-authoring.md “สิ่ง
สิ่งที่ assertions: ไม่ได้มาแทนที่
assertions: คือ
- ข้อ
จำกัด ของ JSON Schema ภายใน schema:— กฎราย ฟิลด์ (range, pattern, enum, format, type) อยู่ ใน คีย์เวิร์ด เนทีฟ ของ JSON Schema - ฟิลด์
validate:ของรูป — predicate แบบแบบ กะทัดรัด กำหนด เอง ราย ฟิลด์ ที่ มี ขอบเขต เป็น ฟิลด์ เดียว ใช้ validate:เมื่อกฎ ใช้ กับ ฟิลด์ ใด ฟิลด์ หนึ่ง ใช้ assertions:เมื่อกฎ เกี่ยวข้อง กับ หลาย ฟิลด์ ที่ ไม่มี ฟิลด์ ใด ฟิลด์ เดียว เป็น “ฟิลด์ ที่ กำลัง ถูก ตรวจ สอบ ความ ถูก ต้อง” - ฟิลด์
when:ของรูป — รูปแบบ กะทัดรัด ทรง ตามเงื่อนไข (ว่า ข้อ จำกัด ของ ทรี ย่อย ใช้ หรือ ไม่) ใช้ when:สำหรับความ แตก ต่าง ของ รูป ทรง ใช้ assertions:เมื่อ การผสม ไม่กัน ของ ค่า ถูก ต้อง ใน แบบ ที่ แสดง เป็น predicate รูป แบบ อิสระ ได้ ดี กว่า - การ
ตรวจ —สอบ ขณะ รัน assertions:ทำงานขณะ คอมไพล์ เท่านั้น สิ่ง ใด ที่ ขึ้น กับ สถานะ คลัสเตอร์ ขณะ รัน (IP ที่ ใช้ งาน จริง เนื้อหา ของ vault สถานะ pod ขณะ รัน) ต้อง แสดง เป็น สตริง ตัว ชี้ ที่ กำหนด แน่นอน — ดู สัญญา ความ บริสุทธิ์ แบบ AOT (AOT Purity)
ตัวอย่างที่แสดงวิธีทำ
ขั้นต่ำ — กฎเชิงสถาปัตยกรรมข้อเดียว
spec: assertions: replication-needs-two-secondaries: | {{- if and (eq .values.architecture "replication") (lt .values.secondary.replicaCount 2) -}} {{- fail "replication requires secondary.replicaCount >= 2" -}} {{- end -}}ขนาดกลาง — สัญญา Component ที่มีหลายกฎ
spec: assertions: # Replication minimum. replication-needs-two-secondaries: | {{- if eq .values.architecture "replication" -}} {{- if lt .values.secondary.replicaCount 2 -}} {{- fail "architecture=replication requires secondary.replicaCount >= 2" -}} {{- end -}} {{- end -}}
# Total node limit. total-node-count-within-cap: | {{- $total := add .values.primary.replicaCount .values.secondary.replicaCount -}} {{- if gt $total 9 -}} {{- fail (printf "total node count exceeds 9: got %d (primary=%d, secondary=%d)" $total .values.primary.replicaCount .values.secondary.replicaCount) -}} {{- end -}}
# A ServiceMonitor scrapes the metrics exporter, so it needs one. service-monitor-needs-metrics: | {{- if and .values.metrics.serviceMonitor.enabled (not .values.metrics.enabled) -}} {{- fail "metrics.serviceMonitor.enabled=true requires metrics.enabled=true" -}} {{- end -}}ระดับใช้งานจริง — Recipe ที่มีกฎของการอิมพลีเมนต์
spec: assertions: # Bitnami 20.x: serviceMonitor namespace requirement. service-monitor-namespace-required: | {{- if and (eq .values.architecture "replication") .values.metrics.serviceMonitor.enabled -}} {{- if not .values.metrics.serviceMonitor.namespace -}} {{- fail "Bitnami MariaDB 20.x requires metrics.serviceMonitor.namespace when architecture=replication and metrics.serviceMonitor.enabled=true" -}} {{- end -}} {{- end -}}
# TLS certificate consistency. tls-needs-both-certificate-files: | {{- if .values.tls.enabled -}} {{- if not (and .values.tls.certFilename .values.tls.certKeyFilename) -}} {{- fail "tls.enabled=true requires both tls.certFilename and tls.certKeyFilename" -}} {{- end -}} {{- end -}}
# Replication-mode storage class consistency. replication-needs-one-storage-class: | {{- if eq .values.architecture "replication" -}} {{- $primaryClass := .values.primary.persistence.storageClass -}} {{- $secondaryClass := .values.secondary.persistence.storageClass -}} {{- if and $primaryClass $secondaryClass (ne $primaryClass $secondaryClass) -}} {{- fail "replication mode requires primary and secondary to use the same storageClass" -}} {{- end -}} {{- end -}}การผสานรวมเครื่องมือ
aggrega buildประเมินค่า assertions ระหว่าง การ ตรวจ สอบ ความ ถูก ต้อง ของ สคีมา กับ การ เรนเดอร์ assertion ที่ ล้ม เหลว หยุด การ บิลด์ ด้วย ข้อความ {{ fail }}ของ assertion นั้นaggrega validateนำความ ถูก ต้อง แบบ เดียวกัน ไป ใช้ ก่อน การ เรนเดอร์ โดย ไม่ เขียน อาร์ติแฟกต์ — สำหรับ Recipe ที่ ไม่ ได้ ดึง ซอร์ส จะ รัน ไปป์ไลน์ การ คอมไพล์ จริง รอบ Aggregate, Manifest และ Release ขั้น ต่ำ ที่ สังเคราะห์ ขึ้น ดัง นั้น เทมเพลต assertion ที่ รูป แบบ ผิด หรือ assertion ที่ อ้างอิง ฟิลด์ ที่ ไม่รู้ จัก จะ ปรากฏ เป็น ข้อ ผิด พลาด ด้าน ความ ถูก ต้อง ส่วน assertions ของ Recipe ที่ ดึง ซอร์ส จะ ถูก ประเมิน ค่า โดย การ บิลด์ assertion ใน กรณี นั้น ที่ เรียก failจะถูก assertion ที่รายงาน เป็น คำ เตือน ที่ มี ข้อความ ของ assertion นั้น และ การ ตรวจ สอบ ผ่าน เพราะ Release ที่ สังเคราะห์ ขึ้น มี ตัว ยึด ตำแหน่ง และ ค่า เริ่ม ต้นแทน ค่าที่ Release จริง กำหนด คำ ตัดสิน ของ assertion จึง ปล่อย ให้การ บิลด์ เป็น ผู้ ทำ — ดู ล้ม (เหลว คือ คำ เตือน aggrega lintครอบคลุมธรรมเนียม การ เผย แพร่ ไม่ใช่ ความ ถูก ต้อง ของ assertion) - IDE ที่
รองรับ เทมเพลต Sprig จะ ไฮไลต์ การ อ้างอิง .values.Xเอกสารประกอบ ที่ แสดง เมื่อ วาง เมาส์ จะ หา ค่า ไป ยัง นิยาม สคีมา เมื่อ กำหนด ค่า การ ผสาน รวม IDE ไว้