Documentation
¶
Overview ¶
Package header provides common header types for AICR data structures.
This package defines the Header type used across recipes, snapshots, and other AICR data structures to provide consistent metadata and versioning information.
Header Structure ¶
The Header contains standard fields for API versioning and metadata:
type Header struct {
APIVersion string `json:"apiVersion" yaml:"apiVersion"` // API version (e.g., "v1")
Kind string `json:"kind" yaml:"kind"` // Resource type (e.g., "Recipe", "Snapshot")
Metadata *Metadata `json:"metadata,omitempty" yaml:"metadata,omitempty"` // Optional metadata
}
Metadata includes timestamps and version information:
type Metadata struct {
Created time.Time `json:"created" yaml:"created"` // Creation timestamp
Version string `json:"version,omitempty" yaml:"version,omitempty"` // Tool version
Custom map[string]any `json:"custom,omitempty" yaml:"custom,omitempty"` // Custom fields
}
Usage ¶
Create a header for a recipe:
header := header.Header{
APIVersion: "v1",
Kind: "Recipe",
Metadata: &header.Metadata{
Created: time.Now(),
Version: "v1.0.0",
},
}
Create a header for a snapshot:
header := header.Header{
APIVersion: "v1",
Kind: "Snapshot",
Metadata: &header.Metadata{
Created: time.Now(),
Version: "v1.0.0",
Custom: map[string]any{
"node": "gpu-node-1",
"cluster": "production",
},
},
}
Serialization ¶
Headers serialize consistently to JSON and YAML:
{
"apiVersion": "v1",
"kind": "Recipe",
"metadata": {
"created": "2025-12-30T10:30:00Z",
"version": "v1.0.0"
}
}
API Versioning ¶
The APIVersion field enables evolution of data formats:
- v1: Current stable API
- Future versions can add fields with backward compatibility
Tools should check APIVersion before parsing:
if header.APIVersion != "v1" {
return fmt.Errorf("unsupported API version: %s", header.APIVersion)
}
Kind Field ¶
The Kind field identifies the resource type:
- Recipe: Configuration recommendations
- Snapshot: System configuration capture
- Bundle: Deployment artifact metadata
Custom Metadata ¶
Custom fields enable extensibility without API version changes:
metadata.Custom = map[string]any{
"node": "gpu-node-1",
"cluster": "production",
"environment": "staging",
}
Timestamps ¶
Timestamps use RFC3339 format for consistency:
metadata.Created = time.Now().UTC() // Serializes as: "2025-12-30T10:30:00Z"
Validation ¶
While Header doesn't enforce validation, consumers should verify:
- APIVersion is supported
- Kind is recognized
- Created timestamp is reasonable
- Version is a valid semantic version (if present)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Header ¶
type Header struct {
// Kind is the type of the snapshot object.
Kind Kind `json:"kind,omitempty" yaml:"kind,omitempty"`
// APIVersion is the API version of the snapshot object.
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
// Metadata contains key-value pairs with metadata about the snapshot.
Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}
Header contains metadata and versioning information for AICR resources. It follows Kubernetes-style resource conventions with Kind, APIVersion, and Metadata fields.
func New ¶
New creates a new Header instance with the provided functional options. The Metadata map is initialized automatically.
func (*Header) GetMetadata ¶
GetMetadata returns the Metadata map of the Header.
type Kind ¶
type Kind string
Kind represents the type of AICR resource. All AICR resources should use these constants for consistency.
const ( KindSnapshot Kind = "Snapshot" KindRecipe Kind = "Recipe" KindRecipeResult Kind = "RecipeResult" KindValidationResult Kind = "ValidationResult" )
Valid Kind constants for all AICR resource types.
type Option ¶
type Option func(*Header)
Option is a functional option for configuring Header instances.
func WithAPIVersion ¶
WithAPIVersion returns an Option that sets the APIVersion field of the Header. The APIVersion identifies the schema version for the resource.
func WithKind ¶
WithKind returns an Option that sets the Kind field of the Header. Kind represents the type of the resource (e.g., "Snapshot", "Recipe").
func WithMetadata ¶
WithMetadata returns an Option that adds a metadata key-value pair to the Header. If the Metadata map is nil, it will be initialized.