- Add Kubernetes cluster management and operations - Include pod, service, and deployment management - Implement pattern-based resource deletion - Support namespace creation and management - Provide Rhai scripting wrappers for all functions - Include production safety features (timeouts, retries, rate limiting)
114 lines
3.3 KiB
Rust
114 lines
3.3 KiB
Rust
//! Configuration for production safety features
|
|
|
|
use std::time::Duration;
|
|
|
|
/// Configuration for Kubernetes operations with production safety features
|
|
#[derive(Debug, Clone)]
|
|
pub struct KubernetesConfig {
|
|
/// Timeout for individual API operations
|
|
pub operation_timeout: Duration,
|
|
|
|
/// Maximum number of retry attempts for failed operations
|
|
pub max_retries: u32,
|
|
|
|
/// Base delay for exponential backoff retry strategy
|
|
pub retry_base_delay: Duration,
|
|
|
|
/// Maximum delay between retries
|
|
pub retry_max_delay: Duration,
|
|
|
|
/// Rate limiting: maximum requests per second
|
|
pub rate_limit_rps: u32,
|
|
|
|
/// Rate limiting: burst capacity
|
|
pub rate_limit_burst: u32,
|
|
}
|
|
|
|
impl Default for KubernetesConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
// Conservative timeout for production
|
|
operation_timeout: Duration::from_secs(30),
|
|
|
|
// Reasonable retry attempts
|
|
max_retries: 3,
|
|
|
|
// Exponential backoff starting at 1 second
|
|
retry_base_delay: Duration::from_secs(1),
|
|
|
|
// Maximum 30 seconds between retries
|
|
retry_max_delay: Duration::from_secs(30),
|
|
|
|
// Conservative rate limiting: 10 requests per second
|
|
rate_limit_rps: 10,
|
|
|
|
// Allow small bursts
|
|
rate_limit_burst: 20,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl KubernetesConfig {
|
|
/// Create a new configuration with custom settings
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
/// Set operation timeout
|
|
pub fn with_timeout(mut self, timeout: Duration) -> Self {
|
|
self.operation_timeout = timeout;
|
|
self
|
|
}
|
|
|
|
/// Set retry configuration
|
|
pub fn with_retries(mut self, max_retries: u32, base_delay: Duration, max_delay: Duration) -> Self {
|
|
self.max_retries = max_retries;
|
|
self.retry_base_delay = base_delay;
|
|
self.retry_max_delay = max_delay;
|
|
self
|
|
}
|
|
|
|
/// Set rate limiting configuration
|
|
pub fn with_rate_limit(mut self, rps: u32, burst: u32) -> Self {
|
|
self.rate_limit_rps = rps;
|
|
self.rate_limit_burst = burst;
|
|
self
|
|
}
|
|
|
|
/// Create configuration optimized for high-throughput environments
|
|
pub fn high_throughput() -> Self {
|
|
Self {
|
|
operation_timeout: Duration::from_secs(60),
|
|
max_retries: 5,
|
|
retry_base_delay: Duration::from_millis(500),
|
|
retry_max_delay: Duration::from_secs(60),
|
|
rate_limit_rps: 50,
|
|
rate_limit_burst: 100,
|
|
}
|
|
}
|
|
|
|
/// Create configuration optimized for low-latency environments
|
|
pub fn low_latency() -> Self {
|
|
Self {
|
|
operation_timeout: Duration::from_secs(10),
|
|
max_retries: 2,
|
|
retry_base_delay: Duration::from_millis(100),
|
|
retry_max_delay: Duration::from_secs(5),
|
|
rate_limit_rps: 20,
|
|
rate_limit_burst: 40,
|
|
}
|
|
}
|
|
|
|
/// Create configuration for development/testing
|
|
pub fn development() -> Self {
|
|
Self {
|
|
operation_timeout: Duration::from_secs(120),
|
|
max_retries: 1,
|
|
retry_base_delay: Duration::from_millis(100),
|
|
retry_max_delay: Duration::from_secs(2),
|
|
rate_limit_rps: 100,
|
|
rate_limit_burst: 200,
|
|
}
|
|
}
|
|
}
|