-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdoc.go
More file actions
314 lines (313 loc) · 10.1 KB
/
doc.go
File metadata and controls
314 lines (313 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
// Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package recipe provides configuration recipe generation based on deployment criteria.
//
// # Overview
//
// The recipe package generates tailored configuration recommendations for GPU-accelerated
// Kubernetes clusters. It uses a metadata-driven model where base configurations are
// enhanced with criteria-specific overlays to produce deployment-ready component references.
//
// # Core Types
//
// Criteria: Specifies target deployment parameters
//
// type Criteria struct {
// Service CriteriaServiceType // eks, gke, aks, any
// Accelerator CriteriaAcceleratorType // h100, gb200, a100, l40, any
// Intent CriteriaIntentType // training, inference, any
// OS CriteriaOSType // ubuntu, cos, rhel, any
// Nodes int // node count (0 = any)
// }
//
// RecipeResult: Generated configuration result
//
// type RecipeResult struct {
// Header // API version, kind, metadata
// Criteria *Criteria // Input criteria
// MatchedRules []string // Applied overlay rules
// ComponentRefs []ComponentRef // Component references (Helm or Kustomize)
// Constraints []ConstraintRef // Validation constraints
// }
//
// Recipe: Legacy format still used by bundlers
//
// type Recipe struct {
// Header // API version, kind, metadata
// Request *RequestInfo // Input metadata (optional)
// MatchedRules []string // Applied overlay rules
// Measurements []*measurement.Measurement // Configuration data
// }
//
// Builder: Generates recipes from criteria
//
// type Builder struct {
// Version string // Builder version for tracking
// }
//
// # Criteria Types
//
// Service types for Kubernetes environments:
// - CriteriaServiceEKS: Amazon EKS
// - CriteriaServiceGKE: Google GKE
// - CriteriaServiceAKS: Azure AKS
// - CriteriaServiceAny: Any service (wildcard)
//
// Accelerator types for GPU selection:
// - CriteriaAcceleratorH100: NVIDIA H100
// - CriteriaAcceleratorGB200: NVIDIA GB200
// - CriteriaAcceleratorA100: NVIDIA A100
// - CriteriaAcceleratorL40: NVIDIA L40
// - CriteriaAcceleratorAny: Any accelerator (wildcard)
//
// Intent types for workload optimization:
// - CriteriaIntentTraining: ML training workloads
// - CriteriaIntentInference: Inference workloads
// - CriteriaIntentAny: Generic workloads
//
// # Usage
//
// Basic recipe generation with criteria:
//
// criteria := recipe.NewCriteria()
// criteria.Service = recipe.CriteriaServiceEKS
// criteria.Accelerator = recipe.CriteriaAcceleratorH100
// criteria.Intent = recipe.CriteriaIntentTraining
//
// ctx := context.Background()
// builder := recipe.NewBuilder()
// result, err := builder.BuildFromCriteria(ctx, criteria)
// if err != nil {
// log.Fatal(err)
// }
//
// fmt.Printf("Matched rules: %v\n", result.MatchedRules)
// for _, ref := range result.ComponentRefs {
// fmt.Printf("Component: %s, Version: %s\n", ref.Name, ref.Version)
// }
//
// HTTP handler for API server:
//
// builder := recipe.NewBuilder()
// http.HandleFunc("/v1/recipe", builder.HandleRecipes)
//
// Parse criteria from HTTP request:
//
// criteria, err := recipe.ParseCriteriaFromRequest(r)
// if err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
//
// # Query Parameters (HTTP API - GET)
//
// The HTTP handler accepts these query parameters for GET requests:
// - service: eks, gke, aks, any (default: any)
// - accelerator: h100, gb200, a100, l40, any (default: any)
// - gpu: alias for accelerator (backwards compatibility)
// - intent: training, inference, any (default: any)
// - os: ubuntu, cos, rhel, any (default: any)
// - nodes: integer node count (default: 0 = any)
//
// # Criteria Files (CLI and HTTP API - POST)
//
// Criteria can be defined in a Kubernetes-style YAML or JSON file using the
// RecipeCriteria resource type. This provides an alternative to individual
// CLI flags or query parameters.
//
// RecipeCriteria: Kubernetes-style resource for criteria definition
//
// type RecipeCriteria struct {
// Kind string // Must be "RecipeCriteria"
// APIVersion string // Must be "aicr.nvidia.com/v1alpha1"
// Metadata struct {
// Name string // Optional descriptive name
// }
// Spec *Criteria // The criteria specification
// }
//
// Example criteria file (criteria.yaml):
//
// kind: RecipeCriteria
// apiVersion: aicr.nvidia.com/v1alpha1
// metadata:
// name: gb200-eks-ubuntu-training
// spec:
// service: eks
// os: ubuntu
// accelerator: gb200
// intent: training
//
// Load criteria from a file:
//
// criteria, err := recipe.LoadCriteriaFromFile("/path/to/criteria.yaml")
// if err != nil {
// log.Fatal(err)
// }
// result, err := builder.BuildFromCriteria(ctx, criteria)
//
// Parse criteria from HTTP request body (POST):
//
// criteria, err := recipe.ParseCriteriaFromBody(r.Body, r.Header.Get("Content-Type"))
// if err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
//
// CLI usage with criteria file:
//
// aicr recipe --criteria /path/to/criteria.yaml --output recipe.yaml
//
// CLI flags can override criteria file values:
//
// aicr recipe --criteria criteria.yaml --service gke --output recipe.yaml
//
// HTTP API POST request:
//
// curl -X POST http://localhost:8080/v1/recipe \
// -H "Content-Type: application/yaml" \
// -d @criteria.yaml
//
// # Criteria Matching
//
// Criteria use asymmetric matching with priority-based resolution:
//
// Recipe Wildcard (recipe field = "any"):
// - Recipe "any" acts as a wildcard, matching any query value
// - Example: Recipe with accelerator="any" matches query accelerator="h100"
//
// Query Wildcard (query field = "any"):
// - Query "any" only matches recipes that also have "any"
// - Prevents generic queries from matching overly-specific recipes
// - Example: Query accelerator="any" does NOT match recipe accelerator="h100"
//
// Exact Match:
// - Query service="eks", accelerator="h100" matches recipe with same values
//
// Priority:
// - More specific overlays take precedence
// - Multiple matching overlays are applied in priority order
// - Later overlays can override earlier ones
//
// # Metadata Store Model
//
// Recipe generation uses YAML metadata files:
//
// 1. Load overlays/base.yaml (common component versions and settings)
// 2. Find matching overlay files based on criteria
// 3. Merge overlay configurations into result
// 4. Return RecipeResult with component references
//
// Base structure (recipes/overlays/base.yaml):
//
// apiVersion: aicr.nvidia.com/v1alpha1
// kind: Base
// metadata:
// name: base
// version: v1.0.0
// components:
// - name: gpu-operator
// version: v25.3.3
// repository: https://helm.ngc.nvidia.com/nvidia
//
// Overlay structure (recipes/overlays/*.yaml):
//
// apiVersion: aicr.nvidia.com/v1alpha1
// kind: Overlay
// metadata:
// name: h100-training
// priority: 100
// match:
// accelerator: h100
// intent: training
// components:
// - name: gpu-operator
// version: v25.3.3
// values:
// mig.strategy: mixed
//
// # RecipeInput Interface
//
// The RecipeInput interface allows bundlers to work with both legacy Recipe
// and new RecipeResult formats:
//
// type RecipeInput interface {
// GetMeasurements() []*measurement.Measurement
// GetComponentRef(name string) *ComponentRef
// GetValuesForComponent(name string) (map[string]any, error)
// }
//
// # Error Handling
//
// BuildFromCriteria returns errors when:
// - Criteria is nil
// - Metadata store cannot be loaded
// - No matching overlays found
// - Component configuration is invalid
//
// ParseCriteriaFromRequest returns errors when:
// - Service type is invalid
// - Accelerator type is invalid
// - Intent type is invalid
// - Nodes count is negative or non-numeric
//
// # Data Source
//
// Recipe metadata is embedded at build time from:
// - recipes/overlays/base.yaml (base component versions)
// - recipes/overlays/*.yaml (criteria-specific overlays)
//
// The metadata store is loaded once and cached (singleton pattern with sync.Once).
//
// # Observability
//
// The recipe builder exports Prometheus metrics:
// - recipe_built_duration_seconds: Time to build recipe
// - recipe_rule_match_total{status}: Rule matching statistics
//
// # Integration
//
// The recipe package is used by:
// - pkg/cli - recipe command for CLI usage
// - pkg/api - API recipe endpoint
// - pkg/bundler - Bundle generation from recipes
//
// It depends on:
// - pkg/measurement - Measurement data structures
// - pkg/version - Version parsing
// - pkg/header - Common header types
// - pkg/errors - Structured error handling
//
// # Component Types
//
// The recipe system supports two component deployment types:
//
// Helm Components:
// - Use Helm charts for deployment
// - Configured via helm section in registry.yaml
// - Support values files and inline overrides
//
// Kustomize Components:
// - Use Kustomize for deployment
// - Configured via kustomize section in registry.yaml
// - Support Git/OCI sources with path and tag
//
// The component registry (recipes/registry.yaml) determines component
// defaults. Components must have either helm OR kustomize configuration.
//
// # Subpackages
//
// - recipe/version - Semantic version parsing (moved to pkg/version)
// - recipe/header - Common header structures (moved to pkg/header)
package recipe