| Crates.io | sal-kubernetes |
| lib.rs | sal-kubernetes |
| version | 0.1.0 |
| created_at | 2025-06-30 17:37:25.868615+00 |
| updated_at | 2025-06-30 17:37:25.868615+00 |
| description | SAL Kubernetes - Kubernetes cluster management and operations using kube-rs SDK |
| homepage | |
| repository | https://git.threefold.info/herocode/sal |
| max_upload_size | |
| id | 1732126 |
| size | 206,462 |
Kubernetes cluster management and operations for the System Abstraction Layer (SAL).
This package includes destructive operations that can permanently delete Kubernetes resources!
delete(pattern) function uses PCRE regex patterns to bulk delete resourcesThis package provides a high-level interface for managing Kubernetes clusters using the kube-rs SDK. It focuses on namespace-scoped operations through the KubernetesManager factory pattern.
KubernetesManager instance operates on a single namespaceuse sal_kubernetes::KubernetesManager;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a manager for the "default" namespace
let km = KubernetesManager::new("default").await?;
// List all pods in the namespace
let pods = km.pods_list().await?;
println!("Found {} pods", pods.len());
// Create a namespace (no error if it already exists)
km.namespace_create("my-namespace").await?;
// Delete resources matching a pattern
km.delete("test-.*").await?;
Ok(())
}
// Create Kubernetes manager for namespace
let km = kubernetes_manager_new("default");
// List pods
let pods = pods_list(km);
print("Found " + pods.len() + " pods");
// Create namespace
namespace_create(km, "my-app");
// Delete test resources
delete(km, "test-.*");
kube: Kubernetes client libraryk8s-openapi: Kubernetes API typestokio: Async runtimeregex: Pattern matching for resource deletionrhai: Scripting integration (optional)The package uses the standard Kubernetes configuration methods:
~/.kube/config or KUBECONFIG environment variable)use sal_kubernetes::{KubernetesManager, KubernetesConfig};
use std::time::Duration;
// Create with custom configuration
let config = KubernetesConfig::new()
.with_timeout(Duration::from_secs(60))
.with_retries(5, Duration::from_secs(1), Duration::from_secs(30))
.with_rate_limit(20, 50);
let km = KubernetesManager::with_config("my-namespace", config).await?;
// High-throughput environment
let config = KubernetesConfig::high_throughput();
// Low-latency environment
let config = KubernetesConfig::low_latency();
// Development/testing
let config = KubernetesConfig::development();
All operations return Result<T, KubernetesError> with comprehensive error types for different failure scenarios including API errors, configuration issues, and permission problems.
The main interface for Kubernetes operations. Each instance is scoped to a single namespace.
KubernetesManager::new(namespace) - Create a manager for the specified namespacepods_list() - List all pods in the namespaceservices_list() - List all services in the namespacedeployments_list() - List all deployments in the namespaceconfigmaps_list() - List all configmaps in the namespacesecrets_list() - List all secrets in the namespacepod_get(name) - Get a specific pod by nameservice_get(name) - Get a specific service by namedeployment_get(name) - Get a specific deployment by namepod_delete(name) - Delete a specific pod by nameservice_delete(name) - Delete a specific service by namedeployment_delete(name) - Delete a specific deployment by namedelete(pattern) - Delete all resources matching a PCRE patternnamespace_create(name) - Create a namespace (idempotent)namespace_exists(name) - Check if a namespace existsnamespaces_list() - List all namespaces (cluster-wide)resource_counts() - Get counts of all resource types in the namespacenamespace() - Get the namespace this manager operates onWhen using the Rhai integration, the following functions are available:
kubernetes_manager_new(namespace) - Create a KubernetesManagerpods_list(km) - List podsservices_list(km) - List servicesdeployments_list(km) - List deploymentsnamespaces_list(km) - List all namespacesdelete(km, pattern) - Delete resources matching patternnamespace_create(km, name) - Create namespacenamespace_exists(km, name) - Check namespace existenceresource_counts(km) - Get resource countspod_delete(km, name) - Delete specific podservice_delete(km, name) - Delete specific servicedeployment_delete(km, name) - Delete specific deploymentnamespace(km) - Get manager's namespaceThe examples/kubernetes/ directory contains comprehensive examples:
basic_operations.rhai - Basic listing and counting operationsnamespace_management.rhai - Creating and managing namespacespattern_deletion.rhai - Using PCRE patterns for bulk deletionmulti_namespace_operations.rhai - Working across multiple namespacesRun tests with:
# Unit tests (no cluster required)
cargo test --package sal-kubernetes
# Integration tests (requires cluster)
KUBERNETES_TEST_ENABLED=1 cargo test --package sal-kubernetes
# Rhai integration tests
KUBERNETES_TEST_ENABLED=1 cargo test --package sal-kubernetes --features rhai