@intentius/chant-lexicon-k8s 0.46.0 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/dist/components/kubectl-apply.d.ts +5 -0
  2. package/dist/components/kubectl-apply.d.ts.map +1 -1
  3. package/dist/composites/flux-app.d.ts +12 -0
  4. package/dist/composites/flux-app.d.ts.map +1 -1
  5. package/dist/composites/index.d.ts +8 -0
  6. package/dist/composites/index.d.ts.map +1 -1
  7. package/dist/composites/inference-service.d.ts +86 -0
  8. package/dist/composites/inference-service.d.ts.map +1 -0
  9. package/dist/composites/model.d.ts +80 -0
  10. package/dist/composites/model.d.ts.map +1 -0
  11. package/dist/composites/operator-stack.d.ts +183 -0
  12. package/dist/composites/operator-stack.d.ts.map +1 -0
  13. package/dist/composites/vllm-serving-runtime.d.ts +100 -0
  14. package/dist/composites/vllm-serving-runtime.d.ts.map +1 -0
  15. package/dist/crd/crd-sources.d.ts.map +1 -1
  16. package/dist/deep-observe-hooks.d.ts.map +1 -1
  17. package/dist/generated/index.d.ts +167 -40
  18. package/dist/generated/index.d.ts.map +1 -1
  19. package/dist/group-namespace.d.ts.map +1 -1
  20. package/dist/index.d.ts +3 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/integrity.json +41 -33
  23. package/dist/kube/apply.d.ts.map +1 -1
  24. package/dist/lint/audit-catalog.d.ts.map +1 -1
  25. package/dist/lint/post-synth/argo-helpers.d.ts.map +1 -1
  26. package/dist/lint/post-synth/crd-schema-helpers.d.ts.map +1 -1
  27. package/dist/lint/post-synth/index.d.ts.map +1 -1
  28. package/dist/lint/post-synth/k8s-helpers.d.ts +56 -6
  29. package/dist/lint/post-synth/k8s-helpers.d.ts.map +1 -1
  30. package/dist/lint/post-synth/sops-helpers.d.ts +38 -0
  31. package/dist/lint/post-synth/sops-helpers.d.ts.map +1 -0
  32. package/dist/lint/post-synth/wk8005.d.ts.map +1 -1
  33. package/dist/lint/post-synth/wk8006.d.ts.map +1 -1
  34. package/dist/lint/post-synth/wk8041.d.ts.map +1 -1
  35. package/dist/lint/post-synth/wk8042.d.ts.map +1 -1
  36. package/dist/lint/post-synth/wk8101.d.ts.map +1 -1
  37. package/dist/lint/post-synth/wk8102.d.ts.map +1 -1
  38. package/dist/lint/post-synth/wk8103.d.ts.map +1 -1
  39. package/dist/lint/post-synth/wk8104.d.ts.map +1 -1
  40. package/dist/lint/post-synth/wk8105.d.ts.map +1 -1
  41. package/dist/lint/post-synth/wk8201.d.ts.map +1 -1
  42. package/dist/lint/post-synth/wk8202.d.ts.map +1 -1
  43. package/dist/lint/post-synth/wk8203.d.ts.map +1 -1
  44. package/dist/lint/post-synth/wk8204.d.ts.map +1 -1
  45. package/dist/lint/post-synth/wk8205.d.ts.map +1 -1
  46. package/dist/lint/post-synth/wk8207.d.ts.map +1 -1
  47. package/dist/lint/post-synth/wk8208.d.ts.map +1 -1
  48. package/dist/lint/post-synth/wk8209.d.ts.map +1 -1
  49. package/dist/lint/post-synth/wk8301.d.ts.map +1 -1
  50. package/dist/lint/post-synth/wk8302.d.ts.map +1 -1
  51. package/dist/lint/post-synth/wk8303.d.ts.map +1 -1
  52. package/dist/lint/post-synth/wk8304.d.ts.map +1 -1
  53. package/dist/lint/post-synth/wk8305.d.ts.map +1 -1
  54. package/dist/lint/post-synth/wk8306.d.ts.map +1 -1
  55. package/dist/lint/post-synth/wk8401.d.ts.map +1 -1
  56. package/dist/lint/post-synth/wk8402.d.ts.map +1 -1
  57. package/dist/lint/post-synth/wk8403.d.ts.map +1 -1
  58. package/dist/lint/post-synth/wk8404.d.ts +12 -0
  59. package/dist/lint/post-synth/wk8404.d.ts.map +1 -0
  60. package/dist/lint/post-synth/wk8405.d.ts +13 -0
  61. package/dist/lint/post-synth/wk8405.d.ts.map +1 -0
  62. package/dist/lint/post-synth/wk8406.d.ts +12 -0
  63. package/dist/lint/post-synth/wk8406.d.ts.map +1 -0
  64. package/dist/lint/post-synth/wk8407.d.ts +21 -0
  65. package/dist/lint/post-synth/wk8407.d.ts.map +1 -0
  66. package/dist/lint/post-synth/wk8503.d.ts +39 -0
  67. package/dist/lint/post-synth/wk8503.d.ts.map +1 -0
  68. package/dist/lint/post-synth/wk8504.d.ts +28 -0
  69. package/dist/lint/post-synth/wk8504.d.ts.map +1 -0
  70. package/dist/lint/post-synth/wk8505.d.ts +28 -0
  71. package/dist/lint/post-synth/wk8505.d.ts.map +1 -0
  72. package/dist/manifest.json +1 -1
  73. package/dist/meta.json +1039 -68
  74. package/dist/okf/index.md +26 -2
  75. package/dist/okf/rules/FLUX002.md +0 -1
  76. package/dist/okf/rules/WK8404.md +11 -0
  77. package/dist/okf/rules/WK8405.md +17 -0
  78. package/dist/okf/rules/WK8406.md +11 -0
  79. package/dist/okf/rules/WK8407.md +15 -0
  80. package/dist/okf/rules/WK8503.md +17 -0
  81. package/dist/okf/rules/WK8504.md +11 -0
  82. package/dist/okf/rules/WK8505.md +15 -0
  83. package/dist/okf/types/AWSClusterControllerIdentity.md +14 -0
  84. package/dist/okf/types/AWSManagedCluster.md +14 -0
  85. package/dist/okf/types/AWSManagedControlPlane.md +14 -0
  86. package/dist/okf/types/AWSManagedMachinePool.md +14 -0
  87. package/dist/okf/types/CAPICluster.md +14 -0
  88. package/dist/okf/types/Certificate.md +1 -0
  89. package/dist/okf/types/ClusterResourceSet.md +14 -0
  90. package/dist/okf/types/ClusterServingRuntime.md +14 -0
  91. package/dist/okf/types/{Cluster.md → CnpgCluster.md} +2 -2
  92. package/dist/okf/types/DBInstance.md +14 -0
  93. package/dist/okf/types/{Bucket.md → FluxBucket.md} +2 -6
  94. package/dist/okf/types/HelmChartProxy.md +14 -0
  95. package/dist/okf/types/IamRole.md +14 -0
  96. package/dist/okf/types/InferenceService.md +19 -0
  97. package/dist/okf/types/InfisicalDynamicSecret.md +4 -0
  98. package/dist/okf/types/InfisicalSecret.md +4 -0
  99. package/dist/okf/types/Kustomization.md +1 -0
  100. package/dist/okf/types/MachinePool.md +14 -0
  101. package/dist/okf/types/PDB.md +1 -0
  102. package/dist/okf/types/PodIdentityAssociation.md +14 -0
  103. package/dist/okf/types/Policy.md +14 -0
  104. package/dist/okf/types/S3Bucket.md +14 -0
  105. package/dist/okf/types/ServingRuntime.md +14 -0
  106. package/dist/okf/types/StatefulSet.md +1 -0
  107. package/dist/okf/types/User.md +14 -0
  108. package/dist/op/activities/ensure-secret.d.ts +41 -0
  109. package/dist/op/activities/ensure-secret.d.ts.map +1 -0
  110. package/dist/op/activities/index.d.ts +2 -0
  111. package/dist/op/activities/index.d.ts.map +1 -1
  112. package/dist/op/activities/kubectl.d.ts +9 -0
  113. package/dist/op/activities/kubectl.d.ts.map +1 -1
  114. package/dist/op/activities/wait-for-ready.d.ts.map +1 -1
  115. package/dist/op/builders.d.ts +69 -0
  116. package/dist/op/builders.d.ts.map +1 -0
  117. package/dist/plugin.d.ts.map +1 -1
  118. package/dist/rules/argo-helpers.ts +2 -6
  119. package/dist/rules/crd-schema-helpers.ts +4 -6
  120. package/dist/rules/k8s-helpers.ts +87 -24
  121. package/dist/rules/sops-helpers.ts +76 -0
  122. package/dist/rules/wk8005.ts +27 -32
  123. package/dist/rules/wk8006.ts +33 -38
  124. package/dist/rules/wk8041.ts +19 -24
  125. package/dist/rules/wk8042.ts +17 -22
  126. package/dist/rules/wk8101.ts +29 -34
  127. package/dist/rules/wk8102.ts +13 -18
  128. package/dist/rules/wk8103.ts +17 -22
  129. package/dist/rules/wk8104.ts +30 -35
  130. package/dist/rules/wk8105.ts +16 -21
  131. package/dist/rules/wk8201.ts +26 -31
  132. package/dist/rules/wk8202.ts +17 -22
  133. package/dist/rules/wk8203.ts +17 -22
  134. package/dist/rules/wk8204.ts +46 -51
  135. package/dist/rules/wk8205.ts +27 -32
  136. package/dist/rules/wk8207.ts +14 -19
  137. package/dist/rules/wk8208.ts +14 -19
  138. package/dist/rules/wk8209.ts +14 -19
  139. package/dist/rules/wk8301.ts +25 -30
  140. package/dist/rules/wk8302.ts +19 -24
  141. package/dist/rules/wk8303.ts +23 -26
  142. package/dist/rules/wk8304.ts +35 -40
  143. package/dist/rules/wk8305.ts +39 -42
  144. package/dist/rules/wk8306.ts +20 -25
  145. package/dist/rules/wk8401.ts +59 -64
  146. package/dist/rules/wk8402.ts +13 -18
  147. package/dist/rules/wk8403.ts +32 -37
  148. package/dist/rules/wk8404.ts +49 -0
  149. package/dist/rules/wk8405.ts +85 -0
  150. package/dist/rules/wk8406.ts +55 -0
  151. package/dist/rules/wk8407.ts +66 -0
  152. package/dist/rules/wk8503.ts +220 -0
  153. package/dist/rules/wk8504.ts +51 -0
  154. package/dist/rules/wk8505.ts +63 -0
  155. package/dist/secret-labels.d.ts +31 -0
  156. package/dist/secret-labels.d.ts.map +1 -0
  157. package/dist/secret-store.d.ts +73 -0
  158. package/dist/secret-store.d.ts.map +1 -0
  159. package/dist/serializer.d.ts.map +1 -1
  160. package/dist/sops/encrypted-secret-file.d.ts +52 -0
  161. package/dist/sops/encrypted-secret-file.d.ts.map +1 -0
  162. package/dist/sops/entity.d.ts +31 -0
  163. package/dist/sops/entity.d.ts.map +1 -0
  164. package/dist/teardown.d.ts.map +1 -1
  165. package/dist/types/index.d.ts +261 -9
  166. package/package.json +4 -4
  167. package/src/components/kubectl-apply.ts +5 -0
  168. package/src/composites/composites.test.ts +556 -0
  169. package/src/composites/flux-app.ts +23 -0
  170. package/src/composites/index.ts +15 -0
  171. package/src/composites/inference-service.ts +140 -0
  172. package/src/composites/model.ts +150 -0
  173. package/src/composites/operator-stack.ts +385 -0
  174. package/src/composites/vllm-serving-runtime.test.ts +167 -0
  175. package/src/composites/vllm-serving-runtime.ts +196 -0
  176. package/src/crd/cnpg.test.ts +8 -3
  177. package/src/crd/crd-sources.ts +183 -0
  178. package/src/crd/parser.test.ts +14 -0
  179. package/src/deep-observe-hooks.ts +24 -0
  180. package/src/deep-observe.test.ts +89 -0
  181. package/src/generated/index.d.ts +261 -9
  182. package/src/generated/index.ts +167 -40
  183. package/src/generated/lexicon-k8s.json +1039 -68
  184. package/src/generated/operations.json +272 -0
  185. package/src/group-namespace.test.ts +31 -0
  186. package/src/group-namespace.ts +13 -0
  187. package/src/index.ts +17 -0
  188. package/src/kube/apply.ts +5 -0
  189. package/src/lint/audit-catalog.ts +7 -0
  190. package/src/lint/post-synth/argo-helpers.ts +2 -6
  191. package/src/lint/post-synth/crd-schema-helpers.ts +4 -6
  192. package/src/lint/post-synth/index.ts +14 -0
  193. package/src/lint/post-synth/k8s-helpers.test.ts +26 -9
  194. package/src/lint/post-synth/k8s-helpers.ts +87 -24
  195. package/src/lint/post-synth/post-synth.test.ts +826 -0
  196. package/src/lint/post-synth/sops-helpers.ts +76 -0
  197. package/src/lint/post-synth/wk8005.ts +27 -32
  198. package/src/lint/post-synth/wk8006.ts +33 -38
  199. package/src/lint/post-synth/wk8041.ts +19 -24
  200. package/src/lint/post-synth/wk8042.ts +17 -22
  201. package/src/lint/post-synth/wk8101.ts +29 -34
  202. package/src/lint/post-synth/wk8102.ts +13 -18
  203. package/src/lint/post-synth/wk8103.ts +17 -22
  204. package/src/lint/post-synth/wk8104.ts +30 -35
  205. package/src/lint/post-synth/wk8105.ts +16 -21
  206. package/src/lint/post-synth/wk8201.ts +26 -31
  207. package/src/lint/post-synth/wk8202.ts +17 -22
  208. package/src/lint/post-synth/wk8203.ts +17 -22
  209. package/src/lint/post-synth/wk8204.ts +46 -51
  210. package/src/lint/post-synth/wk8205.ts +27 -32
  211. package/src/lint/post-synth/wk8207.ts +14 -19
  212. package/src/lint/post-synth/wk8208.ts +14 -19
  213. package/src/lint/post-synth/wk8209.ts +14 -19
  214. package/src/lint/post-synth/wk8301.ts +25 -30
  215. package/src/lint/post-synth/wk8302.ts +19 -24
  216. package/src/lint/post-synth/wk8303.ts +23 -26
  217. package/src/lint/post-synth/wk8304.ts +35 -40
  218. package/src/lint/post-synth/wk8305.ts +39 -42
  219. package/src/lint/post-synth/wk8306.ts +20 -25
  220. package/src/lint/post-synth/wk8401.ts +59 -64
  221. package/src/lint/post-synth/wk8402.ts +13 -18
  222. package/src/lint/post-synth/wk8403.ts +32 -37
  223. package/src/lint/post-synth/wk8404.ts +49 -0
  224. package/src/lint/post-synth/wk8405.ts +85 -0
  225. package/src/lint/post-synth/wk8406.ts +55 -0
  226. package/src/lint/post-synth/wk8407.ts +66 -0
  227. package/src/lint/post-synth/wk8503.ts +220 -0
  228. package/src/lint/post-synth/wk8504.ts +51 -0
  229. package/src/lint/post-synth/wk8505.ts +63 -0
  230. package/src/op/activities/ensure-secret.ts +71 -0
  231. package/src/op/activities/index.ts +7 -0
  232. package/src/op/activities/kubectl.test.ts +32 -0
  233. package/src/op/activities/kubectl.ts +28 -5
  234. package/src/op/activities/wait-for-ready.test.ts +34 -0
  235. package/src/op/activities/wait-for-ready.ts +26 -0
  236. package/src/op/builders.test.ts +82 -0
  237. package/src/op/builders.ts +95 -0
  238. package/src/plugin.ts +21 -2
  239. package/src/secret-labels.ts +36 -0
  240. package/src/secret-store.test.ts +184 -0
  241. package/src/secret-store.ts +165 -0
  242. package/src/serializer.ts +41 -2
  243. package/src/sops/encrypted-secret-file.test.ts +333 -0
  244. package/src/sops/encrypted-secret-file.ts +264 -0
  245. package/src/sops/entity.ts +53 -0
  246. package/src/teardown.test.ts +36 -0
  247. package/src/teardown.ts +14 -0
  248. package/src/testdata/sops/db-credentials.sops.yaml +23 -0
@@ -0,0 +1,140 @@
1
+ /**
2
+ * InferenceService composite — KServe `InferenceService` (v1beta1).
3
+ *
4
+ * Spec-true to KServe: the predictor references a `ServingRuntime` by name
5
+ * (the plug seam KServe itself defines — see #984's VllmServingRuntime) and
6
+ * a model `storageUri`, plus the real `ComponentExtensionSpec` autoscaling
7
+ * knobs (`minReplicas`/`maxReplicas`/`scaleTarget`/`scaleMetric`) and
8
+ * `canaryTrafficPercent`. No chant-flavored runtime abstraction is invented;
9
+ * `runtime` is just the `ServingRuntime`/`ClusterServingRuntime` name string
10
+ * KServe's own webhook resolves against `supportedModelFormats`.
11
+ *
12
+ * Coupling note (#984/#986 land in parallel in this same lexicon): this
13
+ * composite does not import either sibling. `runtime` is a plain name
14
+ * string (whatever `VllmServingRuntime` from #984 names its `ServingRuntime`
15
+ * object). `model` accepts either a raw `storageUri` string or a
16
+ * `{ storageUri }`-shaped object — the resolved-value shape `Model` from
17
+ * #986 is expected to return — matched structurally, not by import.
18
+ */
19
+
20
+ import { Composite, mergeDefaults } from "@intentius/chant";
21
+ import { InferenceService as InferenceServiceResource } from "../generated";
22
+
23
+ /** Knative concurrency, or a raw HPA metric (cpu/memory/rps). */
24
+ export type ScaleMetric = "concurrency" | "cpu" | "memory" | "rps";
25
+
26
+ /**
27
+ * A resolved model reference. Matches the resolved-value shape the `Model`
28
+ * composite (#986) is expected to return — structurally, not by import.
29
+ */
30
+ export interface ModelReference {
31
+ storageUri: string;
32
+ }
33
+
34
+ export interface InferenceServiceProps {
35
+ name: string;
36
+ namespace: string;
37
+ /** A raw `storageUri` (e.g. `"gs://bucket/model"`) or a resolved model ref. */
38
+ model: string | ModelReference;
39
+ /** `ServingRuntime`/`ClusterServingRuntime` name the predictor pins to. */
40
+ runtime: string;
41
+ /**
42
+ * Model format name for KServe's runtime auto-matching (e.g. `"vLLM"`).
43
+ * Optional since `runtime` already pins the ServingRuntime explicitly;
44
+ * set it if the ServingRuntime's `supportedModelFormats` expects it.
45
+ */
46
+ modelFormat?: string;
47
+ /** Minimum predictor replicas. */
48
+ minReplicas?: number;
49
+ /** Maximum predictor replicas. */
50
+ maxReplicas?: number;
51
+ /** Autoscaling target value (e.g. concurrency-per-replica, or CPU/memory/RPS target). */
52
+ scaleTarget?: number;
53
+ /** Which metric `scaleTarget` is measured against. */
54
+ scaleMetric?: ScaleMetric;
55
+ /** Percentage of traffic (0-100) routed to this revision as a canary. */
56
+ canaryTrafficPercent?: number;
57
+ labels?: Record<string, string>;
58
+ defaults?: {
59
+ inferenceService?: Partial<Record<string, unknown>>;
60
+ };
61
+ }
62
+
63
+ export type InferenceServiceResult = {
64
+ inferenceService: InstanceType<typeof InferenceServiceResource>;
65
+ };
66
+
67
+ function resolveStorageUri(model: string | ModelReference): string {
68
+ return typeof model === "string" ? model : model.storageUri;
69
+ }
70
+
71
+ /**
72
+ * Create an InferenceService composite — a KServe `InferenceService`
73
+ * predictor referencing a `ServingRuntime` and a model `storageUri`, with
74
+ * autoscaling bounds and an optional canary traffic split.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import { InferenceService } from "@intentius/chant-lexicon-k8s";
79
+ *
80
+ * const svc = InferenceService({
81
+ * name: "llama-3-8b",
82
+ * namespace: "serving",
83
+ * model: "gs://my-models/llama-3-8b/v1",
84
+ * runtime: "vllm-runtime",
85
+ * modelFormat: "vLLM",
86
+ * minReplicas: 1,
87
+ * maxReplicas: 4,
88
+ * scaleTarget: 8,
89
+ * scaleMetric: "concurrency",
90
+ * canaryTrafficPercent: 10,
91
+ * });
92
+ * ```
93
+ */
94
+ export const InferenceService = Composite((props: InferenceServiceProps) => {
95
+ const {
96
+ name,
97
+ namespace,
98
+ model,
99
+ runtime,
100
+ modelFormat,
101
+ minReplicas,
102
+ maxReplicas,
103
+ scaleTarget,
104
+ scaleMetric,
105
+ canaryTrafficPercent,
106
+ labels: extraLabels = {},
107
+ defaults: defs,
108
+ } = props;
109
+
110
+ const commonLabels: Record<string, string> = {
111
+ "app.kubernetes.io/name": name,
112
+ "app.kubernetes.io/managed-by": "chant",
113
+ "app.kubernetes.io/component": "inference-service",
114
+ ...extraLabels,
115
+ };
116
+
117
+ const predictor: Record<string, unknown> = {
118
+ model: {
119
+ runtime,
120
+ storageUri: resolveStorageUri(model),
121
+ ...(modelFormat !== undefined && { modelFormat: { name: modelFormat } }),
122
+ },
123
+ ...(minReplicas !== undefined && { minReplicas }),
124
+ ...(maxReplicas !== undefined && { maxReplicas }),
125
+ ...(scaleTarget !== undefined && { scaleTarget }),
126
+ ...(scaleMetric !== undefined && { scaleMetric }),
127
+ ...(canaryTrafficPercent !== undefined && { canaryTrafficPercent }),
128
+ };
129
+
130
+ const inferenceService = new InferenceServiceResource(mergeDefaults({
131
+ metadata: {
132
+ name,
133
+ namespace,
134
+ labels: commonLabels,
135
+ },
136
+ spec: { predictor },
137
+ }, defs?.inferenceService));
138
+
139
+ return { inferenceService };
140
+ }, "InferenceService");
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Model composite — resolves a model artifact reference to a KServe
3
+ * `storageUri` (+ optional warm-cache PVC), keyed by `(id, version)`.
4
+ *
5
+ * This is the FSx-warm-cache equivalent from the Netflix serving yardstick
6
+ * (see epic #982): a small, spec-true resolver that InferenceService (#985)
7
+ * consumes for its predictor's model reference. It does not itself emit an
8
+ * InferenceService or ServingRuntime — those are #984/#985's job.
9
+ *
10
+ * `version` is required so every resolved `storageUri` is pinned: the
11
+ * version is always appended as the trailing path segment, whether the
12
+ * default `id`-derived path is used or `uri` overrides it. This keeps the
13
+ * output stable for the unpinned-model lint rule (#988).
14
+ *
15
+ * `Model` itself is a plain resolver — a resolved value object, per the
16
+ * composite conventions — rather than a `Composite`, because its primary
17
+ * output (`storageUri`) is a string, not a Declarable; a `Composite`
18
+ * factory's members must all be Declarables. The optional cache PVC is
19
+ * built through an internal `Composite` so it gets the same bookkeeping
20
+ * (provenance, defaults-merging) as every other emitted resource.
21
+ */
22
+
23
+ import { Composite, mergeDefaults } from "@intentius/chant";
24
+ import { PersistentVolumeClaim } from "../generated";
25
+
26
+ /** Where the model's weights live. Maps to the matching KServe storage-initializer scheme. */
27
+ export type ModelSource = "hf" | "gcs" | "s3" | "pvc";
28
+
29
+ const STORAGE_SCHEME: Record<ModelSource, string> = {
30
+ hf: "hf",
31
+ gcs: "gs",
32
+ s3: "s3",
33
+ pvc: "pvc",
34
+ };
35
+
36
+ export interface ModelProps {
37
+ /** Model identifier, e.g. "llama-3-8b-instruct". Used to key the resolved storageUri and cache PVC. */
38
+ id: string;
39
+ /**
40
+ * Model version/revision. REQUIRED — feeds the unpinned-model lint rule
41
+ * (#988). Always appears as the trailing segment of the resolved
42
+ * `storageUri` so the reference is pinned.
43
+ */
44
+ version: string;
45
+ /** Where the model artifact is hosted; selects the storageUri scheme. */
46
+ source: ModelSource;
47
+ /**
48
+ * Explicit path override (e.g. a bucket/prefix, HF repo id, or PVC name)
49
+ * in place of the `id`-derived default. `version` is still appended.
50
+ */
51
+ uri?: string;
52
+ /** When set, emits a warm-cache PVC named `${id}-${version}` for the InferenceService (#985) to mount. */
53
+ cache?: {
54
+ storageClass: string;
55
+ size: string;
56
+ };
57
+ /** Per-member defaults for fine-grained overrides. */
58
+ defaults?: {
59
+ cachePvc?: Partial<Record<string, unknown>>;
60
+ };
61
+ }
62
+
63
+ export interface ModelResult {
64
+ /** Resolved KServe storageUri, pinned to `version`. */
65
+ storageUri: string;
66
+ /** Warm-cache PVC, present only when `cache` is set. Named `${id}-${version}`. */
67
+ cache?: InstanceType<typeof PersistentVolumeClaim>;
68
+ }
69
+
70
+ /**
71
+ * Resolve a model artifact's `{ id, version, source, uri }` to a pinned
72
+ * KServe `storageUri` string.
73
+ */
74
+ export function resolveModelStorageUri(props: Pick<ModelProps, "id" | "version" | "source" | "uri">): string {
75
+ const { id, version, source, uri } = props;
76
+ const scheme = STORAGE_SCHEME[source];
77
+ const path = uri ?? id;
78
+ return `${scheme}://${path}/${version}`;
79
+ }
80
+
81
+ interface ModelCachePvcProps {
82
+ id: string;
83
+ version: string;
84
+ storageClass: string;
85
+ size: string;
86
+ defaults?: Partial<Record<string, unknown>>;
87
+ }
88
+
89
+ const ModelCachePvc = Composite<ModelCachePvcProps, { pvc: InstanceType<typeof PersistentVolumeClaim> }>(
90
+ (props) => {
91
+ const { id, version, storageClass, size, defaults } = props;
92
+
93
+ const pvc = new PersistentVolumeClaim(mergeDefaults({
94
+ metadata: {
95
+ name: `${id}-${version}`,
96
+ labels: {
97
+ "app.kubernetes.io/name": id,
98
+ "app.kubernetes.io/managed-by": "chant",
99
+ "app.kubernetes.io/component": "model-cache",
100
+ },
101
+ },
102
+ spec: {
103
+ accessModes: ["ReadWriteMany"],
104
+ storageClassName: storageClass,
105
+ resources: { requests: { storage: size } },
106
+ },
107
+ }, defaults));
108
+
109
+ return { pvc };
110
+ },
111
+ "ModelCachePvc",
112
+ );
113
+
114
+ /**
115
+ * Resolve a model artifact `{ id, version, source, uri, cache }` to a pinned
116
+ * `storageUri`, with an optional warm-cache PVC.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * import { Model } from "@intentius/chant-lexicon-k8s";
121
+ *
122
+ * const { storageUri, cache } = Model({
123
+ * id: "llama-3-8b-instruct",
124
+ * version: "2024-07-01",
125
+ * source: "gcs",
126
+ * uri: "my-models-bucket/llama-3-8b-instruct",
127
+ * cache: { storageClass: "premium-rwo", size: "200Gi" },
128
+ * });
129
+ * ```
130
+ */
131
+ export function Model(props: ModelProps): ModelResult {
132
+ const { id, version, cache, defaults } = props;
133
+
134
+ const storageUri = resolveModelStorageUri(props);
135
+
136
+ const cachePvc = cache
137
+ ? ModelCachePvc({
138
+ id,
139
+ version,
140
+ storageClass: cache.storageClass,
141
+ size: cache.size,
142
+ defaults: defaults?.cachePvc,
143
+ }).pvc
144
+ : undefined;
145
+
146
+ return {
147
+ storageUri,
148
+ ...(cachePvc && { cache: cachePvc }),
149
+ };
150
+ }
@@ -0,0 +1,385 @@
1
+ /**
2
+ * OperatorStack composite (#1940, epic #1487) — the operating loop
3
+ * materialized in-cluster as a declared estate on gitops principles: one
4
+ * Namespace, one CronJob per hosted `ConvergeOp` tick, and RBAC scoped to
5
+ * what that tick can actually do. chant declares the loop that runs chant
6
+ * with its own k8s lexicon — the same estate discipline as any other app.
7
+ *
8
+ * ## Why a CronJob, not the operator daemon
9
+ *
10
+ * Issue #1485 ("chant operator: native durable ticks without Temporal")
11
+ * names cron, a systemd timer, a k8s CronJob, a CI schedule, and the
12
+ * `chant operator` daemon as interchangeable safe invokers of the same
13
+ * thing: one converge tick. A k8s CronJob invoking `chant run <name>` per
14
+ * tick is that issue's own "cron … invokes the tick" case, not a dependency
15
+ * on the daemon it proposes — #1485 is a separate, still-unmerged runtime
16
+ * (lease fencing, `chant operator status`, durable gate-as-fact semantics).
17
+ * `OperatorStack`'s container command is deliberately `chant run <name>`,
18
+ * the one-shot local tick `ConvergeOp` (#1484) already ships and tests
19
+ * against (`lexicons/temporal/src/composites/converge-op.ts`'s own doc:
20
+ * "one-shot runnable locally for a single tick"). When #1485 lands, a
21
+ * caller can override `command` to shell out to `chant operator tick`
22
+ * instead — this composite doesn't need to change for that; only the
23
+ * command a caller passes does.
24
+ *
25
+ * `concurrencyPolicy: "Forbid"` is the k8s-native analogue of
26
+ * `ConvergeOp`'s own Temporal schedule `overlap: "Skip"` policy — never
27
+ * queue a second tick behind one still running.
28
+ *
29
+ * ## RBAC derivation
30
+ *
31
+ * `ConvergeOp` adds no authority an environment did not already grant
32
+ * (#1484's Autonomy table). `OperatorStack` re-derives the same bound at the
33
+ * k8s RBAC layer, independently of the temporal lexicon (this module has no
34
+ * dependency on it — see the layering note below): for each hosted
35
+ * ConvergeOp, walk its `dispatchTargets` (the OpConfigs its rule table's
36
+ * `run()` actions may name) through `classifyOpVerbClass`
37
+ * (`packages/core/src/op/op-verb-class.ts`, #1954), then keep only the
38
+ * highest verb class this host's `dial` could ever actually free-run —
39
+ * exactly `convergeTick`'s own `verbClassAllowedToDispatch` gate and
40
+ * `TMP014`'s build-time refusal, restated as an RBAC ceiling:
41
+ *
42
+ * - `dial: "observe"` never dispatches (report-only) → read-only RBAC,
43
+ * regardless of what the rule table's targets could otherwise do.
44
+ * - `dial: "reconcile"` only free-runs a read-only target (TMP014 refuses a
45
+ * mutating dispatch under reconcile in v1) → read-only RBAC.
46
+ * - `dial: "apply"` free-runs read-only and mutating targets → RBAC gains
47
+ * create/update/patch, never delete.
48
+ * - A `dispatchTargets` entry that itself classifies `destructive` is
49
+ * refused outright, at construction — TMP014 already refuses a
50
+ * destructive `run()` target under any dial in v1 (the local dispatch
51
+ * executor can't honor its required gate), so a `destructive` target
52
+ * reaching this composite is either a config bypassing that build check
53
+ * or a target `OperatorStack` should never grant permission toward.
54
+ * `never delete`, unconditionally, in v1 — no verb class here ever grants
55
+ * `delete`/`deletecollection`, and no rule ever uses `"*"`.
56
+ *
57
+ * Each hosted ConvergeOp gets its own ServiceAccount + Role + RoleBinding
58
+ * (never one shared identity across differently-scoped loops) — a read-only
59
+ * loop and a mutating loop sharing a Namespace get RBAC as different as
60
+ * their own dials allow, never the union.
61
+ *
62
+ * ## Layering
63
+ *
64
+ * `lexicons/k8s` has no workspace dependency on `lexicons/temporal` (nor
65
+ * the reverse — see both packages' `package.json`), so this module doesn't
66
+ * import `ConvergeOpConfig`/`ConvergeRule` types. `OperatorStackConvergeHost`
67
+ * restates the handful of `ConvergeOp` fields this composite actually needs
68
+ * (`name`, `schedule`, `env`, `dial`) structurally; `dispatchTargets` takes
69
+ * plain `OpConfig`-shaped values from `@intentius/chant/op` (a dependency
70
+ * this lexicon already has via the `@intentius/chant` peer dependency),
71
+ * the same type `classifyOpVerbClass` itself takes.
72
+ */
73
+
74
+ import { Composite, mergeDefaults } from "@intentius/chant";
75
+ import { classifyOpVerbClass } from "@intentius/chant/op";
76
+ import type { OpConfig, OpVerbClass } from "@intentius/chant/op";
77
+ import { Namespace, CronJob, ServiceAccount, Role, RoleBinding } from "../generated";
78
+
79
+ // ── Types ────────────────────────────────────────────────────────────────
80
+
81
+ /**
82
+ * Mirrors `ConvergeOp`'s own `ConvergeDial`
83
+ * (`lexicons/temporal/src/composites/converge-op.ts`) structurally — see
84
+ * this module's Layering doc for why it's restated rather than imported.
85
+ */
86
+ export type OperatorDial = "observe" | "reconcile" | "apply";
87
+
88
+ /** One resource-kind grant: an API group plus the resource names within it. Verbs are never specified here — they come from the derived verb class, never authored per-rule (the one place a rule table could smuggle in `delete`). */
89
+ export interface OperatorRbacResourceRule {
90
+ /** `""` is the core API group. */
91
+ apiGroups: string[];
92
+ resources: string[];
93
+ }
94
+
95
+ export interface OperatorStackConvergeHost {
96
+ /** ConvergeOp's own name (`ConvergeOpConfig.name`) — the CronJob, ServiceAccount, Role, and RoleBinding name stem for this host. */
97
+ name: string;
98
+ /** Cron expression driving the tick — the same string passed to `ConvergeOp`'s own `schedule`. */
99
+ schedule: string;
100
+ /** Environment this ConvergeOp converges (`ConvergeOpConfig.env`) — carried onto the container as `CHANT_CONVERGE_ENV`, for log/estate readability only (`chant run <name>` needs no `--env`: the target op already carries it). */
101
+ env: string;
102
+ /** Authority dial (`ConvergeOpConfig.dial`). @default "observe" */
103
+ dial?: OperatorDial;
104
+ /**
105
+ * OpConfigs for every op this ConvergeOp's rule table may `run()` — the
106
+ * sibling `*.op.ts` declarations its `run()` actions name. Used to derive
107
+ * least-privilege RBAC the same way `TMP014` derives its build-time
108
+ * refusals. Omit or leave empty when every rule only `report()`s; the
109
+ * host still gets read-only RBAC for its own observation.
110
+ */
111
+ dispatchTargets?: Pick<OpConfig, "phases" | "onFailure">[];
112
+ /** RBAC resource kinds this host's ServiceAccount may act on (the estate being converged — there's no way to derive this generically from an OpConfig). @default DEFAULT_RESOURCE_RULES */
113
+ resources?: OperatorRbacResourceRule[];
114
+ /** Container command. @default `["chant", "run", <name>]` — see this module's doc on why, and #1485 for the future `chant operator`-shaped alternative. */
115
+ command?: string[];
116
+ }
117
+
118
+ export interface OperatorStackConfig {
119
+ /** Stack name — also the Namespace name unless `namespace` is given. */
120
+ name: string;
121
+ /** Namespace hosting every CronJob. @default config.name */
122
+ namespace?: string;
123
+ /** Container image running the chant CLI. */
124
+ image: string;
125
+ /** ConvergeOps to host — one CronJob (+ ServiceAccount + Role + RoleBinding) per entry. Non-empty; host names must be unique. */
126
+ converge: OperatorStackConvergeHost[];
127
+ /** RBAC resource kinds granted by default when a host doesn't name its own `resources`. @default DEFAULT_RESOURCE_RULES */
128
+ defaultResources?: OperatorRbacResourceRule[];
129
+ /** @default 3 */
130
+ successfulJobsHistoryLimit?: number;
131
+ /** @default 1 */
132
+ failedJobsHistoryLimit?: number;
133
+ /** Additional labels applied to every resource. */
134
+ labels?: Record<string, string>;
135
+ /** Per-member-kind defaults for fine-grained overrides, applied to every host's member of that kind. */
136
+ defaults?: {
137
+ namespace?: Partial<Record<string, unknown>>;
138
+ serviceAccount?: Partial<Record<string, unknown>>;
139
+ role?: Partial<Record<string, unknown>>;
140
+ roleBinding?: Partial<Record<string, unknown>>;
141
+ cronJob?: Partial<Record<string, unknown>>;
142
+ };
143
+ }
144
+
145
+ /**
146
+ * Flat member shape: `namespace`, plus `serviceAccount_<host>`,
147
+ * `role_<host>`, `roleBinding_<host>`, `cronJob_<host>` for every entry in
148
+ * `converge` — a `Composite` member must itself be a `Declarable`
149
+ * (`packages/core/src/composite.ts`), so per-host resources are flat, keyed
150
+ * members rather than grouped under a nested `Record` (a plain object isn't
151
+ * a `Declarable`, so it can't itself be a composite member). A host named
152
+ * `"fountain-converge"` reads back as
153
+ * `result["cronJob_fountain-converge"]` (bracket notation — the key isn't a
154
+ * valid bare identifier).
155
+ */
156
+ export interface OperatorStackResult {
157
+ namespace: InstanceType<typeof Namespace>;
158
+ [member: string]:
159
+ | InstanceType<typeof Namespace>
160
+ | InstanceType<typeof ServiceAccount>
161
+ | InstanceType<typeof Role>
162
+ | InstanceType<typeof RoleBinding>
163
+ | InstanceType<typeof CronJob>;
164
+ }
165
+
166
+ // ── RBAC derivation ──────────────────────────────────────────────────────
167
+
168
+ /** Default RBAC resource kinds — the common workload surface a converge tick observes/acts on. Deliberately excludes `secrets`: a host that needs secret access opts in explicitly via its own `resources`. */
169
+ export const DEFAULT_RESOURCE_RULES: OperatorRbacResourceRule[] = [
170
+ { apiGroups: [""], resources: ["pods", "services", "configmaps", "persistentvolumeclaims", "events"] },
171
+ { apiGroups: ["apps"], resources: ["deployments", "statefulsets", "daemonsets", "replicasets"] },
172
+ { apiGroups: ["batch"], resources: ["jobs", "cronjobs"] },
173
+ ];
174
+
175
+ const READ_VERBS = ["get", "list", "watch"];
176
+ const MUTATE_VERBS = [...READ_VERBS, "create", "update", "patch"];
177
+
178
+ /** RBAC verbs for a derived class. Never returns `delete`/`deletecollection`/`"*"` — v1 has no path to a destructive dispatch (see this module's RBAC derivation doc). */
179
+ function rbacVerbsFor(verbClass: OpVerbClass): string[] {
180
+ return verbClass === "mutating" ? MUTATE_VERBS : READ_VERBS;
181
+ }
182
+
183
+ /**
184
+ * Whether `dial` ever actually free-runs a dispatch classified `verbClass` —
185
+ * restates `convergeTick`'s own `verbClassAllowedToDispatch`
186
+ * (`lexicons/temporal/src/op/activities/converge.ts`) so the RBAC ceiling
187
+ * this composite grants matches the ceiling the tick itself enforces at
188
+ * runtime, without importing across the lexicon boundary (see this module's
189
+ * Layering doc).
190
+ */
191
+ function dialAllowsVerbClass(dial: OperatorDial, verbClass: OpVerbClass): boolean {
192
+ if (verbClass === "read-only") return true;
193
+ if (verbClass === "mutating") return dial === "apply";
194
+ return false; // destructive: never free-run under any dial in v1.
195
+ }
196
+
197
+ /**
198
+ * Derive the highest verb class a host's ServiceAccount actually needs:
199
+ * the max, across `dispatchTargets`, of each target's own class — but only
200
+ * counting a target `dial` could ever actually dispatch (one it can't just
201
+ * gets reported, per `TMP014`/`convergeTick`, and needs no elevated grant).
202
+ * A `dispatchTargets` entry that classifies `destructive` is refused
203
+ * outright rather than silently ignored — see this module's RBAC
204
+ * derivation doc on why a destructive target reaching this composite is
205
+ * itself a refusal, not a no-op.
206
+ */
207
+ export function deriveHostVerbClass(hostName: string, dial: OperatorDial, dispatchTargets: Pick<OpConfig, "phases" | "onFailure">[]): OpVerbClass {
208
+ let effective: OpVerbClass = "read-only";
209
+ for (const target of dispatchTargets) {
210
+ const verbClass = classifyOpVerbClass(target);
211
+ if (verbClass === "destructive") {
212
+ throw new Error(
213
+ `OperatorStack host "${hostName}": a dispatchTargets entry classifies as destructive — ConvergeOp v1 refuses a destructive run() target under any dial ` +
214
+ `(TMP014; the local dispatch executor can't honor its required gate). Remove it from dispatchTargets, or remediate manually via a gated op.`,
215
+ );
216
+ }
217
+ if (!dialAllowsVerbClass(dial, verbClass)) continue; // dial refuses this dispatch — reported, not run; needs no elevated RBAC
218
+ if (verbClass === "mutating") effective = "mutating";
219
+ }
220
+ return effective;
221
+ }
222
+
223
+ // ── Composite ────────────────────────────────────────────────────────────
224
+
225
+ /**
226
+ * Create an OperatorStack composite — a Namespace hosting one CronJob (+
227
+ * least-privilege ServiceAccount/Role/RoleBinding) per ConvergeOp, the
228
+ * in-cluster declared estate for the operating loop.
229
+ *
230
+ * @example
231
+ * ```ts
232
+ * import { OperatorStack } from "@intentius/chant-lexicon-k8s";
233
+ *
234
+ * const stack = OperatorStack({
235
+ * name: "chant-operator",
236
+ * image: "ghcr.io/intentius/chant:0.49.0",
237
+ * converge: [
238
+ * { name: "fountain-observe", schedule: "*\/10 * * * *", env: "staging", dial: "observe" },
239
+ * { name: "fountain-converge", schedule: "*\/10 * * * *", env: "staging", dial: "apply", dispatchTargets: [fountainApplyOp] },
240
+ * ],
241
+ * });
242
+ * ```
243
+ */
244
+ export const OperatorStack = Composite((props: OperatorStackConfig) => {
245
+ const {
246
+ name,
247
+ namespace: namespaceName = name,
248
+ image,
249
+ converge,
250
+ defaultResources = DEFAULT_RESOURCE_RULES,
251
+ successfulJobsHistoryLimit = 3,
252
+ failedJobsHistoryLimit = 1,
253
+ labels: extraLabels = {},
254
+ defaults: defs,
255
+ } = props;
256
+
257
+ if (converge.length === 0) {
258
+ throw new Error(`OperatorStack "${name}": at least one ConvergeOp to host is required — a namespace with no CronJob has nothing to converge.`);
259
+ }
260
+ const seen = new Set<string>();
261
+ for (const host of converge) {
262
+ if (!host.name || host.name.trim().length === 0) {
263
+ throw new Error(`OperatorStack "${name}": every hosted ConvergeOp needs a non-empty name.`);
264
+ }
265
+ if (seen.has(host.name)) {
266
+ throw new Error(`OperatorStack "${name}": duplicate hosted ConvergeOp name "${host.name}" — CronJob/ServiceAccount names would collide.`);
267
+ }
268
+ seen.add(host.name);
269
+ if (!host.schedule || host.schedule.trim().length === 0) {
270
+ throw new Error(`OperatorStack "${name}", host "${host.name}": schedule is required — an operator CronJob with no schedule never ticks.`);
271
+ }
272
+ }
273
+ if (!image || image.trim().length === 0) {
274
+ throw new Error(`OperatorStack "${name}": image is required — the CronJob has nothing to run.`);
275
+ }
276
+
277
+ const commonLabels: Record<string, string> = {
278
+ "app.kubernetes.io/name": name,
279
+ "app.kubernetes.io/managed-by": "chant",
280
+ "app.kubernetes.io/component": "operator",
281
+ ...extraLabels,
282
+ };
283
+
284
+ const namespace = new Namespace(mergeDefaults({
285
+ metadata: {
286
+ name: namespaceName,
287
+ labels: { ...commonLabels, "app.kubernetes.io/component": "namespace" },
288
+ },
289
+ }, defs?.namespace));
290
+
291
+ const result: Record<string, any> = { namespace };
292
+
293
+ for (const host of converge) {
294
+ const dial = host.dial ?? "observe";
295
+ const verbClass = deriveHostVerbClass(host.name, dial, host.dispatchTargets ?? []);
296
+ const resourceRules = host.resources ?? defaultResources;
297
+ const verbs = rbacVerbsFor(verbClass);
298
+
299
+ const saName = `${host.name}-sa`;
300
+ const roleName = `${host.name}-role`;
301
+ const bindingName = `${host.name}-binding`;
302
+
303
+ const hostLabels: Record<string, string> = {
304
+ ...commonLabels,
305
+ "app.kubernetes.io/instance": host.name,
306
+ };
307
+
308
+ const serviceAccount = new ServiceAccount(mergeDefaults({
309
+ metadata: {
310
+ name: saName,
311
+ namespace: namespaceName,
312
+ labels: hostLabels,
313
+ },
314
+ }, defs?.serviceAccount));
315
+ result[`serviceAccount_${host.name}`] = serviceAccount;
316
+
317
+ const role = new Role(mergeDefaults({
318
+ metadata: {
319
+ name: roleName,
320
+ namespace: namespaceName,
321
+ labels: { ...hostLabels, "app.kubernetes.io/component": "rbac" },
322
+ },
323
+ rules: resourceRules.map((r) => ({ apiGroups: r.apiGroups, resources: r.resources, verbs })),
324
+ }, defs?.role));
325
+ result[`role_${host.name}`] = role;
326
+
327
+ const roleBinding = new RoleBinding(mergeDefaults({
328
+ metadata: {
329
+ name: bindingName,
330
+ namespace: namespaceName,
331
+ labels: { ...hostLabels, "app.kubernetes.io/component": "rbac" },
332
+ },
333
+ roleRef: {
334
+ apiGroup: "rbac.authorization.k8s.io",
335
+ kind: "Role",
336
+ name: roleName,
337
+ },
338
+ subjects: [
339
+ { kind: "ServiceAccount", name: saName, namespace: namespaceName },
340
+ ],
341
+ }, defs?.roleBinding));
342
+ result[`roleBinding_${host.name}`] = roleBinding;
343
+
344
+ const command = host.command ?? ["chant", "run", host.name];
345
+
346
+ const cronJob = new CronJob(mergeDefaults({
347
+ metadata: {
348
+ name: host.name,
349
+ namespace: namespaceName,
350
+ labels: { ...hostLabels, "app.kubernetes.io/component": "converge-tick" },
351
+ },
352
+ spec: {
353
+ schedule: host.schedule,
354
+ concurrencyPolicy: "Forbid",
355
+ successfulJobsHistoryLimit,
356
+ failedJobsHistoryLimit,
357
+ jobTemplate: {
358
+ spec: {
359
+ template: {
360
+ metadata: { labels: { ...hostLabels, "app.kubernetes.io/component": "converge-tick" } },
361
+ spec: {
362
+ serviceAccountName: saName,
363
+ restartPolicy: "OnFailure",
364
+ containers: [
365
+ {
366
+ name: host.name,
367
+ image,
368
+ command,
369
+ env: [
370
+ { name: "CHANT_CONVERGE_ENV", value: host.env },
371
+ { name: "CHANT_CONVERGE_DIAL", value: dial },
372
+ ],
373
+ },
374
+ ],
375
+ },
376
+ },
377
+ },
378
+ },
379
+ },
380
+ }, defs?.cronJob));
381
+ result[`cronJob_${host.name}`] = cronJob;
382
+ }
383
+
384
+ return result;
385
+ }, "OperatorStack");