timonel 2.8.0-beta.5 → 2.8.0

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 (128) hide show
  1. package/CHANGELOG.md +9 -25
  2. package/README.md +12 -55
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/{src/cli.js → cli.js} +4 -35
  5. package/dist/cli.js.map +1 -0
  6. package/dist/index.d.ts +14 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +13 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/{src/lib → lib}/helm.d.ts +234 -4
  11. package/dist/lib/helm.d.ts.map +1 -0
  12. package/dist/{src/lib → lib}/helm.js +309 -20
  13. package/dist/lib/helm.js.map +1 -0
  14. package/dist/lib/helmChartWriter.d.ts.map +1 -0
  15. package/dist/{src/lib → lib}/helmChartWriter.js +5 -19
  16. package/dist/lib/helmChartWriter.js.map +1 -0
  17. package/dist/{src/lib → lib}/resources/baseResourceProvider.d.ts +1 -1
  18. package/dist/lib/resources/baseResourceProvider.d.ts.map +1 -0
  19. package/dist/lib/resources/baseResourceProvider.js.map +1 -0
  20. package/dist/{src/lib → lib}/resources/cloud/aws/awsResources.d.ts +5 -14
  21. package/dist/lib/resources/cloud/aws/awsResources.d.ts.map +1 -0
  22. package/dist/{src/lib → lib}/resources/cloud/aws/awsResources.js +63 -78
  23. package/dist/lib/resources/cloud/aws/awsResources.js.map +1 -0
  24. package/dist/lib/resources/cloud/aws/karpenterResources.d.ts.map +1 -0
  25. package/dist/lib/resources/cloud/aws/karpenterResources.js.map +1 -0
  26. package/dist/lib/rutter.d.ts +445 -0
  27. package/dist/lib/rutter.d.ts.map +1 -0
  28. package/dist/lib/rutter.js +585 -0
  29. package/dist/lib/rutter.js.map +1 -0
  30. package/dist/{src/lib → lib}/security.d.ts +2 -72
  31. package/dist/lib/security.d.ts.map +1 -0
  32. package/dist/lib/security.js +390 -0
  33. package/dist/lib/security.js.map +1 -0
  34. package/dist/lib/umbrella.d.ts.map +1 -0
  35. package/dist/lib/umbrella.js.map +1 -0
  36. package/dist/{src/lib → lib}/umbrellaRutter.d.ts +1 -1
  37. package/dist/lib/umbrellaRutter.d.ts.map +1 -0
  38. package/dist/lib/umbrellaRutter.js.map +1 -0
  39. package/dist/{src/lib → lib}/utils/helmHelpers.d.ts +2 -12
  40. package/dist/lib/utils/helmHelpers.d.ts.map +1 -0
  41. package/dist/{src/lib → lib}/utils/helmHelpers.js +2 -46
  42. package/dist/lib/utils/helmHelpers.js.map +1 -0
  43. package/package.json +3 -4
  44. package/dist/src/cli.d.ts.map +0 -1
  45. package/dist/src/cli.js.map +0 -1
  46. package/dist/src/index.d.ts +0 -23
  47. package/dist/src/index.d.ts.map +0 -1
  48. package/dist/src/index.js +0 -15
  49. package/dist/src/index.js.map +0 -1
  50. package/dist/src/lib/constants.d.ts +0 -142
  51. package/dist/src/lib/constants.d.ts.map +0 -1
  52. package/dist/src/lib/constants.js +0 -167
  53. package/dist/src/lib/constants.js.map +0 -1
  54. package/dist/src/lib/helm.d.ts.map +0 -1
  55. package/dist/src/lib/helm.js.map +0 -1
  56. package/dist/src/lib/helmChartWriter.d.ts.map +0 -1
  57. package/dist/src/lib/helmChartWriter.js.map +0 -1
  58. package/dist/src/lib/resources/autoscaling/autoscalingResources.d.ts +0 -248
  59. package/dist/src/lib/resources/autoscaling/autoscalingResources.d.ts.map +0 -1
  60. package/dist/src/lib/resources/autoscaling/autoscalingResources.js +0 -81
  61. package/dist/src/lib/resources/autoscaling/autoscalingResources.js.map +0 -1
  62. package/dist/src/lib/resources/baseResourceProvider.d.ts.map +0 -1
  63. package/dist/src/lib/resources/baseResourceProvider.js.map +0 -1
  64. package/dist/src/lib/resources/cloud/aws/awsResources.d.ts.map +0 -1
  65. package/dist/src/lib/resources/cloud/aws/awsResources.js.map +0 -1
  66. package/dist/src/lib/resources/cloud/aws/karpenterResources.d.ts.map +0 -1
  67. package/dist/src/lib/resources/cloud/aws/karpenterResources.js.map +0 -1
  68. package/dist/src/lib/resources/cloud/azure/azureResources.d.ts +0 -169
  69. package/dist/src/lib/resources/cloud/azure/azureResources.d.ts.map +0 -1
  70. package/dist/src/lib/resources/cloud/azure/azureResources.js +0 -218
  71. package/dist/src/lib/resources/cloud/azure/azureResources.js.map +0 -1
  72. package/dist/src/lib/resources/cloud/gcp/gcpResources.d.ts +0 -164
  73. package/dist/src/lib/resources/cloud/gcp/gcpResources.d.ts.map +0 -1
  74. package/dist/src/lib/resources/cloud/gcp/gcpResources.js +0 -192
  75. package/dist/src/lib/resources/cloud/gcp/gcpResources.js.map +0 -1
  76. package/dist/src/lib/resources/core/coreResources.d.ts +0 -790
  77. package/dist/src/lib/resources/core/coreResources.d.ts.map +0 -1
  78. package/dist/src/lib/resources/core/coreResources.js +0 -1115
  79. package/dist/src/lib/resources/core/coreResources.js.map +0 -1
  80. package/dist/src/lib/resources/core/storageResources.d.ts +0 -133
  81. package/dist/src/lib/resources/core/storageResources.d.ts.map +0 -1
  82. package/dist/src/lib/resources/core/storageResources.js +0 -120
  83. package/dist/src/lib/resources/core/storageResources.js.map +0 -1
  84. package/dist/src/lib/resources/network/networkResources.d.ts +0 -515
  85. package/dist/src/lib/resources/network/networkResources.d.ts.map +0 -1
  86. package/dist/src/lib/resources/network/networkResources.js +0 -784
  87. package/dist/src/lib/resources/network/networkResources.js.map +0 -1
  88. package/dist/src/lib/resources/security/encryption.d.ts +0 -290
  89. package/dist/src/lib/resources/security/encryption.d.ts.map +0 -1
  90. package/dist/src/lib/resources/security/encryption.js +0 -295
  91. package/dist/src/lib/resources/security/encryption.js.map +0 -1
  92. package/dist/src/lib/resources/security/index.d.ts +0 -6
  93. package/dist/src/lib/resources/security/index.d.ts.map +0 -1
  94. package/dist/src/lib/resources/security/index.js +0 -6
  95. package/dist/src/lib/resources/security/index.js.map +0 -1
  96. package/dist/src/lib/resources/validation/validationResources.d.ts +0 -26
  97. package/dist/src/lib/resources/validation/validationResources.d.ts.map +0 -1
  98. package/dist/src/lib/resources/validation/validationResources.js +0 -33
  99. package/dist/src/lib/resources/validation/validationResources.js.map +0 -1
  100. package/dist/src/lib/rutter.d.ts +0 -1106
  101. package/dist/src/lib/rutter.d.ts.map +0 -1
  102. package/dist/src/lib/rutter.js +0 -1295
  103. package/dist/src/lib/rutter.js.map +0 -1
  104. package/dist/src/lib/security.d.ts.map +0 -1
  105. package/dist/src/lib/security.js +0 -569
  106. package/dist/src/lib/security.js.map +0 -1
  107. package/dist/src/lib/umbrella.d.ts.map +0 -1
  108. package/dist/src/lib/umbrella.js.map +0 -1
  109. package/dist/src/lib/umbrellaRutter.d.ts.map +0 -1
  110. package/dist/src/lib/umbrellaRutter.js.map +0 -1
  111. package/dist/src/lib/utils/helmHelpers.d.ts.map +0 -1
  112. package/dist/src/lib/utils/helmHelpers.js.map +0 -1
  113. package/dist/src/lib/utils/podTemplates.d.ts +0 -192
  114. package/dist/src/lib/utils/podTemplates.d.ts.map +0 -1
  115. package/dist/src/lib/utils/podTemplates.js +0 -331
  116. package/dist/src/lib/utils/podTemplates.js.map +0 -1
  117. package/dist/src/lib/utils/resourceNaming.d.ts +0 -57
  118. package/dist/src/lib/utils/resourceNaming.d.ts.map +0 -1
  119. package/dist/src/lib/utils/resourceNaming.js +0 -82
  120. package/dist/src/lib/utils/resourceNaming.js.map +0 -1
  121. /package/dist/{src/cli.d.ts → cli.d.ts} +0 -0
  122. /package/dist/{src/lib → lib}/helmChartWriter.d.ts +0 -0
  123. /package/dist/{src/lib → lib}/resources/baseResourceProvider.js +0 -0
  124. /package/dist/{src/lib → lib}/resources/cloud/aws/karpenterResources.d.ts +0 -0
  125. /package/dist/{src/lib → lib}/resources/cloud/aws/karpenterResources.js +0 -0
  126. /package/dist/{src/lib → lib}/umbrella.d.ts +0 -0
  127. /package/dist/{src/lib → lib}/umbrella.js +0 -0
  128. /package/dist/{src/lib → lib}/umbrellaRutter.js +0 -0
@@ -1,1295 +0,0 @@
1
- import { Chart, App, Testing } from 'cdk8s';
2
- import YAML from 'yaml';
3
- // Import resource providers
4
- import { CoreResources } from './resources/core/coreResources.js';
5
- import { StorageResources } from './resources/core/storageResources.js';
6
- import { AWSResources } from './resources/cloud/aws/awsResources.js';
7
- import { AzureResources } from './resources/cloud/azure/azureResources.js';
8
- import { GCPResources } from './resources/cloud/gcp/gcpResources.js';
9
- import { AutoscalingResources } from './resources/autoscaling/autoscalingResources.js';
10
- import { NetworkResources } from './resources/network/networkResources.js';
11
- import { KarpenterResources } from './resources/cloud/aws/karpenterResources.js';
12
- // Import HelmChartWriter for write functionality
13
- import { HelmChartWriter } from './helmChartWriter.js';
14
- import { include, helm } from './helm.js';
15
- import { generateHelpersTemplate } from './utils/helmHelpers.js';
16
- import { generateManifestName } from './utils/resourceNaming.js';
17
- /**
18
- * Rutter class with modular architecture
19
- * Provides a clean API while delegating to specialized resource providers
20
- * Maintains full backward compatibility with the original Rutter class
21
- *
22
- * @since 2.4.0
23
- */
24
- export class Rutter {
25
- constructor(props) {
26
- this.assets = [];
27
- this.props = props;
28
- this.meta = props.meta;
29
- this.defaultValues = props.defaultValues ?? {};
30
- this.envValues = props.envValues ?? {};
31
- // Create CDK8s infrastructure
32
- this.app = new App();
33
- this.chart = new Chart(this.app, props.meta.name, {
34
- ...props.chartProps,
35
- ...(props.namespace ? { namespace: props.namespace } : {}),
36
- });
37
- // Initialize resource providers
38
- this.coreResources = new CoreResources(this.chart);
39
- this.storageResources = new StorageResources(this.chart);
40
- this.awsResources = new AWSResources(this.chart);
41
- this.azureResources = new AzureResources(this.chart);
42
- this.gcpResources = new GCPResources(this.chart);
43
- this.autoscalingResources = new AutoscalingResources(this.chart);
44
- this.networkResources = new NetworkResources(this.chart);
45
- this.karpenterResources = new KarpenterResources(this.chart);
46
- }
47
- // Core Kubernetes Resources
48
- /**
49
- * Creates a Deployment resource
50
- * @param spec - Deployment specification
51
- * @returns Created Deployment ApiObject
52
- *
53
- * @example
54
- * ```typescript
55
- * rutter.addDeployment({
56
- * name: 'web-app',
57
- * image: 'nginx:1.21',
58
- * replicas: 3,
59
- * containerPort: 80
60
- * });
61
- * ```
62
- *
63
- * @since 1.0.0
64
- */
65
- addDeployment(spec) {
66
- return this.coreResources.addDeployment(spec);
67
- }
68
- /**
69
- * Creates a DaemonSet resource
70
- * @param spec - DaemonSet specification
71
- * @returns Created DaemonSet ApiObject
72
- *
73
- * @example
74
- * ```typescript
75
- * rutter.addDaemonSet({
76
- * name: 'log-collector',
77
- * image: 'fluentd:v1.14',
78
- * containerPort: 24224,
79
- * hostNetwork: true
80
- * });
81
- * ```
82
- *
83
- * @since 2.4.0
84
- */
85
- addDaemonSet(spec) {
86
- return this.coreResources.addDaemonSet(spec);
87
- }
88
- /**
89
- * Creates a StatefulSet resource
90
- * @param spec - StatefulSet specification
91
- * @returns Created StatefulSet ApiObject
92
- *
93
- * @example
94
- * ```typescript
95
- * rutter.addStatefulSet({
96
- * name: 'database',
97
- * image: 'postgres:13',
98
- * replicas: 3,
99
- * serviceName: 'database-headless',
100
- * containerPort: 5432
101
- * });
102
- * ```
103
- *
104
- * @since 2.4.0
105
- */
106
- addStatefulSet(spec) {
107
- return this.coreResources.addStatefulSet(spec);
108
- }
109
- /**
110
- * Creates a Role resource for RBAC
111
- * @param spec - Role specification
112
- * @returns Created Role ApiObject
113
- *
114
- * @example
115
- * ```typescript
116
- * rutter.addRole({
117
- * name: 'pod-reader',
118
- * rules: [
119
- * {
120
- * apiGroups: [''],
121
- * resources: ['pods'],
122
- * verbs: ['get', 'list', 'watch']
123
- * }
124
- * ]
125
- * });
126
- * ```
127
- *
128
- * @since 2.4.0
129
- */
130
- addRole(spec) {
131
- return this.coreResources.addRole(spec);
132
- }
133
- /**
134
- * Creates a ClusterRole resource for cluster-wide RBAC
135
- * @param spec - ClusterRole specification
136
- * @returns Created ClusterRole ApiObject
137
- *
138
- * @example
139
- * ```typescript
140
- * rutter.addClusterRole({
141
- * name: 'cluster-reader',
142
- * rules: [
143
- * {
144
- * apiGroups: [''],
145
- * resources: ['nodes', 'namespaces'],
146
- * verbs: ['get', 'list', 'watch']
147
- * }
148
- * ]
149
- * });
150
- * ```
151
- *
152
- * @since 2.4.0
153
- */
154
- addClusterRole(spec) {
155
- return this.coreResources.addClusterRole(spec);
156
- }
157
- /**
158
- * Creates a RoleBinding resource for RBAC
159
- * @param spec - RoleBinding specification
160
- * @returns Created RoleBinding ApiObject
161
- *
162
- * @example
163
- * ```typescript
164
- * rutter.addRoleBinding({
165
- * name: 'pod-reader-binding',
166
- * roleRef: {
167
- * kind: 'Role',
168
- * name: 'pod-reader',
169
- * apiGroup: 'rbac.authorization.k8s.io'
170
- * },
171
- * subjects: [
172
- * {
173
- * kind: 'ServiceAccount',
174
- * name: 'my-service-account'
175
- * }
176
- * ]
177
- * });
178
- * ```
179
- *
180
- * @since 2.4.0
181
- */
182
- addRoleBinding(spec) {
183
- return this.coreResources.addRoleBinding(spec);
184
- }
185
- /**
186
- * Creates a ClusterRoleBinding resource for cluster-wide RBAC
187
- * @param spec - ClusterRoleBinding specification
188
- * @returns Created ClusterRoleBinding ApiObject
189
- *
190
- * @example
191
- * ```typescript
192
- * rutter.addClusterRoleBinding({
193
- * name: 'cluster-reader-binding',
194
- * roleRef: {
195
- * kind: 'ClusterRole',
196
- * name: 'cluster-reader',
197
- * apiGroup: 'rbac.authorization.k8s.io'
198
- * },
199
- * subjects: [
200
- * {
201
- * kind: 'ServiceAccount',
202
- * name: 'monitoring-agent',
203
- * namespace: 'monitoring'
204
- * }
205
- * ]
206
- * });
207
- * ```
208
- *
209
- * @since 2.4.0
210
- */
211
- addClusterRoleBinding(spec) {
212
- return this.coreResources.addClusterRoleBinding(spec);
213
- }
214
- /**
215
- * Creates a Job resource for batch workloads
216
- * @param spec - Job specification
217
- * @returns Created Job ApiObject
218
- *
219
- * @example
220
- * ```typescript
221
- * rutter.addJob({
222
- * name: 'data-processor',
223
- * image: 'busybox:1.35',
224
- * command: ['sh', '-c', 'echo "Processing..." && sleep 30'],
225
- * completions: 1
226
- * });
227
- * ```
228
- *
229
- * @since 2.4.0
230
- */
231
- addJob(spec) {
232
- return this.coreResources.addJob(spec);
233
- }
234
- /**
235
- * Creates a Service resource
236
- * @param spec - Service specification
237
- * @returns Created Service ApiObject
238
- *
239
- * @example
240
- * ```typescript
241
- * rutter.addService({
242
- * name: 'web-service',
243
- * port: 80,
244
- * targetPort: 8080,
245
- * type: 'ClusterIP'
246
- * });
247
- * ```
248
- *
249
- * @since 1.0.0
250
- */
251
- addService(spec) {
252
- return this.coreResources.addService(spec);
253
- }
254
- /**
255
- * Creates a ConfigMap resource
256
- * @param spec - ConfigMap specification
257
- * @returns Created ConfigMap ApiObject
258
- *
259
- * @example
260
- * ```typescript
261
- * rutter.addConfigMap({
262
- * name: 'app-config',
263
- * data: {
264
- * 'config.yaml': 'key: value',
265
- * 'app.properties': 'debug=true'
266
- * }
267
- * });
268
- * ```
269
- *
270
- * @since 1.0.0
271
- */
272
- addConfigMap(spec) {
273
- return this.coreResources.addConfigMap(spec);
274
- }
275
- /**
276
- * Creates a Secret resource
277
- * @param spec - Secret specification
278
- * @returns Created Secret ApiObject
279
- *
280
- * @example
281
- * ```typescript
282
- * rutter.addSecret({
283
- * name: 'app-secrets',
284
- * type: 'Opaque',
285
- * data: {
286
- * username: 'YWRtaW4=',
287
- * password: 'MWYyZDFlMmU2N2Rm'
288
- * }
289
- * });
290
- * ```
291
- *
292
- * @since 1.0.0
293
- */
294
- addSecret(spec) {
295
- return this.coreResources.addSecret(spec);
296
- }
297
- /**
298
- * Creates a ServiceAccount resource
299
- * @param spec - ServiceAccount specification
300
- * @returns Created ServiceAccount ApiObject
301
- *
302
- * @example
303
- * ```typescript
304
- * rutter.addServiceAccount({
305
- * name: 'app-service-account',
306
- * automountServiceAccountToken: false
307
- * });
308
- * ```
309
- *
310
- * @since 1.0.0
311
- */
312
- addServiceAccount(spec) {
313
- return this.coreResources.addServiceAccount(spec);
314
- }
315
- // Storage Resources
316
- /**
317
- * Creates a PersistentVolume resource
318
- * @param spec - PersistentVolume specification
319
- * @returns Created PersistentVolume ApiObject
320
- *
321
- * @example
322
- * ```typescript
323
- * rutter.addPersistentVolume({
324
- * name: 'data-pv',
325
- * capacity: '10Gi',
326
- * accessModes: ['ReadWriteOnce'],
327
- * storageClassName: 'fast-ssd'
328
- * });
329
- * ```
330
- *
331
- * @since 1.0.0
332
- */
333
- addPersistentVolume(spec) {
334
- return this.storageResources.addPersistentVolume(spec);
335
- }
336
- /**
337
- * Creates a PersistentVolumeClaim resource
338
- * @param spec - PersistentVolumeClaim specification
339
- * @returns Created PersistentVolumeClaim ApiObject
340
- *
341
- * @example
342
- * ```typescript
343
- * rutter.addPersistentVolumeClaim({
344
- * name: 'data-pvc',
345
- * size: '10Gi',
346
- * accessModes: ['ReadWriteOnce'],
347
- * storageClassName: 'fast-ssd'
348
- * });
349
- * ```
350
- *
351
- * @since 1.0.0
352
- */
353
- addPersistentVolumeClaim(spec) {
354
- return this.storageResources.addPersistentVolumeClaim(spec);
355
- }
356
- /**
357
- * Creates a StorageClass resource
358
- * @param spec - StorageClass specification
359
- * @returns Created StorageClass ApiObject
360
- *
361
- * @example
362
- * ```typescript
363
- * rutter.addStorageClass({
364
- * name: 'fast-ssd',
365
- * provisioner: 'kubernetes.io/aws-ebs',
366
- * parameters: {
367
- * type: 'gp3',
368
- * encrypted: 'true'
369
- * }
370
- * });
371
- * ```
372
- *
373
- * @since 1.0.0
374
- */
375
- addStorageClass(spec) {
376
- return this.storageResources.addStorageClass(spec);
377
- }
378
- // AWS Resources
379
- /**
380
- * Creates an AWS EBS StorageClass
381
- * @param spec - EBS StorageClass specification
382
- * @returns Created StorageClass ApiObject
383
- *
384
- * @example
385
- * ```typescript
386
- * rutter.addAWSEBSStorageClass({
387
- * name: 'fast-ebs',
388
- * volumeType: 'gp3',
389
- * encrypted: true,
390
- * allowVolumeExpansion: true
391
- * });
392
- * ```
393
- *
394
- * @since 1.0.0
395
- */
396
- addAWSEBSStorageClass(spec) {
397
- return this.awsResources.addEBSStorageClass(spec);
398
- }
399
- /**
400
- * Creates an AWS EFS StorageClass
401
- * @param spec - EFS StorageClass specification
402
- * @returns Created StorageClass ApiObject
403
- *
404
- * @example
405
- * ```typescript
406
- * rutter.addAWSEFSStorageClass({
407
- * name: 'efs-storage',
408
- * fileSystemId: 'fs-12345678',
409
- * directoryPerms: '0755'
410
- * });
411
- * ```
412
- *
413
- * @since 1.0.0
414
- */
415
- addAWSEFSStorageClass(spec) {
416
- return this.awsResources.addEFSStorageClass(spec);
417
- }
418
- /**
419
- * Creates an AWS IRSA ServiceAccount
420
- * @param spec - IRSA ServiceAccount specification
421
- * @returns Created ServiceAccount ApiObject
422
- *
423
- * @example
424
- * ```typescript
425
- * rutter.addAWSIRSAServiceAccount({
426
- * name: 'aws-service-account',
427
- * roleArn: 'arn:aws:iam::123456789012:role/MyRole'
428
- * });
429
- * ```
430
- *
431
- * @since 1.0.0
432
- */
433
- addAWSIRSAServiceAccount(spec) {
434
- return this.awsResources.addIRSAServiceAccount(spec);
435
- }
436
- /**
437
- * Creates an AWS ALB Ingress
438
- * @param spec - ALB Ingress specification
439
- * @returns Created Ingress ApiObject
440
- *
441
- * @example
442
- * ```typescript
443
- * rutter.addAWSALBIngress({
444
- * name: 'web-ingress',
445
- * rules: [{
446
- * paths: [{
447
- * path: '/',
448
- * pathType: 'Prefix',
449
- * backend: { service: { name: 'web-service', port: { number: 80 } } }
450
- * }]
451
- * }],
452
- * scheme: 'internet-facing'
453
- * });
454
- * ```
455
- *
456
- * @since 1.0.0
457
- */
458
- addAWSALBIngress(spec) {
459
- return this.awsResources.addALBIngress(spec);
460
- }
461
- // Azure Cloud Resources
462
- /**
463
- * Creates an Azure Disk StorageClass
464
- * @param spec - Azure Disk StorageClass specification
465
- * @returns Created StorageClass ApiObject
466
- *
467
- * @since 2.4.0
468
- */
469
- addAzureDiskStorageClass(spec) {
470
- return this.azureResources.addAzureDiskStorageClass(spec);
471
- }
472
- /**
473
- * Creates an Azure File StorageClass
474
- * @param spec - Azure File StorageClass specification
475
- * @returns Created StorageClass ApiObject
476
- *
477
- * @since 2.4.0
478
- */
479
- addAzureFileStorageClass(spec) {
480
- return this.azureResources.addAzureFileStorageClass(spec);
481
- }
482
- /**
483
- * Creates an Azure Application Gateway Ingress
484
- * @param spec - AGIC Ingress specification
485
- * @returns Created Ingress ApiObject
486
- *
487
- * @since 2.4.0
488
- */
489
- addAzureApplicationGatewayIngress(spec) {
490
- return this.azureResources.addApplicationGatewayIngress(spec);
491
- }
492
- /**
493
- * Creates an Azure Key Vault SecretProviderClass
494
- * @param spec - Azure Key Vault SecretProviderClass specification
495
- * @returns Created SecretProviderClass ApiObject
496
- *
497
- * @since 2.4.0
498
- */
499
- addAzureKeyVaultSecretProviderClass(spec) {
500
- return this.azureResources.addAzureKeyVaultSecretProviderClass(spec);
501
- }
502
- /**
503
- * Creates an Azure Container Registry ServiceAccount
504
- * @param spec - Azure ACR ServiceAccount specification
505
- * @returns Created ServiceAccount ApiObject
506
- *
507
- * @since 2.4.0
508
- */
509
- addAzureACRServiceAccount(spec) {
510
- return this.azureResources.addAzureACRServiceAccount(spec);
511
- }
512
- // GCP Cloud Resources
513
- /**
514
- * Creates a GCP Persistent Disk StorageClass
515
- * @param spec - GCP PD StorageClass specification
516
- * @returns Created StorageClass ApiObject
517
- *
518
- * @since 2.4.0
519
- */
520
- addGCPPersistentDiskStorageClass(spec) {
521
- return this.gcpResources.addPersistentDiskStorageClass(spec);
522
- }
523
- /**
524
- * Creates a GCP Filestore StorageClass
525
- * @param spec - GCP Filestore StorageClass specification
526
- * @returns Created StorageClass ApiObject
527
- *
528
- * @since 2.4.0
529
- */
530
- addGCPFilestoreStorageClass(spec) {
531
- return this.gcpResources.addFilestoreStorageClass(spec);
532
- }
533
- /**
534
- * Creates a GCE Ingress with Google Cloud Load Balancer
535
- * @param spec - GCE Ingress specification
536
- * @returns Created Ingress ApiObject
537
- *
538
- * @since 2.4.0
539
- */
540
- addGCPGCEIngress(spec) {
541
- return this.gcpResources.addGCEIngress(spec);
542
- }
543
- /**
544
- * Creates a ServiceAccount with Workload Identity annotations
545
- * @param spec - Workload Identity ServiceAccount specification
546
- * @returns Created ServiceAccount ApiObject
547
- *
548
- * @since 2.4.0
549
- */
550
- addGCPWorkloadIdentityServiceAccount(spec) {
551
- return this.gcpResources.addWorkloadIdentityServiceAccount(spec);
552
- }
553
- /**
554
- * Creates a ServiceAccount with GCP Artifact Registry access
555
- * @param spec - Artifact Registry ServiceAccount specification
556
- * @returns Created ServiceAccount ApiObject
557
- *
558
- * @example
559
- * ```typescript
560
- * rutter.addGCPArtifactRegistryServiceAccount({
561
- * name: 'artifact-registry-sa',
562
- * googleServiceAccount: 'my-gsa@project.iam.gserviceaccount.com'
563
- * });
564
- * ```
565
- *
566
- * @since 2.7.0
567
- */
568
- addGCPArtifactRegistryServiceAccount(spec) {
569
- return this.gcpResources.addArtifactRegistryServiceAccount(spec);
570
- }
571
- // AWS Karpenter Resources
572
- /**
573
- * Creates a Karpenter NodePool resource
574
- * @param spec - NodePool specification
575
- * @returns Created NodePool ApiObject
576
- *
577
- * @example
578
- * ```typescript
579
- * rutter.addKarpenterNodePool({
580
- * name: 'default-nodepool',
581
- * template: {
582
- * spec: {
583
- * nodeClassRef: {
584
- * apiVersion: 'karpenter.k8s.aws/v1beta1',
585
- * kind: 'EC2NodeClass',
586
- * name: 'default'
587
- * }
588
- * }
589
- * }
590
- * });
591
- * ```
592
- *
593
- * @since 2.7.0
594
- */
595
- addKarpenterNodePool(spec) {
596
- return this.karpenterResources.addKarpenterNodePool(spec);
597
- }
598
- /**
599
- * Creates a Karpenter NodeClaim resource
600
- * @param spec - NodeClaim specification
601
- * @returns Created NodeClaim ApiObject
602
- *
603
- * @example
604
- * ```typescript
605
- * rutter.addKarpenterNodeClaim({
606
- * name: 'my-node-claim',
607
- * nodeClassRef: {
608
- * apiVersion: 'karpenter.k8s.aws/v1beta1',
609
- * kind: 'EC2NodeClass',
610
- * name: 'default'
611
- * }
612
- * });
613
- * ```
614
- *
615
- * @since 2.7.0
616
- */
617
- addKarpenterNodeClaim(spec) {
618
- return this.karpenterResources.addKarpenterNodeClaim(spec);
619
- }
620
- /**
621
- * Creates a Karpenter EC2NodeClass resource
622
- * @param spec - EC2NodeClass specification
623
- * @returns Created EC2NodeClass ApiObject
624
- *
625
- * @example
626
- * ```typescript
627
- * rutter.addKarpenterEC2NodeClass({
628
- * name: 'default',
629
- * amiFamily: 'AL2',
630
- * subnetSelectorTerms: [{ tags: { 'karpenter.sh/discovery': 'my-cluster' } }],
631
- * securityGroupSelectorTerms: [{ tags: { 'karpenter.sh/discovery': 'my-cluster' } }]
632
- * });
633
- * ```
634
- *
635
- * @since 2.7.0
636
- */
637
- addKarpenterEC2NodeClass(spec) {
638
- return this.karpenterResources.addKarpenterEC2NodeClass(spec);
639
- }
640
- /**
641
- * Creates a Karpenter NodePool with optimized disruption settings for cost efficiency
642
- * @param spec - NodePool specification with disruption optimization
643
- * @returns Created NodePool ApiObject
644
- *
645
- * @example
646
- * ```typescript
647
- * rutter.addKarpenterNodePoolWithDisruption({
648
- * name: 'cost-optimized',
649
- * nodeClassRef: {
650
- * apiVersion: 'karpenter.k8s.aws/v1beta1',
651
- * kind: 'EC2NodeClass',
652
- * name: 'default'
653
- * },
654
- * consolidationPolicy: 'WhenEmptyOrUnderutilized',
655
- * consolidateAfter: '30s',
656
- * expireAfter: '24h',
657
- * disruptionBudgets: [
658
- * { nodes: '20%' },
659
- * { nodes: '0', schedule: '0 9 * * 1-5', duration: '8h' }
660
- * ]
661
- * });
662
- * ```
663
- *
664
- * @since 2.7.1
665
- */
666
- addKarpenterNodePoolWithDisruption(spec) {
667
- return this.karpenterResources.addKarpenterNodePoolWithDisruption(spec);
668
- }
669
- /**
670
- * Creates a Karpenter NodePool with scheduling constraints and priorities
671
- * @param spec - NodePool specification with scheduling optimization
672
- * @returns Created NodePool ApiObject
673
- *
674
- * @example
675
- * ```typescript
676
- * rutter.addKarpenterNodePoolWithScheduling({
677
- * name: 'gpu-workloads',
678
- * nodeClassRef: {
679
- * apiVersion: 'karpenter.k8s.aws/v1beta1',
680
- * kind: 'EC2NodeClass',
681
- * name: 'gpu-nodeclass'
682
- * },
683
- * requirements: [
684
- * { key: 'node.kubernetes.io/instance-type', operator: 'In', values: ['g4dn.xlarge', 'g4dn.2xlarge'] }
685
- * ],
686
- * taints: [
687
- * { key: 'nvidia.com/gpu', effect: 'NoSchedule' }
688
- * ],
689
- * terminationGracePeriod: '60s',
690
- * weight: 100
691
- * });
692
- * ```
693
- *
694
- * @since 2.7.1
695
- */
696
- addKarpenterNodePoolWithScheduling(spec) {
697
- return this.karpenterResources.addKarpenterNodePoolWithScheduling(spec);
698
- }
699
- // Network Resources
700
- /**
701
- * Creates a NetworkPolicy resource
702
- * @param spec - NetworkPolicy specification
703
- * @returns Created NetworkPolicy ApiObject
704
- *
705
- * @example
706
- * ```typescript
707
- * rutter.addNetworkPolicy({
708
- * name: 'deny-all',
709
- * podSelector: {},
710
- * policyTypes: ['Ingress', 'Egress']
711
- * });
712
- * ```
713
- *
714
- * @since 2.7.0
715
- */
716
- addNetworkPolicy(spec) {
717
- return this.networkResources.addNetworkPolicy(spec);
718
- }
719
- /**
720
- * Creates a NetworkPolicy from a predefined template
721
- * @param templateName - Name of the predefined template
722
- * @param name - Policy name
723
- * @param podSelector - Pod selector to apply policy to
724
- * @param labels - Optional labels
725
- * @param annotations - Optional annotations
726
- * @returns Created NetworkPolicy ApiObject
727
- * @example
728
- * ```typescript
729
- * // Create a deny-all policy
730
- * rutter.addNetworkPolicyFromTemplate(
731
- * 'deny-all',
732
- * 'default-deny',
733
- * { matchLabels: { app: 'web' } }
734
- * );
735
- * ```
736
- * @since 2.9.0
737
- */
738
- addNetworkPolicyFromTemplate(templateName, name, podSelector, labels, annotations) {
739
- return this.networkResources.addNetworkPolicyFromTemplate(templateName, name, podSelector, labels, annotations);
740
- }
741
- /**
742
- * Gets predefined NetworkPolicy templates for common security patterns
743
- * @returns Array of predefined NetworkPolicy templates
744
- * @since 2.9.0
745
- */
746
- static getNetworkPolicyTemplates() {
747
- return NetworkResources.getNetworkPolicyTemplates();
748
- }
749
- /**
750
- * Creates a deny-all NetworkPolicy that blocks all traffic
751
- * @param name - Policy name
752
- * @param podSelector - Pod selector to apply policy to
753
- * @param labels - Optional labels
754
- * @param annotations - Optional annotations
755
- * @returns Created NetworkPolicy ApiObject
756
- *
757
- * @example
758
- * ```typescript
759
- * rutter.addDenyAllNetworkPolicy('deny-all', { matchLabels: { app: 'web' } });
760
- * ```
761
- *
762
- * @since 2.7.0
763
- */
764
- addDenyAllNetworkPolicy(name, podSelector = {}, labels, annotations) {
765
- return this.networkResources.addDenyAllNetworkPolicy(name, podSelector, labels, annotations);
766
- }
767
- /**
768
- * Creates a NetworkPolicy that allows traffic from specific pods
769
- * @param name - Policy name
770
- * @param podSelector - Pod selector to apply policy to
771
- * @param fromPodSelector - Pod selector for allowed source pods
772
- * @param ports - Optional ports to allow
773
- * @param labels - Optional labels
774
- * @param annotations - Optional annotations
775
- * @returns Created NetworkPolicy ApiObject
776
- *
777
- * @example
778
- * ```typescript
779
- * rutter.addAllowFromPodsNetworkPolicy(
780
- * 'allow-from-frontend',
781
- * { matchLabels: { app: 'backend' } },
782
- * { matchLabels: { app: 'frontend' } },
783
- * [{ port: 8080, protocol: 'TCP' }]
784
- * );
785
- * ```
786
- *
787
- * @since 2.7.0
788
- */
789
- addAllowFromPodsNetworkPolicy(name, podSelector, fromPodSelector, ports, labels, annotations) {
790
- return this.networkResources.addAllowFromPodsNetworkPolicy(name, podSelector, fromPodSelector, ports, labels, annotations);
791
- }
792
- /**
793
- * Creates a NetworkPolicy that allows traffic from specific namespaces
794
- * @param name - Policy name
795
- * @param podSelector - Pod selector to apply policy to
796
- * @param fromNamespaceSelector - Namespace selector for allowed source namespaces
797
- * @param ports - Optional ports to allow
798
- * @param labels - Optional labels
799
- * @param annotations - Optional annotations
800
- * @returns Created NetworkPolicy ApiObject
801
- *
802
- * @example
803
- * ```typescript
804
- * rutter.addAllowFromNamespaceNetworkPolicy(
805
- * 'allow-from-monitoring',
806
- * { matchLabels: { app: 'web' } },
807
- * { matchLabels: { name: 'monitoring' } },
808
- * [{ port: 9090, protocol: 'TCP' }]
809
- * );
810
- * ```
811
- *
812
- * @since 2.7.0
813
- */
814
- addAllowFromNamespaceNetworkPolicy(name, podSelector, fromNamespaceSelector, ports, labels, annotations) {
815
- return this.networkResources.addAllowFromNamespaceNetworkPolicy(name, podSelector, fromNamespaceSelector, ports, labels, annotations);
816
- }
817
- addIngress(specOrName, host, serviceName, servicePort, options) {
818
- if (typeof specOrName === 'string') {
819
- return this.createSimpleIngress(specOrName, host, serviceName, servicePort, options);
820
- }
821
- // Original spec-based overload
822
- return this.networkResources.addIngress(specOrName);
823
- }
824
- /**
825
- * Creates a simple Ingress with enhanced options
826
- * @private
827
- */
828
- createSimpleIngress(name, host, serviceName, servicePort, options) {
829
- const tlsSecretName = typeof options?.tls === 'string' ? options.tls : `${name}-tls`;
830
- const annotations = this.buildIngressAnnotations(options);
831
- const spec = {
832
- name,
833
- rules: [
834
- {
835
- host,
836
- http: {
837
- paths: [
838
- {
839
- path: options?.path || '/',
840
- pathType: options?.pathType || 'Prefix',
841
- backend: {
842
- service: {
843
- name: serviceName,
844
- port: { number: servicePort },
845
- },
846
- },
847
- },
848
- ],
849
- },
850
- },
851
- ],
852
- ...(options?.className && { ingressClassName: options.className }),
853
- ...(Object.keys(annotations).length > 0 && { annotations }),
854
- ...(options?.tls && {
855
- tls: [
856
- {
857
- hosts: [host],
858
- secretName: tlsSecretName,
859
- },
860
- ],
861
- }),
862
- };
863
- return this.networkResources.addIngress(spec);
864
- }
865
- /**
866
- * Builds annotations for Ingress based on options
867
- * @private
868
- */
869
- buildIngressAnnotations(options) {
870
- const annotations = { ...options?.annotations };
871
- this.addSSLRedirectAnnotation(annotations, options);
872
- this.addCertManagerAnnotation(annotations, options);
873
- this.addNginxAnnotations(annotations, options);
874
- return annotations;
875
- }
876
- /**
877
- * Adds SSL redirect annotation based on class and options
878
- * @private
879
- */
880
- addSSLRedirectAnnotation(annotations, options) {
881
- if (!options?.tls || options.sslRedirect === false)
882
- return;
883
- if (options.className === 'nginx' || !options.className) {
884
- annotations['nginx.ingress.kubernetes.io/ssl-redirect'] = 'true';
885
- }
886
- else if (options.className === 'alb') {
887
- annotations['alb.ingress.kubernetes.io/ssl-redirect'] = '443';
888
- }
889
- }
890
- /**
891
- * Adds cert-manager annotation if specified
892
- * @private
893
- */
894
- addCertManagerAnnotation(annotations, options) {
895
- if (options?.certManager) {
896
- annotations['cert-manager.io/cluster-issuer'] = options.certManager;
897
- }
898
- }
899
- /**
900
- * Adds NGINX-specific annotations
901
- * @private
902
- */
903
- addNginxAnnotations(annotations, options) {
904
- if (options?.className !== 'nginx' && options?.className)
905
- return;
906
- if (options?.cors) {
907
- annotations['nginx.ingress.kubernetes.io/enable-cors'] = 'true';
908
- }
909
- if (options?.bodySize) {
910
- annotations['nginx.ingress.kubernetes.io/proxy-body-size'] = options.bodySize;
911
- }
912
- if (options?.timeout) {
913
- annotations['nginx.ingress.kubernetes.io/proxy-read-timeout'] = options.timeout.toString();
914
- }
915
- if (options?.backendProtocol && options.backendProtocol !== 'HTTP') {
916
- annotations['nginx.ingress.kubernetes.io/backend-protocol'] = options.backendProtocol;
917
- }
918
- if (options?.rewriteTarget) {
919
- annotations['nginx.ingress.kubernetes.io/rewrite-target'] = options.rewriteTarget;
920
- }
921
- }
922
- /**
923
- * Creates a secure Ingress resource with TLS validation and environment-aware security defaults
924
- * @param spec - Enhanced Ingress specification with security options
925
- * @returns Created Ingress ApiObject
926
- *
927
- * @example
928
- * ```typescript
929
- * // Production Ingress with mandatory TLS
930
- * rutter.addSecureIngress({
931
- * name: 'secure-web-ingress',
932
- * environment: 'production',
933
- * tls: [{
934
- * hosts: ['secure.example.com'],
935
- * secretName: 'secure-example-tls'
936
- * }],
937
- * forceSSLRedirect: true,
938
- * rules: [{
939
- * host: 'secure.example.com',
940
- * http: {
941
- * paths: [{
942
- * path: '/',
943
- * pathType: 'Prefix',
944
- * backend: {
945
- * service: { name: 'web-service', port: { number: 80 } }
946
- * }
947
- * }]
948
- * }
949
- * }]
950
- * });
951
- * ```
952
- *
953
- * @since 2.8.0
954
- */
955
- addSecureIngress(spec) {
956
- return this.networkResources.addSecureIngress(spec);
957
- }
958
- // AWS ECR ServiceAccount
959
- /**
960
- * Creates a ServiceAccount with ECR access annotations
961
- * @param spec - ECR ServiceAccount specification
962
- * @returns Created ServiceAccount ApiObject
963
- *
964
- * @example
965
- * ```typescript
966
- * rutter.addAWSECRServiceAccount({
967
- * name: 'ecr-service-account',
968
- * roleArn: 'arn:aws:iam::123456789012:role/ECRAccessRole'
969
- * });
970
- * ```
971
- *
972
- * @since 2.7.0
973
- */
974
- addAWSECRServiceAccount(spec) {
975
- return this.awsResources.addECRServiceAccount(spec);
976
- }
977
- // Autoscaling Resources
978
- /**
979
- * Creates a Horizontal Pod Autoscaler (HPA) resource
980
- * @param spec - HPA specification
981
- * @returns Created HPA ApiObject
982
- *
983
- * @example
984
- * ```typescript
985
- * rutter.addHorizontalPodAutoscaler({
986
- * name: 'web-hpa',
987
- * scaleTargetRef: {
988
- * apiVersion: 'apps/v1',
989
- * kind: 'Deployment',
990
- * name: 'web-app'
991
- * },
992
- * minReplicas: 2,
993
- * maxReplicas: 10,
994
- * metrics: [{
995
- * type: 'Resource',
996
- * resource: {
997
- * name: 'cpu',
998
- * target: { type: 'Utilization', averageUtilization: 70 }
999
- * }
1000
- * }]
1001
- * });
1002
- * ```
1003
- *
1004
- * @since 2.7.0
1005
- */
1006
- addHorizontalPodAutoscaler(spec) {
1007
- return this.autoscalingResources.addHorizontalPodAutoscaler(spec);
1008
- }
1009
- /**
1010
- * Creates a Vertical Pod Autoscaler (VPA) resource
1011
- * @param spec - VPA specification
1012
- * @returns Created VPA ApiObject
1013
- *
1014
- * @example
1015
- * ```typescript
1016
- * rutter.addVerticalPodAutoscaler({
1017
- * name: 'web-vpa',
1018
- * targetRef: {
1019
- * apiVersion: 'apps/v1',
1020
- * kind: 'Deployment',
1021
- * name: 'web-app'
1022
- * },
1023
- * updatePolicy: { updateMode: 'Auto' }
1024
- * });
1025
- * ```
1026
- *
1027
- * @since 2.7.0
1028
- */
1029
- addVerticalPodAutoscaler(spec) {
1030
- return this.autoscalingResources.addVerticalPodAutoscaler(spec);
1031
- }
1032
- /**
1033
- * Creates a CronJob resource
1034
- * @param spec - CronJob specification
1035
- * @returns Created CronJob ApiObject
1036
- *
1037
- * @example
1038
- * ```typescript
1039
- * rutter.addCronJob({
1040
- * name: 'backup-job',
1041
- * schedule: '0 2 * * *',
1042
- * jobTemplate: {
1043
- * spec: {
1044
- * template: {
1045
- * spec: {
1046
- * containers: [{
1047
- * name: 'backup',
1048
- * image: 'backup:latest',
1049
- * command: ['backup.sh']
1050
- * }],
1051
- * restartPolicy: 'OnFailure'
1052
- * }
1053
- * }
1054
- * }
1055
- * }
1056
- * });
1057
- * ```
1058
- *
1059
- * @since 2.7.0
1060
- */
1061
- addCronJob(spec) {
1062
- return this.autoscalingResources.addCronJob(spec);
1063
- }
1064
- // Utility methods
1065
- /**
1066
- * Adds a custom resource definition (CRD) YAML or object
1067
- * @param yamlOrObject - CRD YAML content string or object
1068
- * @param id - Unique identifier for the CRD
1069
- *
1070
- * @example
1071
- * ```typescript
1072
- * // Using YAML string
1073
- * rutter.addCrd(`
1074
- * apiVersion: apiextensions.k8s.io/v1
1075
- * kind: CustomResourceDefinition
1076
- * metadata:
1077
- * name: example.com
1078
- * spec:
1079
- * group: example.com
1080
- * versions: []
1081
- * `);
1082
- *
1083
- * // Using object
1084
- * rutter.addCrd({
1085
- * apiVersion: 'apiextensions.k8s.io/v1',
1086
- * kind: 'CustomResourceDefinition',
1087
- * metadata: { name: 'example.com' },
1088
- * spec: { group: 'example.com', versions: [] }
1089
- * });
1090
- * ```
1091
- *
1092
- * @since 1.0.0
1093
- */
1094
- addCrd(yamlOrObject, id = 'crd') {
1095
- let yaml;
1096
- let crdObject;
1097
- if (typeof yamlOrObject === 'string') {
1098
- // Validate YAML string
1099
- try {
1100
- crdObject = YAML.parse(yamlOrObject);
1101
- yaml = yamlOrObject.trim();
1102
- }
1103
- catch (error) {
1104
- throw new Error(`Invalid YAML provided to addCrd(): ${error instanceof Error ? error.message : 'Unknown error'}`);
1105
- }
1106
- }
1107
- else if (typeof yamlOrObject === 'object' && yamlOrObject !== null) {
1108
- // Use object directly and convert to YAML
1109
- crdObject = yamlOrObject;
1110
- try {
1111
- yaml = YAML.stringify(yamlOrObject).trim();
1112
- }
1113
- catch (error) {
1114
- throw new Error(`Failed to convert object to YAML in addCrd(): ${error instanceof Error ? error.message : 'Unknown error'}`);
1115
- }
1116
- }
1117
- else {
1118
- throw new Error('addCrd() requires either a YAML string or an object');
1119
- }
1120
- // Ensure we have valid content
1121
- if (!yaml) {
1122
- throw new Error('addCrd() received empty or invalid content');
1123
- }
1124
- // Validate CRD structure
1125
- this.validateCrdStructure(crdObject);
1126
- this.assets.push({ id, yaml, target: 'crds' });
1127
- }
1128
- /**
1129
- * Validates CRD structure according to Kubernetes specification
1130
- * @param crd - CRD object to validate
1131
- * @private
1132
- * @since 2.5.0
1133
- */
1134
- validateCrdStructure(crd) {
1135
- if (crd['apiVersion'] !== 'apiextensions.k8s.io/v1') {
1136
- throw new Error('CRD must use apiVersion: apiextensions.k8s.io/v1');
1137
- }
1138
- if (crd['kind'] !== 'CustomResourceDefinition') {
1139
- throw new Error('CRD must have kind: CustomResourceDefinition');
1140
- }
1141
- if (!crd['metadata'] || typeof crd['metadata'] !== 'object' || crd['metadata'] === null) {
1142
- throw new Error('CRD must have a metadata object');
1143
- }
1144
- const metadata = crd['metadata'];
1145
- if (!metadata['name'] || typeof metadata['name'] !== 'string') {
1146
- throw new Error('CRD must have a valid metadata.name');
1147
- }
1148
- if (!crd['spec'] || typeof crd['spec'] !== 'object' || crd['spec'] === null) {
1149
- throw new Error('CRD must have a spec object');
1150
- }
1151
- const spec = crd['spec'];
1152
- if (!spec['group'] || typeof spec['group'] !== 'string') {
1153
- throw new Error('CRD must have a valid spec.group');
1154
- }
1155
- if (!Array.isArray(spec['versions']) || spec['versions'].length === 0) {
1156
- throw new Error('CRD must have at least one version in spec.versions');
1157
- }
1158
- }
1159
- /**
1160
- * Gets chart metadata
1161
- * @returns Chart metadata
1162
- *
1163
- * @since 1.0.0
1164
- */
1165
- getMeta() {
1166
- return { ...this.meta };
1167
- }
1168
- /**
1169
- * Gets default values
1170
- * @returns Default values object
1171
- *
1172
- * @since 1.0.0
1173
- */
1174
- getDefaultValues() {
1175
- return { ...this.defaultValues };
1176
- }
1177
- /**
1178
- * Gets environment-specific values
1179
- * @returns Environment values object
1180
- *
1181
- * @since 1.0.0
1182
- */
1183
- getEnvValues() {
1184
- return { ...this.envValues };
1185
- }
1186
- /**
1187
- * Gets all assets (CRDs, etc.)
1188
- * @returns Array of assets
1189
- *
1190
- * @since 1.0.0
1191
- */
1192
- getAssets() {
1193
- return [...this.assets];
1194
- }
1195
- /**
1196
- * Converts the chart to SynthAsset array for HelmChartWriter
1197
- * @returns Array of synthesized assets
1198
- *
1199
- * @since 2.4.0
1200
- */
1201
- toSynthArray() {
1202
- // Use cdk8s Testing.synth to obtain manifest objects
1203
- const manifestObjs = Testing.synth(this.chart);
1204
- // Enforce common labels best-practice on all rendered objects
1205
- const enriched = manifestObjs.map((obj) => {
1206
- if (obj && typeof obj === 'object') {
1207
- const o = obj;
1208
- o.metadata = o.metadata ?? {};
1209
- o.metadata.labels = o.metadata.labels ?? {};
1210
- const labels = o.metadata.labels;
1211
- const defaults = {
1212
- 'helm.sh/chart': '{{ .Chart.Name }}-{{ .Chart.Version }}',
1213
- 'app.kubernetes.io/name': include(Rutter.HELPER_NAME),
1214
- 'app.kubernetes.io/instance': helm.releaseName,
1215
- 'app.kubernetes.io/version': helm.chartVersion,
1216
- 'app.kubernetes.io/managed-by': '{{ .Release.Service }}',
1217
- 'app.kubernetes.io/part-of': helm.chartName,
1218
- };
1219
- // Apply defaults only if not already set
1220
- for (const [key, value] of Object.entries(defaults)) {
1221
- if (!(key in labels)) {
1222
- // eslint-disable-next-line security/detect-object-injection -- Safe: controlled label assignment
1223
- labels[key] = value;
1224
- }
1225
- }
1226
- }
1227
- return obj;
1228
- });
1229
- const synthAssets = [];
1230
- if (this.props.singleManifestFile) {
1231
- // Combine all resources into single manifest
1232
- const combinedYaml = enriched
1233
- .map((obj) => YAML.stringify(obj).trim())
1234
- .filter(Boolean)
1235
- .join('\n---\n');
1236
- const manifestId = this.props.manifestPrefix ?? 'manifests';
1237
- synthAssets.push({ id: manifestId, yaml: combinedYaml });
1238
- }
1239
- else {
1240
- // Create separate files for each resource (default behavior)
1241
- enriched.forEach((obj, index) => {
1242
- const yaml = YAML.stringify(obj).trim();
1243
- if (yaml) {
1244
- const manifestId = generateManifestName(obj, this.props.namingStrategy ?? 'descriptive', index + 1, this.props.manifestPrefix);
1245
- synthAssets.push({ id: manifestId, yaml });
1246
- }
1247
- });
1248
- }
1249
- // Add any additional assets (CRDs, etc.)
1250
- this.assets.forEach((asset) => {
1251
- synthAssets.push({ id: asset.id, yaml: asset.yaml });
1252
- });
1253
- return synthAssets;
1254
- }
1255
- /**
1256
- * Writes the Helm chart to the specified output directory
1257
- * @param outDir - Output directory path
1258
- *
1259
- * @since 1.0.0
1260
- */
1261
- write(outDir) {
1262
- // Generate helpers template
1263
- let helpersContent;
1264
- if (this.props.helpersTpl) {
1265
- if (typeof this.props.helpersTpl === 'string') {
1266
- helpersContent = this.props.helpersTpl;
1267
- }
1268
- else {
1269
- helpersContent = this.props.helpersTpl
1270
- .map((helper) => `{{/*
1271
- ${helper.name}
1272
- */}}
1273
- {{- define "${helper.name}" -}}
1274
- ${helper.template}
1275
- {{- end }}`)
1276
- .join('\n\n');
1277
- }
1278
- }
1279
- else {
1280
- // Auto-generate standard helpers
1281
- helpersContent = generateHelpersTemplate(this.props.cloudProvider);
1282
- }
1283
- HelmChartWriter.write({
1284
- outDir,
1285
- meta: this.meta,
1286
- defaultValues: this.defaultValues,
1287
- envValues: this.envValues,
1288
- assets: this.toSynthArray(),
1289
- helpersTpl: helpersContent,
1290
- });
1291
- }
1292
- }
1293
- // Constants for labels
1294
- Rutter.HELPER_NAME = 'chart.name';
1295
- //# sourceMappingURL=rutter.js.map