@intentius/chant-lexicon-k8s 0.0.13 → 0.0.15
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 +20 -15
- package/dist/manifest.json +1 -1
- package/dist/rules/wk8204.ts +33 -1
- package/dist/rules/wk8304.ts +70 -0
- package/dist/rules/wk8305.ts +115 -0
- package/dist/rules/wk8306.ts +50 -0
- package/dist/skills/chant-k8s-eks.md +156 -0
- package/dist/skills/chant-k8s-patterns.md +245 -0
- package/dist/skills/chant-k8s.md +36 -227
- package/package.json +27 -24
- package/src/codegen/docs.ts +5 -5
- package/src/composites/adot-collector.ts +245 -0
- package/src/composites/agic-ingress.ts +149 -0
- package/src/composites/alb-ingress.ts +152 -0
- package/src/composites/autoscaled-service.ts +51 -0
- package/src/composites/azure-disk-storage-class.ts +82 -0
- package/src/composites/azure-file-storage-class.ts +77 -0
- package/src/composites/azure-monitor-collector.ts +232 -0
- package/src/composites/batch-job.ts +221 -0
- package/src/composites/composites.test.ts +1584 -0
- package/src/composites/config-connector-context.ts +62 -0
- package/src/composites/configured-app.ts +224 -0
- package/src/composites/cron-workload.ts +6 -0
- package/src/composites/ebs-storage-class.ts +96 -0
- package/src/composites/efs-storage-class.ts +77 -0
- package/src/composites/external-dns-agent.ts +174 -0
- package/src/composites/filestore-storage-class.ts +79 -0
- package/src/composites/fluent-bit-agent.ts +220 -0
- package/src/composites/gce-pd-storage-class.ts +85 -0
- package/src/composites/gke-gateway.ts +143 -0
- package/src/composites/index.ts +47 -0
- package/src/composites/irsa-service-account.ts +114 -0
- package/src/composites/metrics-server.ts +224 -0
- package/src/composites/monitored-service.ts +221 -0
- package/src/composites/network-isolated-app.ts +202 -0
- package/src/composites/node-agent.ts +6 -0
- package/src/composites/secure-ingress.ts +149 -0
- package/src/composites/security-context.ts +10 -0
- package/src/composites/sidecar-app.ts +207 -0
- package/src/composites/stateful-app.ts +67 -15
- package/src/composites/web-app.ts +104 -35
- package/src/composites/worker-pool.ts +38 -4
- package/src/composites/workload-identity-sa.ts +118 -0
- package/src/composites/workload-identity-service-account.ts +116 -0
- package/src/index.ts +24 -2
- package/src/lint/post-synth/post-synth.test.ts +362 -1
- package/src/lint/post-synth/wk8204.ts +33 -1
- package/src/lint/post-synth/wk8304.ts +70 -0
- package/src/lint/post-synth/wk8305.ts +115 -0
- package/src/lint/post-synth/wk8306.ts +50 -0
- package/src/plugin.test.ts +2 -2
- package/src/plugin.ts +556 -242
- package/src/serializer.test.ts +120 -0
- package/src/serializer.ts +16 -4
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* that need RBAC for secrets/configmaps and optional autoscaling, but no Service.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import type { ContainerSecurityContext } from "./security-context";
|
|
9
|
+
|
|
8
10
|
export interface WorkerPoolProps {
|
|
9
11
|
/** Worker name — used in metadata and labels. */
|
|
10
12
|
name: string;
|
|
@@ -30,6 +32,14 @@ export interface WorkerPoolProps {
|
|
|
30
32
|
maxReplicas: number;
|
|
31
33
|
targetCPUPercent?: number;
|
|
32
34
|
};
|
|
35
|
+
/** PodDisruptionBudget minAvailable — if set, creates a PDB. */
|
|
36
|
+
minAvailable?: number | string;
|
|
37
|
+
/** Container security context (supports PSS restricted fields). */
|
|
38
|
+
securityContext?: ContainerSecurityContext;
|
|
39
|
+
/** Termination grace period in seconds. */
|
|
40
|
+
terminationGracePeriodSeconds?: number;
|
|
41
|
+
/** Priority class name for pod scheduling. */
|
|
42
|
+
priorityClassName?: string;
|
|
33
43
|
/** CPU request (default: "100m"). */
|
|
34
44
|
cpuRequest?: string;
|
|
35
45
|
/** Memory request (default: "128Mi"). */
|
|
@@ -53,6 +63,7 @@ export interface WorkerPoolResult {
|
|
|
53
63
|
roleBinding?: Record<string, unknown>;
|
|
54
64
|
configMap?: Record<string, unknown>;
|
|
55
65
|
hpa?: Record<string, unknown>;
|
|
66
|
+
pdb?: Record<string, unknown>;
|
|
56
67
|
}
|
|
57
68
|
|
|
58
69
|
/**
|
|
@@ -81,6 +92,10 @@ export function WorkerPool(props: WorkerPoolProps): WorkerPoolResult {
|
|
|
81
92
|
config,
|
|
82
93
|
rbacRules,
|
|
83
94
|
autoscaling,
|
|
95
|
+
minAvailable,
|
|
96
|
+
securityContext,
|
|
97
|
+
terminationGracePeriodSeconds,
|
|
98
|
+
priorityClassName,
|
|
84
99
|
cpuRequest = "100m",
|
|
85
100
|
memoryRequest = "128Mi",
|
|
86
101
|
cpuLimit = "500m",
|
|
@@ -122,6 +137,14 @@ export function WorkerPool(props: WorkerPoolProps): WorkerPoolResult {
|
|
|
122
137
|
...(config && {
|
|
123
138
|
envFrom: [{ configMapRef: { name: configMapName } }],
|
|
124
139
|
}),
|
|
140
|
+
...(securityContext && { securityContext }),
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const podSpec: Record<string, unknown> = {
|
|
144
|
+
...(createRbac && { serviceAccountName: saName }),
|
|
145
|
+
containers: [container],
|
|
146
|
+
...(terminationGracePeriodSeconds !== undefined && { terminationGracePeriodSeconds }),
|
|
147
|
+
...(priorityClassName && { priorityClassName }),
|
|
125
148
|
};
|
|
126
149
|
|
|
127
150
|
const deploymentProps: Record<string, unknown> = {
|
|
@@ -135,10 +158,7 @@ export function WorkerPool(props: WorkerPoolProps): WorkerPoolResult {
|
|
|
135
158
|
selector: { matchLabels: { "app.kubernetes.io/name": name } },
|
|
136
159
|
template: {
|
|
137
160
|
metadata: { labels: { "app.kubernetes.io/name": name, ...extraLabels } },
|
|
138
|
-
spec:
|
|
139
|
-
...(createRbac && { serviceAccountName: saName }),
|
|
140
|
-
containers: [container],
|
|
141
|
-
},
|
|
161
|
+
spec: podSpec,
|
|
142
162
|
},
|
|
143
163
|
},
|
|
144
164
|
};
|
|
@@ -197,6 +217,20 @@ export function WorkerPool(props: WorkerPoolProps): WorkerPoolResult {
|
|
|
197
217
|
};
|
|
198
218
|
}
|
|
199
219
|
|
|
220
|
+
if (minAvailable !== undefined) {
|
|
221
|
+
result.pdb = {
|
|
222
|
+
metadata: {
|
|
223
|
+
name,
|
|
224
|
+
...(namespace && { namespace }),
|
|
225
|
+
labels: { ...commonLabels, "app.kubernetes.io/component": "disruption-budget" },
|
|
226
|
+
},
|
|
227
|
+
spec: {
|
|
228
|
+
minAvailable,
|
|
229
|
+
selector: { matchLabels: { "app.kubernetes.io/name": name } },
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
200
234
|
if (autoscaling) {
|
|
201
235
|
const targetCPUPercent = autoscaling.targetCPUPercent ?? 70;
|
|
202
236
|
result.hpa = {
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkloadIdentityServiceAccount composite — ServiceAccount + Workload Identity annotation + optional RBAC.
|
|
3
|
+
*
|
|
4
|
+
* @aks Creates a ServiceAccount with the `azure.workload.identity/client-id`
|
|
5
|
+
* annotation and `azure.workload.identity/use: "true"` label for AKS Workload Identity.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface WorkloadIdentityServiceAccountProps {
|
|
9
|
+
/** ServiceAccount name — used in metadata and labels. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Azure AD application client ID for Workload Identity. */
|
|
12
|
+
clientId: string;
|
|
13
|
+
/** Optional RBAC rules — if provided, creates Role + RoleBinding. */
|
|
14
|
+
rbacRules?: Array<{
|
|
15
|
+
apiGroups: string[];
|
|
16
|
+
resources: string[];
|
|
17
|
+
verbs: string[];
|
|
18
|
+
}>;
|
|
19
|
+
/** Additional labels to apply to all resources. */
|
|
20
|
+
labels?: Record<string, string>;
|
|
21
|
+
/** Namespace for all resources. */
|
|
22
|
+
namespace?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface WorkloadIdentityServiceAccountResult {
|
|
26
|
+
serviceAccount: Record<string, unknown>;
|
|
27
|
+
role?: Record<string, unknown>;
|
|
28
|
+
roleBinding?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Create a WorkloadIdentityServiceAccount composite — returns prop objects for
|
|
33
|
+
* a ServiceAccount with AKS Workload Identity annotation, and optional Role + RoleBinding.
|
|
34
|
+
*
|
|
35
|
+
* @aks
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { WorkloadIdentityServiceAccount } from "@intentius/chant-lexicon-k8s";
|
|
39
|
+
*
|
|
40
|
+
* const { serviceAccount, role, roleBinding } = WorkloadIdentityServiceAccount({
|
|
41
|
+
* name: "app-sa",
|
|
42
|
+
* clientId: "00000000-0000-0000-0000-000000000000",
|
|
43
|
+
* rbacRules: [
|
|
44
|
+
* { apiGroups: [""], resources: ["secrets"], verbs: ["get"] },
|
|
45
|
+
* ],
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function WorkloadIdentityServiceAccount(props: WorkloadIdentityServiceAccountProps): WorkloadIdentityServiceAccountResult {
|
|
50
|
+
const {
|
|
51
|
+
name,
|
|
52
|
+
clientId,
|
|
53
|
+
rbacRules,
|
|
54
|
+
labels: extraLabels = {},
|
|
55
|
+
namespace,
|
|
56
|
+
} = props;
|
|
57
|
+
|
|
58
|
+
const roleName = `${name}-role`;
|
|
59
|
+
const bindingName = `${name}-binding`;
|
|
60
|
+
|
|
61
|
+
const commonLabels: Record<string, string> = {
|
|
62
|
+
"app.kubernetes.io/name": name,
|
|
63
|
+
"app.kubernetes.io/managed-by": "chant",
|
|
64
|
+
...extraLabels,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const serviceAccountProps: Record<string, unknown> = {
|
|
68
|
+
metadata: {
|
|
69
|
+
name,
|
|
70
|
+
...(namespace && { namespace }),
|
|
71
|
+
labels: {
|
|
72
|
+
...commonLabels,
|
|
73
|
+
"app.kubernetes.io/component": "service-account",
|
|
74
|
+
"azure.workload.identity/use": "true",
|
|
75
|
+
},
|
|
76
|
+
annotations: {
|
|
77
|
+
"azure.workload.identity/client-id": clientId,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const result: WorkloadIdentityServiceAccountResult = {
|
|
83
|
+
serviceAccount: serviceAccountProps,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if (rbacRules && rbacRules.length > 0) {
|
|
87
|
+
result.role = {
|
|
88
|
+
metadata: {
|
|
89
|
+
name: roleName,
|
|
90
|
+
...(namespace && { namespace }),
|
|
91
|
+
labels: { ...commonLabels, "app.kubernetes.io/component": "rbac" },
|
|
92
|
+
},
|
|
93
|
+
rules: rbacRules,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
result.roleBinding = {
|
|
97
|
+
metadata: {
|
|
98
|
+
name: bindingName,
|
|
99
|
+
...(namespace && { namespace }),
|
|
100
|
+
labels: { ...commonLabels, "app.kubernetes.io/component": "rbac" },
|
|
101
|
+
},
|
|
102
|
+
roleRef: {
|
|
103
|
+
apiGroup: "rbac.authorization.k8s.io",
|
|
104
|
+
kind: "Role",
|
|
105
|
+
name: roleName,
|
|
106
|
+
},
|
|
107
|
+
subjects: [
|
|
108
|
+
{
|
|
109
|
+
kind: "ServiceAccount",
|
|
110
|
+
name,
|
|
111
|
+
...(namespace && { namespace }),
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkloadIdentityServiceAccount composite — ServiceAccount + GKE Workload Identity annotation + optional RBAC.
|
|
3
|
+
*
|
|
4
|
+
* @gke Creates a ServiceAccount with the `iam.gke.io/gcp-service-account`
|
|
5
|
+
* annotation for GKE Workload Identity Federation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface WorkloadIdentityServiceAccountProps {
|
|
9
|
+
/** ServiceAccount name — used in metadata and labels. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** GCP service account email for Workload Identity annotation. */
|
|
12
|
+
gcpServiceAccountEmail: string;
|
|
13
|
+
/** Optional RBAC rules — if provided, creates Role + RoleBinding. */
|
|
14
|
+
rbacRules?: Array<{
|
|
15
|
+
apiGroups: string[];
|
|
16
|
+
resources: string[];
|
|
17
|
+
verbs: string[];
|
|
18
|
+
}>;
|
|
19
|
+
/** Additional labels to apply to all resources. */
|
|
20
|
+
labels?: Record<string, string>;
|
|
21
|
+
/** Namespace for all resources. */
|
|
22
|
+
namespace?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface WorkloadIdentityServiceAccountResult {
|
|
26
|
+
serviceAccount: Record<string, unknown>;
|
|
27
|
+
role?: Record<string, unknown>;
|
|
28
|
+
roleBinding?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Create a WorkloadIdentityServiceAccount composite — returns prop objects for
|
|
33
|
+
* a ServiceAccount with GKE Workload Identity annotation, and optional Role + RoleBinding.
|
|
34
|
+
*
|
|
35
|
+
* @gke
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { WorkloadIdentityServiceAccount } from "@intentius/chant-lexicon-k8s";
|
|
39
|
+
*
|
|
40
|
+
* const { serviceAccount, role, roleBinding } = WorkloadIdentityServiceAccount({
|
|
41
|
+
* name: "app-sa",
|
|
42
|
+
* gcpServiceAccountEmail: "sa@my-project.iam.gserviceaccount.com",
|
|
43
|
+
* rbacRules: [
|
|
44
|
+
* { apiGroups: [""], resources: ["secrets"], verbs: ["get"] },
|
|
45
|
+
* ],
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function WorkloadIdentityServiceAccount(
|
|
50
|
+
props: WorkloadIdentityServiceAccountProps,
|
|
51
|
+
): WorkloadIdentityServiceAccountResult {
|
|
52
|
+
const {
|
|
53
|
+
name,
|
|
54
|
+
gcpServiceAccountEmail,
|
|
55
|
+
rbacRules,
|
|
56
|
+
labels: extraLabels = {},
|
|
57
|
+
namespace,
|
|
58
|
+
} = props;
|
|
59
|
+
|
|
60
|
+
const roleName = `${name}-role`;
|
|
61
|
+
const bindingName = `${name}-binding`;
|
|
62
|
+
|
|
63
|
+
const commonLabels: Record<string, string> = {
|
|
64
|
+
"app.kubernetes.io/name": name,
|
|
65
|
+
"app.kubernetes.io/managed-by": "chant",
|
|
66
|
+
...extraLabels,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const serviceAccountProps: Record<string, unknown> = {
|
|
70
|
+
metadata: {
|
|
71
|
+
name,
|
|
72
|
+
...(namespace && { namespace }),
|
|
73
|
+
labels: { ...commonLabels, "app.kubernetes.io/component": "service-account" },
|
|
74
|
+
annotations: {
|
|
75
|
+
"iam.gke.io/gcp-service-account": gcpServiceAccountEmail,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const result: WorkloadIdentityServiceAccountResult = {
|
|
81
|
+
serviceAccount: serviceAccountProps,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
if (rbacRules && rbacRules.length > 0) {
|
|
85
|
+
result.role = {
|
|
86
|
+
metadata: {
|
|
87
|
+
name: roleName,
|
|
88
|
+
...(namespace && { namespace }),
|
|
89
|
+
labels: { ...commonLabels, "app.kubernetes.io/component": "rbac" },
|
|
90
|
+
},
|
|
91
|
+
rules: rbacRules,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
result.roleBinding = {
|
|
95
|
+
metadata: {
|
|
96
|
+
name: bindingName,
|
|
97
|
+
...(namespace && { namespace }),
|
|
98
|
+
labels: { ...commonLabels, "app.kubernetes.io/component": "rbac" },
|
|
99
|
+
},
|
|
100
|
+
roleRef: {
|
|
101
|
+
apiGroup: "rbac.authorization.k8s.io",
|
|
102
|
+
kind: "Role",
|
|
103
|
+
name: roleName,
|
|
104
|
+
},
|
|
105
|
+
subjects: [
|
|
106
|
+
{
|
|
107
|
+
kind: "ServiceAccount",
|
|
108
|
+
name,
|
|
109
|
+
...(namespace && { namespace }),
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return result;
|
|
116
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -16,8 +16,30 @@ export { K8sLabels, K8sAnnotations } from "./variables";
|
|
|
16
16
|
export * from "./generated/index";
|
|
17
17
|
|
|
18
18
|
// Composites
|
|
19
|
-
export {
|
|
20
|
-
|
|
19
|
+
export {
|
|
20
|
+
WebApp, StatefulApp, CronWorkload, AutoscaledService, WorkerPool, NamespaceEnv, NodeAgent,
|
|
21
|
+
BatchJob, SecureIngress, ConfiguredApp, SidecarApp, MonitoredService, NetworkIsolatedApp,
|
|
22
|
+
IrsaServiceAccount, AlbIngress, EbsStorageClass, EfsStorageClass, FluentBitAgent, ExternalDnsAgent, AdotCollector,
|
|
23
|
+
MetricsServer, WorkloadIdentityServiceAccount, GcePdStorageClass, FilestoreStorageClass, GkeGateway, ConfigConnectorContext,
|
|
24
|
+
} from "./composites/index";
|
|
25
|
+
export type {
|
|
26
|
+
WebAppProps, WebAppResult, StatefulAppProps, StatefulAppResult, CronWorkloadProps, CronWorkloadResult,
|
|
27
|
+
AutoscaledServiceProps, AutoscaledServiceResult, WorkerPoolProps, WorkerPoolResult,
|
|
28
|
+
NamespaceEnvProps, NamespaceEnvResult, NodeAgentProps, NodeAgentResult,
|
|
29
|
+
BatchJobProps, BatchJobResult, SecureIngressProps, SecureIngressResult,
|
|
30
|
+
ConfiguredAppProps, ConfiguredAppResult, SidecarAppProps, SidecarAppResult,
|
|
31
|
+
MonitoredServiceProps, MonitoredServiceResult, NetworkIsolatedAppProps, NetworkIsolatedAppResult,
|
|
32
|
+
IrsaServiceAccountProps, IrsaServiceAccountResult, AlbIngressProps, AlbIngressResult,
|
|
33
|
+
EbsStorageClassProps, EbsStorageClassResult, EfsStorageClassProps, EfsStorageClassResult,
|
|
34
|
+
FluentBitAgentProps, FluentBitAgentResult, ExternalDnsAgentProps, ExternalDnsAgentResult,
|
|
35
|
+
AdotCollectorProps, AdotCollectorResult,
|
|
36
|
+
MetricsServerProps, MetricsServerResult,
|
|
37
|
+
WorkloadIdentityServiceAccountProps, WorkloadIdentityServiceAccountResult,
|
|
38
|
+
GcePdStorageClassProps, GcePdStorageClassResult,
|
|
39
|
+
FilestoreStorageClassProps, FilestoreStorageClassResult,
|
|
40
|
+
GkeGatewayProps, GkeGatewayResult,
|
|
41
|
+
ConfigConnectorContextProps, ConfigConnectorContextResult,
|
|
42
|
+
} from "./composites/index";
|
|
21
43
|
|
|
22
44
|
// RBAC verb constants
|
|
23
45
|
export * from "./actions/index";
|