timonel 3.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +323 -695
  3. package/dist/cli.js +275 -15
  4. package/dist/index.d.ts +5 -1
  5. package/dist/index.js +12 -0
  6. package/dist/lib/helm.d.ts +471 -0
  7. package/dist/lib/helm.js +483 -0
  8. package/dist/lib/helmChartWriter.d.ts +157 -0
  9. package/dist/lib/helmChartWriter.js +171 -1
  10. package/dist/lib/policy/configurationLoader.d.ts +132 -0
  11. package/dist/lib/policy/configurationLoader.js +132 -0
  12. package/dist/lib/policy/errorContextGenerator.d.ts +89 -0
  13. package/dist/lib/policy/errorContextGenerator.js +99 -2
  14. package/dist/lib/policy/errors.d.ts +35 -0
  15. package/dist/lib/policy/errors.js +36 -0
  16. package/dist/lib/policy/index.d.ts +9 -0
  17. package/dist/lib/policy/index.js +16 -0
  18. package/dist/lib/policy/parallelExecutor.d.ts +90 -0
  19. package/dist/lib/policy/parallelExecutor.js +86 -3
  20. package/dist/lib/policy/pluginLoader.d.ts +92 -0
  21. package/dist/lib/policy/pluginLoader.js +92 -1
  22. package/dist/lib/policy/pluginRegistry.d.ts +54 -0
  23. package/dist/lib/policy/pluginRegistry.js +56 -0
  24. package/dist/lib/policy/policyEngine.d.ts +137 -0
  25. package/dist/lib/policy/policyEngine.js +191 -5
  26. package/dist/lib/policy/resultAggregator.d.ts +46 -0
  27. package/dist/lib/policy/resultAggregator.js +69 -1
  28. package/dist/lib/policy/resultFormatter.d.ts +88 -0
  29. package/dist/lib/policy/resultFormatter.js +101 -0
  30. package/dist/lib/policy/types.d.ts +136 -0
  31. package/dist/lib/policy/types.js +8 -0
  32. package/dist/lib/policy/validationCache.d.ts +146 -0
  33. package/dist/lib/policy/validationCache.js +142 -6
  34. package/dist/lib/resources/baseResourceProvider.d.ts +45 -0
  35. package/dist/lib/resources/baseResourceProvider.js +48 -1
  36. package/dist/lib/resources/cloud/aws/awsResources.d.ts +192 -0
  37. package/dist/lib/resources/cloud/aws/awsResources.js +163 -1
  38. package/dist/lib/resources/cloud/aws/karpenterResources.d.ts +131 -0
  39. package/dist/lib/resources/cloud/aws/karpenterResources.js +77 -0
  40. package/dist/lib/rutter.d.ts +381 -3
  41. package/dist/lib/rutter.js +439 -28
  42. package/dist/lib/security.d.ts +123 -0
  43. package/dist/lib/security.js +162 -4
  44. package/dist/lib/templates/flexible-subchart.d.ts +52 -0
  45. package/dist/lib/templates/flexible-subchart.js +70 -0
  46. package/dist/lib/templates/umbrella-chart.d.ts +27 -0
  47. package/dist/lib/templates/umbrella-chart.js +89 -0
  48. package/dist/lib/types.d.ts +26 -0
  49. package/dist/lib/umbrella.d.ts +23 -0
  50. package/dist/lib/umbrella.js +23 -0
  51. package/dist/lib/umbrellaRutter.d.ts +75 -0
  52. package/dist/lib/umbrellaRutter.js +82 -2
  53. package/dist/lib/utils/envVarsLoader.d.ts +49 -0
  54. package/dist/lib/utils/envVarsLoader.js +53 -0
  55. package/dist/lib/utils/helmConstructSerializer.d.ts +17 -0
  56. package/dist/lib/utils/helmConstructSerializer.js +22 -0
  57. package/dist/lib/utils/helmControlStructures.d.ts +194 -0
  58. package/dist/lib/utils/helmControlStructures.js +180 -0
  59. package/dist/lib/utils/helmHelpers/envHelpers.d.ts +13 -0
  60. package/dist/lib/utils/helmHelpers/envHelpers.js +13 -0
  61. package/dist/lib/utils/helmHelpers/gitopsHelpers.d.ts +13 -0
  62. package/dist/lib/utils/helmHelpers/gitopsHelpers.js +13 -0
  63. package/dist/lib/utils/helmHelpers/index.d.ts +74 -0
  64. package/dist/lib/utils/helmHelpers/index.js +85 -1
  65. package/dist/lib/utils/helmHelpers/observabilityHelpers.d.ts +13 -0
  66. package/dist/lib/utils/helmHelpers/observabilityHelpers.js +13 -0
  67. package/dist/lib/utils/helmHelpers/types.d.ts +23 -0
  68. package/dist/lib/utils/helmHelpers/types.js +4 -0
  69. package/dist/lib/utils/helmHelpers/validationHelpers.d.ts +13 -0
  70. package/dist/lib/utils/helmHelpers/validationHelpers.js +13 -0
  71. package/dist/lib/utils/helmHelpers.d.ts +62 -0
  72. package/dist/lib/utils/helmHelpers.js +77 -0
  73. package/dist/lib/utils/helmYamlSerializer.d.ts +77 -0
  74. package/dist/lib/utils/helmYamlSerializer.js +398 -21
  75. package/dist/lib/utils/logger.d.ts +153 -0
  76. package/dist/lib/utils/logger.js +170 -2
  77. package/dist/lib/utils/valuesRef.d.ts +181 -50
  78. package/dist/lib/utils/valuesRef.js +168 -170
  79. package/dist/lib/validation/inputValidator.d.ts +45 -0
  80. package/dist/lib/validation/inputValidator.js +67 -2
  81. package/dist/types/index.d.ts +34 -0
  82. package/dist/types/index.js +3 -0
  83. package/package.json +31 -38
@@ -1,8 +1,19 @@
1
+ /**
2
+ * Policy Engine Type Definitions
3
+ *
4
+ * This module defines the core types and interfaces for the Timonel Policy Engine system.
5
+ * The policy engine provides extensible validation of Kubernetes manifests through plugins.
6
+ *
7
+ * @since 3.0.0
8
+ */
1
9
  import type { TimonelLogger } from '../utils/logger.js';
2
10
  import type { ChartMetadata } from '../rutter.js';
3
11
  import type { ValidationOptions } from '../validation/inputValidator.js';
4
12
  import type { CacheOptions } from './validationCache.js';
5
13
  import type { ParallelExecutionOptions } from './parallelExecutor.js';
14
+ /**
15
+ * JSON Schema type for plugin configuration validation
16
+ */
6
17
  export interface JSONSchema {
7
18
  type?: string;
8
19
  properties?: Record<string, JSONSchema>;
@@ -10,102 +21,227 @@ export interface JSONSchema {
10
21
  additionalProperties?: boolean | JSONSchema;
11
22
  [key: string]: unknown;
12
23
  }
24
+ /**
25
+ * Plugin metadata for discovery and compatibility
26
+ */
13
27
  export interface PluginMetadata {
28
+ /** Plugin author information */
14
29
  author?: string;
30
+ /** Plugin license */
15
31
  license?: string;
32
+ /** Plugin homepage URL */
16
33
  homepage?: string;
34
+ /** Plugin repository URL */
17
35
  repository?: string;
36
+ /** Supported Kubernetes versions */
18
37
  kubernetesVersions?: string[];
38
+ /** Plugin tags for categorization */
19
39
  tags?: string[];
40
+ /** Default configuration for the plugin */
20
41
  defaultConfig?: Record<string, unknown>;
21
42
  }
43
+ /**
44
+ * Validation context provided to plugins during execution
45
+ */
22
46
  export interface ValidationContext {
47
+ /** Chart metadata */
23
48
  readonly chart: ChartMetadata;
49
+ /** Target Kubernetes version */
24
50
  readonly kubernetesVersion?: string;
51
+ /** Deployment environment */
25
52
  readonly environment?: string;
53
+ /** Plugin-specific configuration */
26
54
  readonly config?: Record<string, unknown>;
55
+ /** Logger instance */
27
56
  readonly logger: TimonelLogger;
28
57
  }
58
+ /**
59
+ * Policy violation reported by plugins
60
+ */
29
61
  export interface PolicyViolation {
62
+ /** Plugin that detected the violation */
30
63
  readonly plugin: string;
64
+ /** Severity level of the violation */
31
65
  readonly severity: 'error' | 'warning' | 'info';
66
+ /** Human-readable violation message */
32
67
  readonly message: string;
68
+ /** Path to the violating resource */
33
69
  readonly resourcePath?: string;
70
+ /** Specific field that caused the violation */
34
71
  readonly field?: string;
72
+ /** Suggested remediation steps */
35
73
  readonly suggestion?: string;
74
+ /** Additional context data */
36
75
  readonly context?: Record<string, unknown>;
37
76
  }
77
+ /**
78
+ * Policy warning (non-blocking violation)
79
+ */
38
80
  export interface PolicyWarning extends Omit<PolicyViolation, 'severity'> {
39
81
  readonly severity: 'warning' | 'info';
40
82
  }
83
+ /**
84
+ * Validation execution metadata
85
+ */
41
86
  export interface ValidationMetadata {
87
+ /** Total execution time in milliseconds */
42
88
  readonly executionTime: number;
89
+ /** Number of plugins executed */
43
90
  readonly pluginCount: number;
91
+ /** Number of manifests validated */
44
92
  readonly manifestCount: number;
93
+ /** Timestamp when validation started */
45
94
  readonly startTime?: number;
95
+ /** Additional metadata */
46
96
  readonly [key: string]: unknown;
47
97
  }
98
+ /**
99
+ * Complete validation result
100
+ */
48
101
  export interface PolicyResult {
102
+ /** Overall validation success status */
49
103
  readonly valid: boolean;
104
+ /** Array of policy violations found */
50
105
  readonly violations: PolicyViolation[];
106
+ /** Non-blocking warnings */
51
107
  readonly warnings: PolicyWarning[];
108
+ /** Execution metadata */
52
109
  readonly metadata: ValidationMetadata;
110
+ /** Summary statistics for quick overview */
53
111
  readonly summary?: ResultSummary;
54
112
  }
113
+ /**
114
+ * Summary statistics for validation results
115
+ */
55
116
  export interface ResultSummary {
117
+ /** Total number of violations by severity */
56
118
  readonly violationsBySeverity: {
57
119
  readonly error: number;
58
120
  readonly warning: number;
59
121
  readonly info: number;
60
122
  };
123
+ /** Violations grouped by plugin */
61
124
  readonly violationsByPlugin: Record<string, number>;
125
+ /** Most common violation types */
62
126
  readonly topViolationTypes: Array<{
63
127
  readonly type: string;
64
128
  readonly count: number;
65
129
  }>;
66
130
  }
131
+ /**
132
+ * Policy plugin interface that all plugins must implement
133
+ */
67
134
  export interface PolicyPlugin {
135
+ /** Unique plugin identifier */
68
136
  readonly name: string;
137
+ /** Semantic version of the plugin */
69
138
  readonly version: string;
139
+ /** Human-readable description */
70
140
  readonly description?: string;
141
+ /**
142
+ * Validates manifests and returns violations
143
+ * @param manifests - Kubernetes manifests to validate
144
+ * @param context - Validation context and configuration
145
+ * @returns Promise resolving to validation results
146
+ */
71
147
  validate(manifests: unknown[], context: ValidationContext): Promise<PolicyViolation[]>;
148
+ /** Optional plugin configuration schema */
72
149
  readonly configSchema?: JSONSchema;
150
+ /** Plugin metadata for discovery and compatibility */
73
151
  readonly metadata?: PluginMetadata;
74
152
  }
153
+ /**
154
+ * Result formatter interface for custom output formatting
155
+ */
75
156
  export interface ResultFormatter {
157
+ /**
158
+ * Formats validation results for output
159
+ * @param result - Validation result to format
160
+ * @returns Formatted string representation
161
+ */
76
162
  format(result: PolicyResult): string;
77
163
  }
164
+ /**
165
+ * Retry configuration for plugin execution
166
+ */
78
167
  export interface RetryConfig {
168
+ /** Maximum number of retry attempts */
79
169
  maxAttempts: number;
170
+ /** Base delay between retries in milliseconds */
80
171
  baseDelay: number;
172
+ /** Exponential backoff multiplier */
81
173
  backoffMultiplier: number;
174
+ /** Maximum delay between retries in milliseconds */
82
175
  maxDelay: number;
176
+ /** Whether to retry on timeout errors */
83
177
  retryOnTimeout: boolean;
178
+ /** Whether to retry on plugin errors */
84
179
  retryOnPluginError: boolean;
85
180
  }
181
+ /**
182
+ * Configuration loader options
183
+ */
86
184
  export interface ConfigurationLoaderOptions {
185
+ /** Default environment if not specified */
87
186
  defaultEnvironment?: string;
187
+ /** Whether to validate configurations against schemas */
88
188
  validateSchemas?: boolean;
189
+ /** Whether to allow unknown properties in configurations */
89
190
  allowUnknownProperties?: boolean;
191
+ /** Configuration file paths to load */
90
192
  configurationFiles?: string[];
193
+ /** Environment variable prefix for configuration */
91
194
  environmentPrefix?: string;
92
195
  }
196
+ /**
197
+ * Policy engine configuration options
198
+ */
93
199
  export interface PolicyEngineOptions {
200
+ /** Maximum time to wait for plugin execution (milliseconds) */
94
201
  timeout?: number;
202
+ /** Whether to run plugins in parallel */
95
203
  parallel?: boolean;
204
+ /** Fail fast on first error or collect all violations */
96
205
  failFast?: boolean;
206
+ /** Custom result formatter */
97
207
  formatter?: ResultFormatter;
208
+ /** Plugin-specific configuration */
98
209
  pluginConfig?: Record<string, unknown>;
210
+ /** Retry configuration for plugin execution */
99
211
  retryConfig?: RetryConfig;
212
+ /** Whether to enable graceful degradation on plugin failures */
100
213
  gracefulDegradation?: boolean;
214
+ /** Configuration loader options */
101
215
  configurationLoader?: ConfigurationLoaderOptions;
216
+ /** Target environment for configuration loading */
102
217
  environment?: string;
218
+ /** Cache configuration options */
103
219
  cacheOptions?: CacheOptions;
220
+ /** Parallel execution configuration options */
104
221
  parallelOptions?: ParallelExecutionOptions;
222
+ /** Input validation configuration options */
105
223
  validationOptions?: ValidationOptions;
106
224
  }
225
+ /**
226
+ * Main policy engine interface
227
+ */
107
228
  export interface PolicyEngine {
229
+ /**
230
+ * Registers a policy plugin for validation
231
+ * @param plugin - The policy plugin to register
232
+ * @returns Promise resolving to the engine instance for method chaining
233
+ */
108
234
  use(plugin: PolicyPlugin): Promise<PolicyEngine>;
235
+ /**
236
+ * Validates Kubernetes manifests against registered policies
237
+ * @param manifests - Array of Kubernetes manifest objects
238
+ * @param chartMetadata - Chart metadata for validation context
239
+ * @returns Promise resolving to validation results
240
+ */
109
241
  validate(manifests: unknown[], chartMetadata: ChartMetadata): Promise<PolicyResult>;
242
+ /**
243
+ * Configures engine-wide settings
244
+ * @param options - Configuration options
245
+ */
110
246
  configure(options: PolicyEngineOptions): PolicyEngine;
111
247
  }
@@ -1 +1,9 @@
1
+ /**
2
+ * Policy Engine Type Definitions
3
+ *
4
+ * This module defines the core types and interfaces for the Timonel Policy Engine system.
5
+ * The policy engine provides extensible validation of Kubernetes manifests through plugins.
6
+ *
7
+ * @since 3.0.0
8
+ */
1
9
  export {};
@@ -1,58 +1,204 @@
1
+ /**
2
+ * Validation Result Cache Implementation
3
+ *
4
+ * This module provides caching functionality for policy validation results to optimize
5
+ * performance for repeated manifest validations. It implements cache invalidation
6
+ * strategies and optimizations for large chart processing.
7
+ *
8
+ * @since 3.0.0
9
+ */
1
10
  import type { PolicyResult } from './types.js';
11
+ /**
12
+ * Cache entry metadata
13
+ */
2
14
  export interface CacheEntry {
15
+ /** Cached validation result */
3
16
  readonly result: PolicyResult;
17
+ /** Timestamp when entry was created */
4
18
  readonly timestamp: number;
19
+ /** Hash of the manifests that were validated */
5
20
  readonly manifestHash: string;
21
+ /** Hash of the plugin configuration used */
6
22
  readonly pluginHash: string;
23
+ /** Number of times this entry has been accessed */
7
24
  accessCount: number;
25
+ /** Last access timestamp */
8
26
  lastAccessed: number;
9
27
  }
28
+ /**
29
+ * Cache configuration options
30
+ */
10
31
  export interface CacheOptions {
32
+ /** Maximum number of entries to store */
11
33
  maxEntries?: number;
34
+ /** Maximum age of cache entries in milliseconds */
12
35
  maxAge?: number;
36
+ /** Whether to enable cache compression */
13
37
  enableCompression?: boolean;
38
+ /** Cache eviction strategy */
14
39
  evictionStrategy?: 'lru' | 'lfu' | 'ttl';
40
+ /** Whether to cache results with violations */
15
41
  cacheFailures?: boolean;
42
+ /** Minimum execution time to cache (avoid caching very fast validations) */
16
43
  minExecutionTimeToCache?: number;
17
44
  }
45
+ /**
46
+ * Cache statistics for monitoring
47
+ */
18
48
  export interface CacheStats {
49
+ /** Total number of cache hits */
19
50
  hits: number;
51
+ /** Total number of cache misses */
20
52
  misses: number;
53
+ /** Current number of entries in cache */
21
54
  entries: number;
55
+ /** Total memory usage estimate in bytes */
22
56
  memoryUsage: number;
57
+ /** Cache hit ratio (0-1) */
23
58
  hitRatio: number;
59
+ /** Average access count per entry */
24
60
  averageAccessCount: number;
25
61
  }
62
+ /**
63
+ * Validation result cache implementation
64
+ */
26
65
  export declare class ValidationCache {
27
66
  private readonly cache;
28
67
  private readonly options;
29
68
  private readonly logger;
30
69
  private stats;
31
70
  constructor(options?: CacheOptions);
71
+ /**
72
+ * Gets a cached validation result if available
73
+ * @param manifestHash - Hash of the manifests
74
+ * @param pluginHash - Hash of the plugin configuration
75
+ * @returns Cached result or undefined if not found
76
+ */
32
77
  get(manifestHash: string, pluginHash: string): PolicyResult | undefined;
78
+ /**
79
+ * Stores a validation result in the cache
80
+ * @param manifestHash - Hash of the manifests
81
+ * @param pluginHash - Hash of the plugin configuration
82
+ * @param result - Validation result to cache
83
+ */
33
84
  set(manifestHash: string, pluginHash: string, result: PolicyResult): void;
85
+ /**
86
+ * Invalidates cache entries based on criteria
87
+ * @param criteria - Invalidation criteria
88
+ */
34
89
  invalidate(criteria: {
35
90
  manifestHash?: string;
36
91
  pluginHash?: string;
37
92
  olderThan?: number;
38
93
  all?: boolean;
39
94
  }): number;
95
+ /**
96
+ * Invalidates all cache entries
97
+ * @returns Number of invalidated entries
98
+ * @private
99
+ */
40
100
  private invalidateAll;
101
+ /**
102
+ * Invalidates cache entries based on selective criteria
103
+ * @param criteria - Invalidation criteria
104
+ * @returns Number of invalidated entries
105
+ * @private
106
+ */
41
107
  private invalidateSelective;
108
+ /**
109
+ * Determines if a cache entry should be invalidated
110
+ * @param entry - Cache entry to check
111
+ * @param criteria - Invalidation criteria
112
+ * @returns True if entry should be invalidated
113
+ * @private
114
+ */
42
115
  private shouldInvalidateEntry;
116
+ /**
117
+ * Gets current cache statistics
118
+ * @returns Cache statistics
119
+ */
43
120
  getStats(): CacheStats;
121
+ /**
122
+ * Clears all cache statistics
123
+ */
44
124
  clearStats(): void;
125
+ /**
126
+ * Generates a cache key from manifest and plugin hashes
127
+ * @param manifestHash - Hash of the manifests
128
+ * @param pluginHash - Hash of the plugin configuration
129
+ * @returns Cache key string
130
+ * @private
131
+ */
45
132
  private generateCacheKey;
133
+ /**
134
+ * Checks if a cache entry has expired
135
+ * @param entry - Cache entry to check
136
+ * @returns True if expired
137
+ * @private
138
+ */
46
139
  private isExpired;
140
+ /**
141
+ * Determines if a validation result should be cached
142
+ * @param result - Validation result
143
+ * @returns True if should be cached
144
+ * @private
145
+ */
47
146
  private shouldCache;
147
+ /**
148
+ * Evicts cache entries based on the configured strategy
149
+ * @private
150
+ */
48
151
  private evictEntries;
152
+ /**
153
+ * Evicts least recently used entries
154
+ * @param count - Number of entries to evict
155
+ * @private
156
+ */
49
157
  private evictLRU;
158
+ /**
159
+ * Evicts least frequently used entries
160
+ * @param count - Number of entries to evict
161
+ * @private
162
+ */
50
163
  private evictLFU;
164
+ /**
165
+ * Evicts oldest entries (time to live)
166
+ * @param count - Number of entries to evict
167
+ * @private
168
+ */
51
169
  private evictTTL;
170
+ /**
171
+ * Updates cache statistics
172
+ * @private
173
+ */
52
174
  private updateStats;
175
+ /**
176
+ * Estimates memory usage of the cache
177
+ * @returns Estimated memory usage in bytes
178
+ * @private
179
+ */
53
180
  private estimateMemoryUsage;
181
+ /**
182
+ * Starts periodic cleanup of expired entries
183
+ * @private
184
+ */
54
185
  private startPeriodicCleanup;
186
+ /**
187
+ * Removes expired entries from the cache
188
+ * @private
189
+ */
55
190
  private cleanupExpiredEntries;
56
191
  }
192
+ /**
193
+ * Utility function to generate a hash from manifests
194
+ * @param manifests - Array of manifest objects
195
+ * @returns Hash string
196
+ */
57
197
  export declare function generateManifestHash(manifests: unknown[]): string;
198
+ /**
199
+ * Utility function to generate a hash from plugin configuration
200
+ * @param plugins - Array of plugin names
201
+ * @param pluginConfigs - Plugin configurations
202
+ * @returns Hash string
203
+ */
58
204
  export declare function generatePluginHash(plugins: string[], pluginConfigs: Record<string, unknown>): string;