sherpack-core
Core types and utilities for Sherpack - the Kubernetes package manager with Jinja2 templates.
Overview
sherpack-core provides the foundational data structures and utilities used throughout the Sherpack ecosystem. This crate is dependency-free from Kubernetes APIs, making it suitable for offline operations like templating, packaging, and validation.
Features
- Pack Definition - Complete package metadata and dependency management
- Values System - Deep merge support for configuration values
- Release Tracking - Deployment state management
- Schema Validation - JSON Schema and simplified Sherpack format support
- Archive Operations - Create, extract, and verify
.tgzpackages - Manifest Generation - SHA256 checksums for integrity verification
Modules
pack - Package Definition
The core Pack structure represents a Sherpack package (equivalent to a Helm Chart).
use ;
// Load a pack from disk
let pack = load?;
println!;
// Access dependencies
for dep in &pack.pack.dependencies
Pack.yaml Structure
apiVersion: sherpack/v1
kind: application # or 'library'
metadata:
name: my-app
version: 1.0.0
description: My application
appVersion: "2.0"
keywords:
- web
- api
maintainers:
- name: John Doe
email: john@example.com
dependencies:
- name: redis
version: "^17.0.0"
repository: https://charts.bitnami.com/bitnami
condition: redis.enabled # Evaluated against values.yaml
enabled: true # Static enable/disable
resolve: when-enabled # always | when-enabled | never
alias: cache # Optional rename
Dependency Resolution Control
use ;
let dep = Dependency ;
// Check if dependency should be resolved
let values = json!;
assert!;
values - Configuration Values
Deep merge support for layered configuration.
use ;
// Load from file
let mut values = from_file?;
// Parse CLI --set arguments
let overrides = parse_set_values?;
// Deep merge (overrides win)
values.merge;
// Access nested values
let tag = values.get; // Some("v2.0")
Merge Semantics
| Base | Overlay | Result |
|---|---|---|
{ a: 1 } |
{ a: 2 } |
{ a: 2 } (scalar: replace) |
{ a: { b: 1 } } |
{ a: { c: 2 } } |
{ a: { b: 1, c: 2 } } (object: merge) |
[1, 2] |
[3, 4] |
[3, 4] (array: replace, not append) |
schema - Values Validation
Dual-format schema support for validating configuration.
use ;
// Load schema (auto-detects format)
let schema = load?;
let validator = new?;
// Validate values
let values = json!;
match validator.validate
// Extract defaults from schema
let defaults = schema.extract_defaults;
Supported Schema Formats
JSON Schema (standard)
$schema: "https://json-schema.org/draft/2020-12/schema"
type: object
properties:
replicas:
type: integer
minimum: 1
default: 1
required:
- replicas
Sherpack Simplified Format
schemaVersion: "1"
properties:
replicas:
type: int
required: true
default: 1
min: 1
description: Number of pod replicas
image.tag:
type: string
default: latest
release - Deployment State
Track deployment lifecycle.
use ;
use Utc;
let release = Release ;
Release Statuses
| Status | Description |
|---|---|
Pending |
Installation/upgrade in progress |
Deployed |
Successfully deployed |
Failed |
Deployment failed |
Superseded |
Replaced by newer revision |
Uninstalling |
Uninstall in progress |
Uninstalled |
Successfully uninstalled |
context - Template Context
Build the context passed to templates.
use ;
let context = new;
// Serialize for template engine
let ctx_value = context.to_value?;
// Contains: values, release, pack, capabilities
archive - Package Archives
Create and manage .tgz packages with integrity verification.
use ;
use Path;
// Create archive
create_archive?;
// List contents
for entry in list_archive?
// Extract
extract_archive?;
// Verify integrity
let result = verify_archive?;
if result.is_valid else
manifest - Integrity Manifests
SHA256 checksums for all pack files.
use ;
use Path;
// Generate manifest for a directory
let manifest = generate?;
// Manifest format (YAML)
// sherpack-manifest-version: "1"
// files:
// Pack.yaml: sha256:abc123...
// values.yaml: sha256:def456...
// templates/deployment.yaml: sha256:...
// Verify against manifest
let result = manifest.verify?;
match result
Error Handling
All errors are strongly typed using thiserror:
use ;
match pack_operation
Dependencies
serde/serde_yaml/serde_json- Serializationsemver- Semantic versioningjsonschema- JSON Schema validationsha2- SHA256 checksumstar/flate2- Archive operationschrono- Timestampsthiserror- Error handling
License
MIT OR Apache-2.0