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
//! Kubernetes Resource Optimization Analyzer
//!
//! A native Rust analyzer for detecting over-provisioned and under-provisioned
//! Kubernetes workloads. Helps reduce cloud costs by right-sizing resource
//! requests and limits.
//!
//! # Features
//!
//! ## Phase 1: Static Analysis
//! - Static analysis of Kubernetes manifests (no cluster access required)
//! - **Terraform HCL support** - Parse `kubernetes_*` provider resources
//! - Pattern-based detection of over/under-provisioning
//! - Workload type classification for smarter recommendations
//! - Support for Deployments, StatefulSets, DaemonSets, Jobs, CronJobs
//! - Helm chart and Kustomize directory support
//! - Multiple output formats (table, JSON)
//!
//! ## Phase 2: Live Cluster Analysis
//! - **Kubernetes API integration** - Connect to real clusters via kubeconfig
//! - **metrics-server support** - Real-time CPU/memory usage data
//! - **Prometheus integration** - Historical metrics (P50, P95, P99, max)
//! - Data-driven recommendations based on actual usage
//! - Waste percentage calculations with confidence levels
//!
//! # Example
//!
//! ```rust,ignore
//! use syncable_cli::analyzer::k8s_optimize::{lint, K8sOptimizeConfig, OptimizationResult};
//! use std::path::Path;
//!
//! // Static analysis (no cluster needed)
//! let config = K8sOptimizeConfig::default();
//! let result = lint(Path::new("./k8s/"), &config);
//!
//! // Or using the backward-compatible analyze() function:
//! let result = analyze(Path::new("./k8s/"), &config);
//!
//! // Live cluster analysis (requires kubeconfig)
//! use syncable_cli::analyzer::k8s_optimize::live_analyzer::{LiveAnalyzer, LiveAnalyzerConfig};
//! let live_config = LiveAnalyzerConfig::default();
//! let analyzer = LiveAnalyzer::new(live_config).await?;
//! let live_result = analyzer.analyze().await?;
//! ```
//!
//! # Optimization Rules
//!
//! The analyzer checks for these common issues (K8S-OPT-001 through K8S-OPT-010):
//!
//! ## Over-Provisioning Detection
//! - K8S-OPT-005: CPU request > 1 core for non-batch workload
//! - K8S-OPT-006: Memory request > 2Gi for non-database workload
//! - K8S-OPT-007: Excessive CPU limit-to-request ratio (> 10x)
//! - K8S-OPT-008: Excessive memory limit-to-request ratio (> 4x)
//!
//! ## Under-Provisioning Detection
//! - K8S-OPT-001: No CPU request defined
//! - K8S-OPT-002: No memory request defined
//! - K8S-OPT-003: No CPU limit defined
//! - K8S-OPT-004: No memory limit defined
//!
//! ## Best Practices
//! - K8S-OPT-009: Requests equal to limits (no bursting allowed)
//! - K8S-OPT-010: Unbalanced resource allocation for workload type
// ============================================================================
// Core modules (new structure)
// ============================================================================
/// Configuration for the optimizer.
/// Core data types.
/// Parsing utilities (YAML, Terraform, Helm).
/// Output formatting (table, JSON, YAML).
/// Individual optimization rules (K8S-OPT-001 through K8S-OPT-010).
/// Annotation-based rule ignoring (pragma).
// ============================================================================
// Analysis modules
// ============================================================================
/// Static analysis of Kubernetes manifests.
/// Recommendation generation (now in rules/).
/// Terraform parser (now in parser/terraform.rs, re-exported for compatibility).
// ============================================================================
// Live cluster analysis modules
// ============================================================================
/// Live cluster analyzer.
/// Kubernetes metrics-server client.
/// Prometheus client for historical metrics.
// ============================================================================
// Cost and fix modules
// ============================================================================
/// Cost calculation and estimation.
/// Trend analysis.
/// Fix application to manifest files.
// ============================================================================
// Placeholder subfolders (for future organization)
// ============================================================================
/// Live analysis subfolder (future home for live_analyzer, metrics_client, prometheus_client).
/// Cost analysis subfolder (future home for cost_calculator, trend_analyzer).
/// Fix application subfolder (future home for fix_applicator).
// ============================================================================
// Re-exports: Configuration
// ============================================================================
pub use K8sOptimizeConfig;
// ============================================================================
// Re-exports: Core types
// ============================================================================
pub use ;
// ============================================================================
// Re-exports: Formatting
// ============================================================================
pub use ;
// ============================================================================
// Re-exports: Static analysis (primary API)
// ============================================================================
// Primary API - new lint() functions
pub use ;
// Backward compatibility - keep analyze() functions
pub use ;
// ============================================================================
// Re-exports: Parser utilities
// ============================================================================
pub use ;
// ============================================================================
// Re-exports: Rules
// ============================================================================
pub use ;
// ============================================================================
// Re-exports: Pragma (annotation-based ignores)
// ============================================================================
pub use ;
// ============================================================================
// Re-exports: Live cluster analysis
// ============================================================================
pub use ;
pub use ;
pub use ;
// ============================================================================
// Re-exports: Cost estimation and trends
// ============================================================================
pub use ;
pub use ;
pub use ;