@kustodian/generator 1.0.0 → 1.1.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.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @kustodian/generator
2
+
3
+ Template processing and Flux CD resource generation for Kustodian.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @kustodian/generator
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ This package provides the core generation engine for transforming Kustodian templates into Flux CD resources. It handles template resolution, variable substitution, dependency validation, and output serialization.
14
+
15
+ ## API
16
+
17
+ ### Generator
18
+
19
+ ```typescript
20
+ import { create_generator } from '@kustodian/generator';
21
+
22
+ const generator = create_generator({
23
+ flux_namespace: 'flux-system',
24
+ git_repository_name: 'flux-system',
25
+ });
26
+
27
+ // Generate Flux resources for a cluster
28
+ const result = await generator.generate(cluster, templates, {
29
+ output_dir: './output',
30
+ });
31
+
32
+ // Write generated resources to disk
33
+ await generator.write(result.value);
34
+ ```
35
+
36
+ ### Flux Resource Generation
37
+
38
+ - `generate_flux_kustomization()` - Creates Flux Kustomization resources
39
+ - `generate_flux_oci_repository()` - Creates OCI Repository sources
40
+ - `generate_depends_on()` - Resolves dependency references
41
+ - `generate_health_checks()` - Configures health checks
42
+
43
+ ### Substitution Processing
44
+
45
+ - `substitute_string()` / `substitute_object()` - Apply variable substitutions
46
+ - `validate_substitutions()` - Validate required values are provided
47
+ - `extract_external_substitutions()` - Extract 1Password/Doppler references
48
+
49
+ ### Namespace Management
50
+
51
+ - `generate_namespace_resources()` - Generate Namespace resources
52
+ - `collect_namespaces()` - Collect all namespaces from templates
53
+ - `filter_system_namespaces()` - Filter out system namespaces
54
+
55
+ ### Dependency Validation
56
+
57
+ - `validate_dependencies()` - Validate dependency graph
58
+ - `validate_dependency_graph()` - Full graph validation with cycle detection
59
+ - `build_dependency_graph()` - Build dependency graph from templates
60
+
61
+ ### Output Serialization
62
+
63
+ - `serialize_resource()` / `serialize_resources()` - Serialize to YAML/JSON
64
+ - `write_generation_result()` - Write all generated resources to disk
65
+
66
+ ## License
67
+
68
+ MIT
69
+
70
+ ## Repository
71
+
72
+ [github.com/lucasilverentand/kustodian](https://github.com/lucasilverentand/kustodian)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kustodian/generator",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Template processing and Flux generation for Kustodian",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -35,10 +35,10 @@
35
35
  "registry": "https://npm.pkg.github.com"
36
36
  },
37
37
  "dependencies": {
38
- "@kustodian/core": "workspace:*",
39
- "@kustodian/loader": "workspace:*",
40
- "@kustodian/plugins": "workspace:*",
41
- "@kustodian/schema": "workspace:*",
38
+ "@kustodian/core": "1.0.0",
39
+ "@kustodian/loader": "1.0.0",
40
+ "@kustodian/plugins": "1.0.0",
41
+ "@kustodian/schema": "1.0.0",
42
42
  "yaml": "^2.8.2"
43
43
  },
44
44
  "devDependencies": {}
@@ -4,10 +4,7 @@ import type {
4
4
  SubstitutionType,
5
5
  TemplateType,
6
6
  } from '@kustodian/schema';
7
- import {
8
- is_doppler_substitution,
9
- is_onepassword_substitution,
10
- } from '@kustodian/schema';
7
+ import { is_doppler_substitution, is_onepassword_substitution } from '@kustodian/schema';
11
8
 
12
9
  /**
13
10
  * Extracts 1Password substitutions from templates.
@@ -54,9 +51,10 @@ export function extract_doppler_substitutions(
54
51
  /**
55
52
  * Extracts all external substitutions (1Password and Doppler) from templates.
56
53
  */
57
- export function extract_external_substitutions(
58
- templates: TemplateType[],
59
- ): { onepassword: OnePasswordSubstitutionType[]; doppler: DopplerSubstitutionType[] } {
54
+ export function extract_external_substitutions(templates: TemplateType[]): {
55
+ onepassword: OnePasswordSubstitutionType[];
56
+ doppler: DopplerSubstitutionType[];
57
+ } {
60
58
  return {
61
59
  onepassword: extract_onepassword_substitutions(templates),
62
60
  doppler: extract_doppler_substitutions(templates),
package/src/flux.ts CHANGED
@@ -80,13 +80,49 @@ export function generate_health_checks(
80
80
  }
81
81
 
82
82
  return kustomization.health_checks.map((check) => ({
83
- apiVersion: 'apps/v1',
83
+ apiVersion: check.api_version ?? 'apps/v1',
84
84
  kind: check.kind,
85
85
  name: check.name,
86
86
  namespace: check.namespace ?? namespace,
87
87
  }));
88
88
  }
89
89
 
90
+ /**
91
+ * Generates custom health checks with CEL expressions for a Flux Kustomization.
92
+ */
93
+ export function generate_custom_health_checks(
94
+ kustomization: KustomizationType,
95
+ namespace: string,
96
+ ): FluxKustomizationType['spec']['customHealthChecks'] {
97
+ if (!kustomization.health_check_exprs || kustomization.health_check_exprs.length === 0) {
98
+ return undefined;
99
+ }
100
+
101
+ return kustomization.health_check_exprs.map((check) => {
102
+ const healthCheck: {
103
+ apiVersion: string;
104
+ kind: string;
105
+ namespace?: string;
106
+ current?: string;
107
+ failed?: string;
108
+ } = {
109
+ apiVersion: check.api_version,
110
+ kind: check.kind,
111
+ namespace: check.namespace ?? namespace,
112
+ };
113
+
114
+ if (check.current !== undefined) {
115
+ healthCheck.current = check.current;
116
+ }
117
+
118
+ if (check.failed !== undefined) {
119
+ healthCheck.failed = check.failed;
120
+ }
121
+
122
+ return healthCheck;
123
+ });
124
+ }
125
+
90
126
  /**
91
127
  * Generates a Flux OCIRepository resource.
92
128
  */
@@ -191,6 +227,12 @@ export function generate_flux_kustomization(
191
227
  spec.healthChecks = health_checks;
192
228
  }
193
229
 
230
+ // Add custom health checks with CEL expressions
231
+ const custom_health_checks = generate_custom_health_checks(kustomization, namespace);
232
+ if (custom_health_checks) {
233
+ spec.customHealthChecks = custom_health_checks;
234
+ }
235
+
194
236
  return {
195
237
  apiVersion: 'kustomize.toolkit.fluxcd.io/v1',
196
238
  kind: 'Kustomization',
package/src/output.ts CHANGED
@@ -150,7 +150,10 @@ export async function write_generation_result(
150
150
  // Write each kustomization to templates/{template-name}/{kustomization-name}.yaml
151
151
  for (const generated of result.kustomizations) {
152
152
  const template_dir = path.join(templates_dir, generated.template);
153
- const file_path = path.join(template_dir, `${generated.flux_kustomization.metadata.name}.${ext}`);
153
+ const file_path = path.join(
154
+ template_dir,
155
+ `${generated.flux_kustomization.metadata.name}.${ext}`,
156
+ );
154
157
 
155
158
  const content = serialize_resource(generated.flux_kustomization, format);
156
159
  const file_result = await write_file(file_path, content, options);
package/src/types.ts CHANGED
@@ -116,5 +116,14 @@ export interface FluxKustomizationType {
116
116
  name: string;
117
117
  namespace: string;
118
118
  }>;
119
+ customHealthChecks?: Array<{
120
+ apiVersion: string;
121
+ kind: string;
122
+ namespace?: string;
123
+ /** CEL expression for when resource is healthy/current */
124
+ current?: string;
125
+ /** CEL expression for when resource has failed */
126
+ failed?: string;
127
+ }>;
119
128
  };
120
129
  }