@intentius/chant-lexicon-helm 0.0.18 → 0.0.24
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/dist/integrity.json +5 -5
- package/dist/manifest.json +1 -1
- package/dist/skills/chant-helm.md +447 -0
- package/package.json +21 -3
- package/src/codegen/docs.test.ts +14 -0
- package/src/codegen/generate.test.ts +71 -0
- package/src/codegen/package.test.ts +36 -0
- package/src/composites/composites.test.ts +116 -110
- package/src/composites/helm-batch-job.ts +33 -19
- package/src/composites/helm-crd-lifecycle.ts +37 -24
- package/src/composites/helm-cron-job.ts +25 -13
- package/src/composites/helm-daemon-set.ts +26 -14
- package/src/composites/helm-external-secret.ts +21 -12
- package/src/composites/helm-library.ts +21 -7
- package/src/composites/helm-microservice.ts +46 -29
- package/src/composites/helm-monitored-service.ts +75 -51
- package/src/composites/helm-namespace-env.ts +80 -52
- package/src/composites/helm-secure-ingress.ts +66 -50
- package/src/composites/helm-stateful-service.ts +29 -16
- package/src/composites/helm-web-app.ts +37 -22
- package/src/composites/helm-worker.ts +34 -20
- package/src/import/roundtrip.test.ts +144 -0
- package/src/lint/post-synth/whm101.test.ts +69 -0
- package/src/lint/post-synth/whm102.test.ts +57 -0
- package/src/lint/post-synth/whm103.test.ts +58 -0
- package/src/lint/post-synth/whm104.test.ts +57 -0
- package/src/lint/post-synth/whm105.test.ts +41 -0
- package/src/lint/post-synth/whm201.test.ts +59 -0
- package/src/lint/post-synth/whm202.test.ts +62 -0
- package/src/lint/post-synth/whm203.test.ts +58 -0
- package/src/lint/post-synth/whm204.test.ts +56 -0
- package/src/lint/post-synth/whm301.test.ts +49 -0
- package/src/lint/post-synth/whm302.test.ts +58 -0
- package/src/lint/post-synth/whm401.test.ts +59 -0
- package/src/lint/post-synth/whm402.test.ts +58 -0
- package/src/lint/post-synth/whm403.test.ts +50 -0
- package/src/lint/post-synth/whm404.test.ts +50 -0
- package/src/lint/post-synth/whm405.test.ts +60 -0
- package/src/lint/post-synth/whm406.test.ts +43 -0
- package/src/lint/post-synth/whm407.test.ts +60 -0
- package/src/lint/post-synth/whm501.test.ts +70 -0
- package/src/lint/post-synth/whm502.test.ts +72 -0
- package/src/lint/rules/chart-metadata.test.ts +45 -0
- package/src/lint/rules/no-hardcoded-image.test.ts +41 -0
- package/src/lint/rules/values-no-secrets.test.ts +48 -0
- package/src/plugin.test.ts +3 -3
- package/src/plugin.ts +190 -19
- package/src/resources.ts +29 -0
- package/src/skills/chant-helm.md +447 -0
- package/dist/skills/chant-helm-create-chart.md +0 -211
- package/src/skills/create-chart.md +0 -211
- /package/dist/skills/{chant-helm-chart-patterns.md → chant-helm-patterns.md} +0 -0
- /package/dist/skills/{chant-helm-chart-security-patterns.md → chant-helm-security.md} +0 -0
- /package/src/skills/{chart-patterns.md → chant-helm-patterns.md} +0 -0
- /package/src/skills/{chart-security-patterns.md → chant-helm-security.md} +0 -0
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* for automatic certificate provisioning.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { Composite, mergeDefaults } from "@intentius/chant";
|
|
9
|
+
import { Chart, Values, Ingress, Certificate } from "../resources";
|
|
8
10
|
import { values, include, toYaml, If, Range } from "../intrinsics";
|
|
9
11
|
|
|
10
12
|
export interface HelmSecureIngressProps {
|
|
@@ -16,33 +18,41 @@ export interface HelmSecureIngressProps {
|
|
|
16
18
|
clusterIssuer?: string;
|
|
17
19
|
/** Chart appVersion. */
|
|
18
20
|
appVersion?: string;
|
|
21
|
+
/** Per-member defaults. */
|
|
22
|
+
defaults?: {
|
|
23
|
+
chart?: Partial<Record<string, unknown>>;
|
|
24
|
+
values?: Partial<Record<string, unknown>>;
|
|
25
|
+
ingress?: Partial<Record<string, unknown>>;
|
|
26
|
+
certificate?: Partial<Record<string, unknown>>;
|
|
27
|
+
};
|
|
19
28
|
}
|
|
20
29
|
|
|
21
30
|
export interface HelmSecureIngressResult {
|
|
22
|
-
chart:
|
|
23
|
-
values:
|
|
24
|
-
ingress:
|
|
25
|
-
certificate?:
|
|
31
|
+
chart: InstanceType<typeof Chart>;
|
|
32
|
+
values: InstanceType<typeof Values>;
|
|
33
|
+
ingress: InstanceType<typeof Ingress>;
|
|
34
|
+
certificate?: InstanceType<typeof Certificate>;
|
|
26
35
|
}
|
|
27
36
|
|
|
28
|
-
export
|
|
37
|
+
export const HelmSecureIngress = Composite<HelmSecureIngressProps>((props) => {
|
|
29
38
|
const {
|
|
30
39
|
name,
|
|
31
40
|
ingressClassName = "",
|
|
32
41
|
clusterIssuer = "letsencrypt-prod",
|
|
33
42
|
appVersion = "1.0.0",
|
|
43
|
+
defaults: defs,
|
|
34
44
|
} = props;
|
|
35
45
|
|
|
36
|
-
const chart = {
|
|
46
|
+
const chart = new Chart(mergeDefaults({
|
|
37
47
|
apiVersion: "v2",
|
|
38
48
|
name,
|
|
39
49
|
version: "0.1.0",
|
|
40
50
|
appVersion,
|
|
41
51
|
type: "application",
|
|
42
52
|
description: `A Helm chart for ${name} secure ingress`,
|
|
43
|
-
};
|
|
53
|
+
}, defs?.chart));
|
|
44
54
|
|
|
45
|
-
const
|
|
55
|
+
const valuesRes = new Values(mergeDefaults({
|
|
46
56
|
ingress: {
|
|
47
57
|
enabled: true,
|
|
48
58
|
className: ingressClassName,
|
|
@@ -62,53 +72,59 @@ export function HelmSecureIngress(props: HelmSecureIngressProps): HelmSecureIngr
|
|
|
62
72
|
enabled: true,
|
|
63
73
|
clusterIssuer,
|
|
64
74
|
},
|
|
65
|
-
};
|
|
75
|
+
} as Record<string, unknown>, defs?.values));
|
|
66
76
|
|
|
67
|
-
const ingress =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
77
|
+
const ingress = new Ingress(mergeDefaults(
|
|
78
|
+
If(values.ingress.enabled, {
|
|
79
|
+
apiVersion: "networking.k8s.io/v1",
|
|
80
|
+
kind: "Ingress",
|
|
81
|
+
metadata: {
|
|
82
|
+
name: include(`${name}.fullname`),
|
|
83
|
+
labels: include(`${name}.labels`),
|
|
84
|
+
annotations: toYaml(values.ingress.annotations),
|
|
85
|
+
},
|
|
86
|
+
spec: {
|
|
87
|
+
ingressClassName: values.ingress.className,
|
|
88
|
+
tls: [{
|
|
89
|
+
secretName: values.ingress.tls.secretName,
|
|
90
|
+
hosts: Range(values.ingress.hosts, values.ingress.hosts),
|
|
91
|
+
}],
|
|
92
|
+
rules: Range(values.ingress.hosts, {
|
|
93
|
+
host: values.ingress.hosts,
|
|
94
|
+
http: {
|
|
95
|
+
paths: values.ingress.hosts,
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
},
|
|
99
|
+
}) as Record<string, unknown>,
|
|
100
|
+
defs?.ingress,
|
|
101
|
+
));
|
|
89
102
|
|
|
90
103
|
// cert-manager Certificate CRD (cert-manager.io/v1)
|
|
91
|
-
const certificate =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
spec: {
|
|
99
|
-
secretName: values.ingress.tls.secretName,
|
|
100
|
-
issuerRef: {
|
|
101
|
-
name: values.certManager.clusterIssuer,
|
|
102
|
-
kind: "ClusterIssuer",
|
|
104
|
+
const certificate = new Certificate(mergeDefaults(
|
|
105
|
+
If(values.certManager.enabled, {
|
|
106
|
+
apiVersion: "cert-manager.io/v1",
|
|
107
|
+
kind: "Certificate",
|
|
108
|
+
metadata: {
|
|
109
|
+
name: include(`${name}.fullname`),
|
|
110
|
+
labels: include(`${name}.labels`),
|
|
103
111
|
},
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
112
|
+
spec: {
|
|
113
|
+
secretName: values.ingress.tls.secretName,
|
|
114
|
+
issuerRef: {
|
|
115
|
+
name: values.certManager.clusterIssuer,
|
|
116
|
+
kind: "ClusterIssuer",
|
|
117
|
+
},
|
|
118
|
+
dnsNames: values.ingress.hosts,
|
|
119
|
+
},
|
|
120
|
+
}) as Record<string, unknown>,
|
|
121
|
+
defs?.certificate,
|
|
122
|
+
));
|
|
107
123
|
|
|
108
124
|
return {
|
|
109
125
|
chart,
|
|
110
|
-
values:
|
|
111
|
-
ingress
|
|
112
|
-
certificate
|
|
126
|
+
values: valuesRes,
|
|
127
|
+
ingress,
|
|
128
|
+
certificate,
|
|
113
129
|
};
|
|
114
|
-
}
|
|
130
|
+
}, "HelmSecureIngress");
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Produces a Helm chart for stateful workloads with persistent storage.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { Composite, mergeDefaults } from "@intentius/chant";
|
|
8
|
+
import { Chart, Values, StatefulSet, Service, ServiceAccount } from "../resources";
|
|
7
9
|
import { values, include, printf, toYaml, With } from "../intrinsics";
|
|
8
10
|
|
|
9
11
|
export interface HelmStatefulServiceProps {
|
|
@@ -43,17 +45,25 @@ export interface HelmStatefulServiceProps {
|
|
|
43
45
|
serviceAccount?: boolean;
|
|
44
46
|
/** StatefulSet update strategy defaults. */
|
|
45
47
|
updateStrategy?: Record<string, unknown>;
|
|
48
|
+
/** Per-member defaults. */
|
|
49
|
+
defaults?: {
|
|
50
|
+
chart?: Partial<Record<string, unknown>>;
|
|
51
|
+
values?: Partial<Record<string, unknown>>;
|
|
52
|
+
statefulSet?: Partial<Record<string, unknown>>;
|
|
53
|
+
service?: Partial<Record<string, unknown>>;
|
|
54
|
+
serviceAccount?: Partial<Record<string, unknown>>;
|
|
55
|
+
};
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
export interface HelmStatefulServiceResult {
|
|
49
|
-
chart:
|
|
50
|
-
values:
|
|
51
|
-
statefulSet:
|
|
52
|
-
service:
|
|
53
|
-
serviceAccount?:
|
|
59
|
+
chart: InstanceType<typeof Chart>;
|
|
60
|
+
values: InstanceType<typeof Values>;
|
|
61
|
+
statefulSet: InstanceType<typeof StatefulSet>;
|
|
62
|
+
service: InstanceType<typeof Service>;
|
|
63
|
+
serviceAccount?: InstanceType<typeof ServiceAccount>;
|
|
54
64
|
}
|
|
55
65
|
|
|
56
|
-
export
|
|
66
|
+
export const HelmStatefulService = Composite<HelmStatefulServiceProps>((props) => {
|
|
57
67
|
const {
|
|
58
68
|
name,
|
|
59
69
|
imageRepository = "postgres",
|
|
@@ -64,16 +74,17 @@ export function HelmStatefulService(props: HelmStatefulServiceProps): HelmStatef
|
|
|
64
74
|
storageClass = "",
|
|
65
75
|
appVersion = "1.0.0",
|
|
66
76
|
serviceAccount = false,
|
|
77
|
+
defaults: defs,
|
|
67
78
|
} = props;
|
|
68
79
|
|
|
69
|
-
const chart = {
|
|
80
|
+
const chart = new Chart(mergeDefaults({
|
|
70
81
|
apiVersion: "v2",
|
|
71
82
|
name,
|
|
72
83
|
version: "0.1.0",
|
|
73
84
|
appVersion,
|
|
74
85
|
type: "application",
|
|
75
86
|
description: `A Helm chart for ${name} (stateful)`,
|
|
76
|
-
};
|
|
87
|
+
}, defs?.chart));
|
|
77
88
|
|
|
78
89
|
const valuesObj: Record<string, unknown> = {
|
|
79
90
|
replicaCount: replicas,
|
|
@@ -111,6 +122,8 @@ export function HelmStatefulService(props: HelmStatefulServiceProps): HelmStatef
|
|
|
111
122
|
};
|
|
112
123
|
}
|
|
113
124
|
|
|
125
|
+
const valuesRes = new Values(mergeDefaults(valuesObj, defs?.values));
|
|
126
|
+
|
|
114
127
|
const containerSpec: Record<string, unknown> = {
|
|
115
128
|
name,
|
|
116
129
|
image: printf("%s:%s", values.image.repository, values.image.tag),
|
|
@@ -166,7 +179,7 @@ export function HelmStatefulService(props: HelmStatefulServiceProps): HelmStatef
|
|
|
166
179
|
|
|
167
180
|
if (props.updateStrategy) statefulSetSpec.updateStrategy = toYaml(values.updateStrategy);
|
|
168
181
|
|
|
169
|
-
const statefulSet = {
|
|
182
|
+
const statefulSet = new StatefulSet(mergeDefaults({
|
|
170
183
|
apiVersion: "apps/v1",
|
|
171
184
|
kind: "StatefulSet",
|
|
172
185
|
metadata: {
|
|
@@ -174,9 +187,9 @@ export function HelmStatefulService(props: HelmStatefulServiceProps): HelmStatef
|
|
|
174
187
|
labels: include(`${name}.labels`),
|
|
175
188
|
},
|
|
176
189
|
spec: statefulSetSpec,
|
|
177
|
-
};
|
|
190
|
+
}, defs?.statefulSet));
|
|
178
191
|
|
|
179
|
-
const service = {
|
|
192
|
+
const service = new Service(mergeDefaults({
|
|
180
193
|
apiVersion: "v1",
|
|
181
194
|
kind: "Service",
|
|
182
195
|
metadata: {
|
|
@@ -193,12 +206,12 @@ export function HelmStatefulService(props: HelmStatefulServiceProps): HelmStatef
|
|
|
193
206
|
}],
|
|
194
207
|
selector: include(`${name}.selectorLabels`),
|
|
195
208
|
},
|
|
196
|
-
};
|
|
209
|
+
}, defs?.service));
|
|
197
210
|
|
|
198
|
-
const result:
|
|
211
|
+
const result: Record<string, any> = { chart, values: valuesRes, statefulSet, service };
|
|
199
212
|
|
|
200
213
|
if (serviceAccount) {
|
|
201
|
-
result.serviceAccount = {
|
|
214
|
+
result.serviceAccount = new ServiceAccount(mergeDefaults({
|
|
202
215
|
apiVersion: "v1",
|
|
203
216
|
kind: "ServiceAccount",
|
|
204
217
|
metadata: {
|
|
@@ -206,8 +219,8 @@ export function HelmStatefulService(props: HelmStatefulServiceProps): HelmStatef
|
|
|
206
219
|
labels: include(`${name}.labels`),
|
|
207
220
|
annotations: toYaml(values.serviceAccount.annotations),
|
|
208
221
|
},
|
|
209
|
-
};
|
|
222
|
+
}, defs?.serviceAccount));
|
|
210
223
|
}
|
|
211
224
|
|
|
212
225
|
return result;
|
|
213
|
-
}
|
|
226
|
+
}, "HelmStatefulService");
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Produces a full set of Helm chart entities with parameterized values references.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { Composite, mergeDefaults } from "@intentius/chant";
|
|
8
|
+
import { Chart, Values, Deployment, Service, ServiceAccount, Ingress, HPA } from "../resources";
|
|
7
9
|
import { values, include, printf, toYaml, If, With } from "../intrinsics";
|
|
8
10
|
|
|
9
11
|
export interface HelmWebAppProps {
|
|
@@ -45,19 +47,29 @@ export interface HelmWebAppProps {
|
|
|
45
47
|
readinessProbe?: Record<string, unknown>;
|
|
46
48
|
/** Deployment strategy defaults. */
|
|
47
49
|
strategy?: Record<string, unknown>;
|
|
50
|
+
/** Per-member defaults. */
|
|
51
|
+
defaults?: {
|
|
52
|
+
chart?: Partial<Record<string, unknown>>;
|
|
53
|
+
values?: Partial<Record<string, unknown>>;
|
|
54
|
+
deployment?: Partial<Record<string, unknown>>;
|
|
55
|
+
service?: Partial<Record<string, unknown>>;
|
|
56
|
+
serviceAccount?: Partial<Record<string, unknown>>;
|
|
57
|
+
ingress?: Partial<Record<string, unknown>>;
|
|
58
|
+
hpa?: Partial<Record<string, unknown>>;
|
|
59
|
+
};
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
export interface HelmWebAppResult {
|
|
51
|
-
chart:
|
|
52
|
-
values:
|
|
53
|
-
deployment:
|
|
54
|
-
service:
|
|
55
|
-
serviceAccount?:
|
|
56
|
-
ingress?:
|
|
57
|
-
hpa?:
|
|
63
|
+
chart: InstanceType<typeof Chart>;
|
|
64
|
+
values: InstanceType<typeof Values>;
|
|
65
|
+
deployment: InstanceType<typeof Deployment>;
|
|
66
|
+
service: InstanceType<typeof Service>;
|
|
67
|
+
serviceAccount?: InstanceType<typeof ServiceAccount>;
|
|
68
|
+
ingress?: InstanceType<typeof Ingress>;
|
|
69
|
+
hpa?: InstanceType<typeof HPA>;
|
|
58
70
|
}
|
|
59
71
|
|
|
60
|
-
export
|
|
72
|
+
export const HelmWebApp = Composite<HelmWebAppProps>((props) => {
|
|
61
73
|
const {
|
|
62
74
|
name,
|
|
63
75
|
imageRepository = "nginx",
|
|
@@ -69,16 +81,17 @@ export function HelmWebApp(props: HelmWebAppProps): HelmWebAppResult {
|
|
|
69
81
|
autoscaling = true,
|
|
70
82
|
serviceAccount = true,
|
|
71
83
|
appVersion = "1.0.0",
|
|
84
|
+
defaults: defs,
|
|
72
85
|
} = props;
|
|
73
86
|
|
|
74
|
-
const chart = {
|
|
87
|
+
const chart = new Chart(mergeDefaults({
|
|
75
88
|
apiVersion: "v2",
|
|
76
89
|
name,
|
|
77
90
|
version: "0.1.0",
|
|
78
91
|
appVersion,
|
|
79
92
|
type: "application",
|
|
80
93
|
description: `A Helm chart for ${name}`,
|
|
81
|
-
};
|
|
94
|
+
}, defs?.chart));
|
|
82
95
|
|
|
83
96
|
const valuesObj: Record<string, unknown> = {
|
|
84
97
|
replicaCount: replicas,
|
|
@@ -131,6 +144,8 @@ export function HelmWebApp(props: HelmWebAppProps): HelmWebAppResult {
|
|
|
131
144
|
};
|
|
132
145
|
}
|
|
133
146
|
|
|
147
|
+
const valuesRes = new Values(mergeDefaults(valuesObj, defs?.values));
|
|
148
|
+
|
|
134
149
|
const containerSpec: Record<string, unknown> = {
|
|
135
150
|
name,
|
|
136
151
|
image: printf("%s:%s", values.image.repository, values.image.tag),
|
|
@@ -170,7 +185,7 @@ export function HelmWebApp(props: HelmWebAppProps): HelmWebAppResult {
|
|
|
170
185
|
|
|
171
186
|
if (props.strategy) deploymentSpec.strategy = toYaml(values.strategy);
|
|
172
187
|
|
|
173
|
-
const deployment = {
|
|
188
|
+
const deployment = new Deployment(mergeDefaults({
|
|
174
189
|
apiVersion: "apps/v1",
|
|
175
190
|
kind: "Deployment",
|
|
176
191
|
metadata: {
|
|
@@ -178,9 +193,9 @@ export function HelmWebApp(props: HelmWebAppProps): HelmWebAppResult {
|
|
|
178
193
|
labels: include(`${name}.labels`),
|
|
179
194
|
},
|
|
180
195
|
spec: deploymentSpec,
|
|
181
|
-
};
|
|
196
|
+
}, defs?.deployment));
|
|
182
197
|
|
|
183
|
-
const service = {
|
|
198
|
+
const service = new Service(mergeDefaults({
|
|
184
199
|
apiVersion: "v1",
|
|
185
200
|
kind: "Service",
|
|
186
201
|
metadata: {
|
|
@@ -197,12 +212,12 @@ export function HelmWebApp(props: HelmWebAppProps): HelmWebAppResult {
|
|
|
197
212
|
}],
|
|
198
213
|
selector: include(`${name}.selectorLabels`),
|
|
199
214
|
},
|
|
200
|
-
};
|
|
215
|
+
}, defs?.service));
|
|
201
216
|
|
|
202
|
-
const result:
|
|
217
|
+
const result: Record<string, any> = { chart, values: valuesRes, deployment, service };
|
|
203
218
|
|
|
204
219
|
if (serviceAccount) {
|
|
205
|
-
result.serviceAccount = {
|
|
220
|
+
result.serviceAccount = new ServiceAccount(mergeDefaults({
|
|
206
221
|
apiVersion: "v1",
|
|
207
222
|
kind: "ServiceAccount",
|
|
208
223
|
metadata: {
|
|
@@ -210,11 +225,11 @@ export function HelmWebApp(props: HelmWebAppProps): HelmWebAppResult {
|
|
|
210
225
|
labels: include(`${name}.labels`),
|
|
211
226
|
annotations: toYaml(values.serviceAccount.annotations),
|
|
212
227
|
},
|
|
213
|
-
};
|
|
228
|
+
}, defs?.serviceAccount));
|
|
214
229
|
}
|
|
215
230
|
|
|
216
231
|
if (ingress) {
|
|
217
|
-
result.ingress = {
|
|
232
|
+
result.ingress = new Ingress(mergeDefaults({
|
|
218
233
|
apiVersion: "networking.k8s.io/v1",
|
|
219
234
|
kind: "Ingress",
|
|
220
235
|
metadata: {
|
|
@@ -227,11 +242,11 @@ export function HelmWebApp(props: HelmWebAppProps): HelmWebAppResult {
|
|
|
227
242
|
rules: values.ingress.hosts,
|
|
228
243
|
tls: values.ingress.tls,
|
|
229
244
|
},
|
|
230
|
-
};
|
|
245
|
+
}, defs?.ingress));
|
|
231
246
|
}
|
|
232
247
|
|
|
233
248
|
if (autoscaling) {
|
|
234
|
-
result.hpa = {
|
|
249
|
+
result.hpa = new HPA(mergeDefaults({
|
|
235
250
|
apiVersion: "autoscaling/v2",
|
|
236
251
|
kind: "HorizontalPodAutoscaler",
|
|
237
252
|
metadata: {
|
|
@@ -257,8 +272,8 @@ export function HelmWebApp(props: HelmWebAppProps): HelmWebAppResult {
|
|
|
257
272
|
},
|
|
258
273
|
}],
|
|
259
274
|
},
|
|
260
|
-
};
|
|
275
|
+
}, defs?.hpa));
|
|
261
276
|
}
|
|
262
277
|
|
|
263
278
|
return result;
|
|
264
|
-
}
|
|
279
|
+
}, "HelmWebApp");
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* that don't serve HTTP traffic.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { Composite, mergeDefaults } from "@intentius/chant";
|
|
9
|
+
import { Chart, Values, Deployment, ServiceAccount, HPA, PDB } from "../resources";
|
|
8
10
|
import { values, include, printf, toYaml, If } from "../intrinsics";
|
|
9
11
|
|
|
10
12
|
export interface HelmWorkerProps {
|
|
@@ -22,18 +24,27 @@ export interface HelmWorkerProps {
|
|
|
22
24
|
pdb?: boolean;
|
|
23
25
|
/** Chart appVersion. */
|
|
24
26
|
appVersion?: string;
|
|
27
|
+
/** Per-member defaults. */
|
|
28
|
+
defaults?: {
|
|
29
|
+
chart?: Partial<Record<string, unknown>>;
|
|
30
|
+
values?: Partial<Record<string, unknown>>;
|
|
31
|
+
deployment?: Partial<Record<string, unknown>>;
|
|
32
|
+
serviceAccount?: Partial<Record<string, unknown>>;
|
|
33
|
+
hpa?: Partial<Record<string, unknown>>;
|
|
34
|
+
pdb?: Partial<Record<string, unknown>>;
|
|
35
|
+
};
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
export interface HelmWorkerResult {
|
|
28
|
-
chart:
|
|
29
|
-
values:
|
|
30
|
-
deployment:
|
|
31
|
-
serviceAccount:
|
|
32
|
-
hpa?:
|
|
33
|
-
pdb?:
|
|
39
|
+
chart: InstanceType<typeof Chart>;
|
|
40
|
+
values: InstanceType<typeof Values>;
|
|
41
|
+
deployment: InstanceType<typeof Deployment>;
|
|
42
|
+
serviceAccount: InstanceType<typeof ServiceAccount>;
|
|
43
|
+
hpa?: InstanceType<typeof HPA>;
|
|
44
|
+
pdb?: InstanceType<typeof PDB>;
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
export
|
|
47
|
+
export const HelmWorker = Composite<HelmWorkerProps>((props) => {
|
|
37
48
|
const {
|
|
38
49
|
name,
|
|
39
50
|
imageRepository = "worker",
|
|
@@ -42,16 +53,17 @@ export function HelmWorker(props: HelmWorkerProps): HelmWorkerResult {
|
|
|
42
53
|
autoscaling = false,
|
|
43
54
|
pdb = true,
|
|
44
55
|
appVersion = "1.0.0",
|
|
56
|
+
defaults: defs,
|
|
45
57
|
} = props;
|
|
46
58
|
|
|
47
|
-
const chart = {
|
|
59
|
+
const chart = new Chart(mergeDefaults({
|
|
48
60
|
apiVersion: "v2",
|
|
49
61
|
name,
|
|
50
62
|
version: "0.1.0",
|
|
51
63
|
appVersion,
|
|
52
64
|
type: "application",
|
|
53
65
|
description: `A Helm chart for ${name} worker`,
|
|
54
|
-
};
|
|
66
|
+
}, defs?.chart));
|
|
55
67
|
|
|
56
68
|
const valuesObj: Record<string, unknown> = {
|
|
57
69
|
replicaCount: replicas,
|
|
@@ -101,7 +113,9 @@ export function HelmWorker(props: HelmWorkerProps): HelmWorkerResult {
|
|
|
101
113
|
};
|
|
102
114
|
}
|
|
103
115
|
|
|
104
|
-
const
|
|
116
|
+
const valuesRes = new Values(mergeDefaults(valuesObj, defs?.values));
|
|
117
|
+
|
|
118
|
+
const deployment = new Deployment(mergeDefaults({
|
|
105
119
|
apiVersion: "apps/v1",
|
|
106
120
|
kind: "Deployment",
|
|
107
121
|
metadata: {
|
|
@@ -137,9 +151,9 @@ export function HelmWorker(props: HelmWorkerProps): HelmWorkerResult {
|
|
|
137
151
|
},
|
|
138
152
|
},
|
|
139
153
|
},
|
|
140
|
-
};
|
|
154
|
+
}, defs?.deployment));
|
|
141
155
|
|
|
142
|
-
const serviceAccount = {
|
|
156
|
+
const serviceAccount = new ServiceAccount(mergeDefaults({
|
|
143
157
|
apiVersion: "v1",
|
|
144
158
|
kind: "ServiceAccount",
|
|
145
159
|
metadata: {
|
|
@@ -147,17 +161,17 @@ export function HelmWorker(props: HelmWorkerProps): HelmWorkerResult {
|
|
|
147
161
|
labels: include(`${name}.labels`),
|
|
148
162
|
annotations: toYaml(values.serviceAccount.annotations),
|
|
149
163
|
},
|
|
150
|
-
};
|
|
164
|
+
}, defs?.serviceAccount));
|
|
151
165
|
|
|
152
|
-
const result:
|
|
166
|
+
const result: Record<string, any> = {
|
|
153
167
|
chart,
|
|
154
|
-
values:
|
|
168
|
+
values: valuesRes,
|
|
155
169
|
deployment,
|
|
156
170
|
serviceAccount,
|
|
157
171
|
};
|
|
158
172
|
|
|
159
173
|
if (autoscaling) {
|
|
160
|
-
result.hpa = {
|
|
174
|
+
result.hpa = new HPA(mergeDefaults({
|
|
161
175
|
apiVersion: "autoscaling/v2",
|
|
162
176
|
kind: "HorizontalPodAutoscaler",
|
|
163
177
|
metadata: {
|
|
@@ -183,11 +197,11 @@ export function HelmWorker(props: HelmWorkerProps): HelmWorkerResult {
|
|
|
183
197
|
},
|
|
184
198
|
}],
|
|
185
199
|
},
|
|
186
|
-
};
|
|
200
|
+
}, defs?.hpa));
|
|
187
201
|
}
|
|
188
202
|
|
|
189
203
|
if (pdb) {
|
|
190
|
-
result.pdb = {
|
|
204
|
+
result.pdb = new PDB(mergeDefaults({
|
|
191
205
|
apiVersion: "policy/v1",
|
|
192
206
|
kind: "PodDisruptionBudget",
|
|
193
207
|
metadata: {
|
|
@@ -200,8 +214,8 @@ export function HelmWorker(props: HelmWorkerProps): HelmWorkerResult {
|
|
|
200
214
|
matchLabels: include(`${name}.selectorLabels`),
|
|
201
215
|
},
|
|
202
216
|
},
|
|
203
|
-
};
|
|
217
|
+
}, defs?.pdb));
|
|
204
218
|
}
|
|
205
219
|
|
|
206
220
|
return result;
|
|
207
|
-
}
|
|
221
|
+
}, "HelmWorker");
|