timonel 2.8.3 → 2.9.1

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.
@@ -3,7 +3,23 @@ export interface HelperDefinition {
3
3
  template: string;
4
4
  }
5
5
  export declare const STANDARD_HELPERS: HelperDefinition[];
6
+ export declare const FILE_ACCESS_HELPERS: HelperDefinition[];
7
+ export declare const TEMPLATE_FUNCTION_HELPERS: HelperDefinition[];
8
+ export declare const SPRIG_HELPERS: HelperDefinition[];
9
+ export declare const KUBERNETES_HELPERS: HelperDefinition[];
6
10
  export declare const AWS_HELPERS: HelperDefinition[];
7
11
  export declare function formatHelpers(helpers: HelperDefinition[]): string;
8
- export declare function getDefaultHelpers(cloudProvider?: 'aws'): HelperDefinition[];
9
- export declare function generateHelpersTemplate(cloudProvider?: 'aws', customHelpers?: HelperDefinition[]): string;
12
+ export declare function getDefaultHelpers(cloudProvider?: 'aws', options?: {
13
+ includeFileAccess?: boolean;
14
+ includeTemplateFunction?: boolean;
15
+ includeSprig?: boolean;
16
+ includeKubernetes?: boolean;
17
+ }): HelperDefinition[];
18
+ export declare function generateHelpersTemplate(cloudProvider?: 'aws', customHelpers?: HelperDefinition[], options?: {
19
+ includeFileAccess?: boolean;
20
+ includeTemplateFunction?: boolean;
21
+ includeSprig?: boolean;
22
+ includeKubernetes?: boolean;
23
+ }): string;
24
+ export declare function getHelpersByCategory(category: 'standard' | 'fileAccess' | 'templateFunction' | 'sprig' | 'kubernetes' | 'aws'): HelperDefinition[];
25
+ export declare function createHelper(name: string, template: string): HelperDefinition;
@@ -35,6 +35,203 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}`,
35
35
  app.kubernetes.io/instance: {{ .Release.Name }}`,
36
36
  },
37
37
  ];
38
+ export const FILE_ACCESS_HELPERS = [
39
+ {
40
+ name: 'files.configFromFile',
41
+ template: `{{- $path := . -}}
42
+ {{- if $.Files.Get $path -}}
43
+ {{- $.Files.Get $path | nindent 2 -}}
44
+ {{- else -}}
45
+ {{- fail (printf "File %s not found in chart" $path) -}}
46
+ {{- end -}}`,
47
+ },
48
+ {
49
+ name: 'files.configMapFromFiles',
50
+ template: `{{- $root := . -}}
51
+ {{- $pattern := .pattern -}}
52
+ {{- $files := .files | default ($root.Files.Glob $pattern) -}}
53
+ {{- range $path, $content := $files }}
54
+ {{ base $path }}: |
55
+ {{ $content | indent 4 }}
56
+ {{- end }}`,
57
+ },
58
+ {
59
+ name: 'files.secretFromFiles',
60
+ template: `{{- $root := . -}}
61
+ {{- $pattern := .pattern -}}
62
+ {{- $files := .files | default ($root.Files.Glob $pattern) -}}
63
+ {{- range $path, $content := $files }}
64
+ {{ base $path }}: {{ $content | b64enc }}
65
+ {{- end }}`,
66
+ },
67
+ {
68
+ name: 'files.exists',
69
+ template: `{{- $path := . -}}
70
+ {{- if $.Files.Get $path -}}
71
+ true
72
+ {{- else -}}
73
+ false
74
+ {{- end -}}`,
75
+ },
76
+ ];
77
+ export const TEMPLATE_FUNCTION_HELPERS = [
78
+ {
79
+ name: 'template.render',
80
+ template: `{{- $template := .template -}}
81
+ {{- $context := .context | default . -}}
82
+ {{- tpl $template $context -}}`,
83
+ },
84
+ {
85
+ name: 'template.renderWithValues',
86
+ template: `{{- $template := .template -}}
87
+ {{- $values := .values | default dict -}}
88
+ {{- $context := merge $values . -}}
89
+ {{- tpl $template $context -}}`,
90
+ },
91
+ {
92
+ name: 'validation.required',
93
+ template: `{{- $value := .value -}}
94
+ {{- $message := .message | default (printf "Value %s is required" .key) -}}
95
+ {{- required $message $value -}}`,
96
+ },
97
+ {
98
+ name: 'validation.requireAny',
99
+ template: `{{- $values := .values -}}
100
+ {{- $message := .message | default "At least one value is required" -}}
101
+ {{- $found := false -}}
102
+ {{- range $values -}}
103
+ {{- if . -}}
104
+ {{- $found = true -}}
105
+ {{- end -}}
106
+ {{- end -}}
107
+ {{- if not $found -}}
108
+ {{- fail $message -}}
109
+ {{- end -}}`,
110
+ },
111
+ ];
112
+ export const SPRIG_HELPERS = [
113
+ {
114
+ name: 'string.camelCase',
115
+ template: `{{- . | camelcase }}`,
116
+ },
117
+ {
118
+ name: 'string.kebabCase',
119
+ template: `{{- . | kebabcase }}`,
120
+ },
121
+ {
122
+ name: 'string.snakeCase',
123
+ template: `{{- . | snakecase }}`,
124
+ },
125
+ {
126
+ name: 'string.randomAlphaNum',
127
+ template: `{{- $length := . | default 8 -}}
128
+ {{- randAlphaNum $length }}`,
129
+ },
130
+ {
131
+ name: 'env.getOrDefault',
132
+ template: `{{- $key := .key -}}
133
+ {{- $default := .default | default "" -}}
134
+ {{- $default }}`,
135
+ },
136
+ {
137
+ name: 'list.compact',
138
+ template: `{{- $list := . -}}
139
+ {{- $result := list -}}
140
+ {{- range $list -}}
141
+ {{- if . -}}
142
+ {{- $result = append $result . -}}
143
+ {{- end -}}
144
+ {{- end -}}
145
+ {{- $result | toJson }}`,
146
+ },
147
+ {
148
+ name: 'dict.merge',
149
+ template: `{{- $base := .base | default dict -}}
150
+ {{- $override := .override | default dict -}}
151
+ {{- merge $override $base | toJson }}`,
152
+ },
153
+ {
154
+ name: 'date.now',
155
+ template: `{{- now | date "2006-01-02T15:04:05Z07:00" }}`,
156
+ },
157
+ {
158
+ name: 'date.format',
159
+ template: `{{- $format := .format | default "2006-01-02" -}}
160
+ {{- $date := .date | default now -}}
161
+ {{- $date | date $format }}`,
162
+ },
163
+ ];
164
+ export const KUBERNETES_HELPERS = [
165
+ {
166
+ name: 'k8s.imagePullPolicy',
167
+ template: `{{- $tag := .tag | default .Values.image.tag -}}
168
+ {{- if or (eq $tag "latest") (hasSuffix "-SNAPSHOT" $tag) -}}
169
+ Always
170
+ {{- else -}}
171
+ IfNotPresent
172
+ {{- end }}`,
173
+ },
174
+ {
175
+ name: 'k8s.resourceName',
176
+ template: `{{- $root := .root | default . -}}
177
+ {{- $name := .name | default (include "chart.fullname" $root) -}}
178
+ {{- $suffix := .suffix | default "" -}}
179
+ {{- if $suffix -}}
180
+ {{- printf "%s-%s" $name $suffix | trunc 63 | trimSuffix "-" -}}
181
+ {{- else -}}
182
+ {{- $name | trunc 63 | trimSuffix "-" -}}
183
+ {{- end }}`,
184
+ },
185
+ {
186
+ name: 'k8s.annotations',
187
+ template: `{{- $global := .Values.global.annotations | default dict -}}
188
+ {{- $local := .annotations | default dict -}}
189
+ {{- $merged := merge $local $global -}}
190
+ {{- if $merged -}}
191
+ {{- range $key, $value := $merged }}
192
+ {{ $key }}: {{ $value | quote }}
193
+ {{- end -}}
194
+ {{- end }}`,
195
+ },
196
+ {
197
+ name: 'k8s.labels',
198
+ template: `{{- $global := .Values.global.labels | default dict -}}
199
+ {{- $local := .labels | default dict -}}
200
+ {{- $standard := include "chart.labels" . | fromYaml -}}
201
+ {{- $merged := merge $local $global $standard -}}
202
+ {{- range $key, $value := $merged }}
203
+ {{ $key }}: {{ $value | quote }}
204
+ {{- end }}`,
205
+ },
206
+ {
207
+ name: 'k8s.probe',
208
+ template: `{{- $probe := . -}}
209
+ {{- if $probe.enabled | default true -}}
210
+ {{- if $probe.httpGet }}
211
+ httpGet:
212
+ path: {{ $probe.httpGet.path | default "/" }}
213
+ port: {{ $probe.httpGet.port | default "http" }}
214
+ {{- if $probe.httpGet.scheme }}
215
+ scheme: {{ $probe.httpGet.scheme }}
216
+ {{- end }}
217
+ {{- else if $probe.tcpSocket }}
218
+ tcpSocket:
219
+ port: {{ $probe.tcpSocket.port | default "http" }}
220
+ {{- else if $probe.exec }}
221
+ exec:
222
+ command:
223
+ {{- range $probe.exec.command }}
224
+ - {{ . | quote }}
225
+ {{- end }}
226
+ {{- end }}
227
+ initialDelaySeconds: {{ $probe.initialDelaySeconds | default 30 }}
228
+ periodSeconds: {{ $probe.periodSeconds | default 10 }}
229
+ timeoutSeconds: {{ $probe.timeoutSeconds | default 5 }}
230
+ successThreshold: {{ $probe.successThreshold | default 1 }}
231
+ failureThreshold: {{ $probe.failureThreshold | default 3 }}
232
+ {{- end }}`,
233
+ },
234
+ ];
38
235
  export const AWS_HELPERS = [
39
236
  {
40
237
  name: 'aws.region',
@@ -52,6 +249,19 @@ export const AWS_HELPERS = [
52
249
  name: 'aws.ecrRepository',
53
250
  template: `{{- printf "%s.dkr.ecr.%s.amazonaws.com/%s" (include "aws.accountId" .) (include "aws.region" .) .Values.aws.ecrRepositoryName }}`,
54
251
  },
252
+ {
253
+ name: 'aws.s3Bucket',
254
+ template: `{{- $region := include "aws.region" . -}}
255
+ {{- $accountId := include "aws.accountId" . -}}
256
+ {{- $bucketName := .bucketName | default (printf "%s-%s-%s" .Release.Name $region $accountId | lower) -}}
257
+ {{- $bucketName | trunc 63 | trimSuffix "-" }}`,
258
+ },
259
+ {
260
+ name: 'aws.secretsManagerSecret',
261
+ template: `{{- $region := include "aws.region" . -}}
262
+ {{- $secretName := .secretName | default (printf "%s/%s" .Release.Namespace .Release.Name) -}}
263
+ {{- printf "arn:aws:secretsmanager:%s:%s:secret:%s" $region (include "aws.accountId" .) $secretName }}`,
264
+ },
55
265
  ];
56
266
  export function formatHelpers(helpers) {
57
267
  return helpers
@@ -63,17 +273,50 @@ ${helper.template}
63
273
  {{- end }}`)
64
274
  .join('\n\n');
65
275
  }
66
- export function getDefaultHelpers(cloudProvider) {
276
+ export function getDefaultHelpers(cloudProvider, options) {
67
277
  const helpers = [...STANDARD_HELPERS];
278
+ if (options?.includeFileAccess !== false) {
279
+ helpers.push(...FILE_ACCESS_HELPERS);
280
+ }
281
+ if (options?.includeTemplateFunction !== false) {
282
+ helpers.push(...TEMPLATE_FUNCTION_HELPERS);
283
+ }
284
+ if (options?.includeSprig !== false) {
285
+ helpers.push(...SPRIG_HELPERS);
286
+ }
287
+ if (options?.includeKubernetes !== false) {
288
+ helpers.push(...KUBERNETES_HELPERS);
289
+ }
68
290
  if (cloudProvider === 'aws') {
69
291
  helpers.push(...AWS_HELPERS);
70
292
  }
71
293
  return helpers;
72
294
  }
73
- export function generateHelpersTemplate(cloudProvider, customHelpers) {
74
- const helpers = getDefaultHelpers(cloudProvider);
295
+ export function generateHelpersTemplate(cloudProvider, customHelpers, options) {
296
+ const helpers = getDefaultHelpers(cloudProvider, options);
75
297
  if (customHelpers) {
76
298
  helpers.push(...customHelpers);
77
299
  }
78
300
  return formatHelpers(helpers);
79
301
  }
302
+ export function getHelpersByCategory(category) {
303
+ switch (category) {
304
+ case 'standard':
305
+ return [...STANDARD_HELPERS];
306
+ case 'fileAccess':
307
+ return [...FILE_ACCESS_HELPERS];
308
+ case 'templateFunction':
309
+ return [...TEMPLATE_FUNCTION_HELPERS];
310
+ case 'sprig':
311
+ return [...SPRIG_HELPERS];
312
+ case 'kubernetes':
313
+ return [...KUBERNETES_HELPERS];
314
+ case 'aws':
315
+ return [...AWS_HELPERS];
316
+ default:
317
+ return [];
318
+ }
319
+ }
320
+ export function createHelper(name, template) {
321
+ return { name, template };
322
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "timonel",
3
3
  "type": "module",
4
- "version": "2.8.3",
4
+ "version": "2.9.1",
5
5
  "description": "Timonel: programmatic Helm chart generator using cdk8s (TypeScript)",
6
6
  "bin": {
7
7
  "timonel": "dist/cli.js",
@@ -37,12 +37,9 @@
37
37
  "deps:update": "pnpm update --latest",
38
38
  "md:lint": "markdownlint \"**/*.md\"",
39
39
  "md:fix": "markdownlint --fix \"**/*.md\"",
40
- "test": "pnpm test:unit && pnpm test:integration",
41
- "test:unit": "vitest run --config vitest.config.ts",
42
- "test:integration": "vitest run --config vitest.integration.config.ts",
40
+ "test:integration": "vitest run --config vitest.config.ts",
43
41
  "test:watch": "vitest",
44
42
  "test:coverage": "vitest run --coverage",
45
- "test:basic-integration": "vitest run tests/integration/basic-chart-generation.int.spec.ts --config vitest.integration.config.ts",
46
43
  "ci:check": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm build",
47
44
  "release": "semantic-release",
48
45
  "release:dry": "semantic-release --dry-run",
@@ -87,6 +84,8 @@
87
84
  "cdk8s": "^2.70.11",
88
85
  "cdk8s-plus-33": "^2.3.5",
89
86
  "constructs": "^10.4.2",
87
+ "handlebars": "^4.7.8",
88
+ "timonel": "^2.9.0",
90
89
  "ts-node": "^10.9.2",
91
90
  "yaml": "^2.8.1"
92
91
  },