@heynixie/pulumi-k8s 0.59.1 → 0.61.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 CHANGED
@@ -35,7 +35,8 @@ bun add @heynixie/pulumi-k8s
35
35
  - **nixie's pod.** One replica on a `ReadWriteOnce` claim, with the configuration, the encrypted
36
36
  secrets and a git-sync container that follows your definitions repo on GitHub.
37
37
  - **The web client.** A Deployment that rolls out after nixie and calls its API by the Service.
38
- - **The backup.** A CronJob that runs your backup script on nixie's volume, on your schedule.
38
+ - **The backup.** A CronJob that runs the release's backup image on nixie's staging folder, and
39
+ ships each snapshot set to your 2 restic repositories.
39
40
  - **Moving onto it.** Each resource keeps its own Pulumi name and an alias to the stack, so a stack
40
41
  that declared the same resources itself moves onto the component with no replacement.
41
42
 
@@ -0,0 +1,9 @@
1
+ import type { types } from '@pulumi/kubernetes';
2
+ import type { Input } from '@pulumi/pulumi';
3
+ export interface BackupJobPodInputs {
4
+ readonly image: Input<string>;
5
+ readonly claim: string;
6
+ readonly envSecret: string;
7
+ readonly pullSecret: Input<string>;
8
+ }
9
+ export declare function buildBackupJobPodSpec(inputs: BackupJobPodInputs): types.input.core.v1.PodSpec;
package/dist/index.js CHANGED
@@ -186,6 +186,63 @@ function buildNixieWebSpec(inputs) {
186
186
  import { apps, batch, core } from "@pulumi/kubernetes";
187
187
  import { ComponentResource, interpolate, rootStackResource, secret } from "@pulumi/pulumi";
188
188
 
189
+ // src/build-backup-job-pod-spec.ts
190
+ var stagingFolder = "backup";
191
+ function buildBackupJobPodSpec(inputs) {
192
+ return {
193
+ restartPolicy: "OnFailure",
194
+ securityContext: {
195
+ runAsNonRoot: true,
196
+ runAsUser: 10001,
197
+ runAsGroup: 10001,
198
+ fsGroup: 10001,
199
+ seccompProfile: { type: "RuntimeDefault" }
200
+ },
201
+ automountServiceAccountToken: false,
202
+ imagePullSecrets: [{ name: inputs.pullSecret }],
203
+ initContainers: [
204
+ {
205
+ name: "staging",
206
+ image: inputs.image,
207
+ command: ["mkdir", "-p", "-m", "0700", `/state/${stagingFolder}`],
208
+ volumeMounts: [{ name: "state", mountPath: "/state" }],
209
+ resources: { requests: { cpu: "10m", memory: "16Mi" }, limits: { memory: "32Mi" } },
210
+ securityContext: {
211
+ allowPrivilegeEscalation: false,
212
+ readOnlyRootFilesystem: true,
213
+ capabilities: { drop: ["ALL"] }
214
+ }
215
+ }
216
+ ],
217
+ containers: [
218
+ {
219
+ name: "backup",
220
+ image: inputs.image,
221
+ args: ["run"],
222
+ env: [
223
+ { name: "NIXIE_BACKUP_STAGING_DIR", value: "/backup" },
224
+ { name: "HOME", value: "/tmp" }
225
+ ],
226
+ envFrom: [{ secretRef: { name: inputs.envSecret } }],
227
+ volumeMounts: [
228
+ { name: "state", mountPath: "/backup", subPath: stagingFolder },
229
+ { name: "tmp", mountPath: "/tmp" }
230
+ ],
231
+ resources: { requests: { cpu: "50m", memory: "128Mi" }, limits: { memory: "512Mi" } },
232
+ securityContext: {
233
+ allowPrivilegeEscalation: false,
234
+ readOnlyRootFilesystem: true,
235
+ capabilities: { drop: ["ALL"] }
236
+ }
237
+ }
238
+ ],
239
+ volumes: [
240
+ { name: "state", persistentVolumeClaim: { claimName: inputs.claim } },
241
+ { name: "tmp", emptyDir: {} }
242
+ ]
243
+ };
244
+ }
245
+
189
246
  // src/build-backup-pod-spec.ts
190
247
  function buildBackupPodSpec(inputs) {
191
248
  return {
@@ -242,6 +299,20 @@ function buildServiceArgs(shape) {
242
299
  };
243
300
  }
244
301
 
302
+ // src/pick-backup-image.ts
303
+ function pickBackupImage(named, released) {
304
+ if (named !== undefined) {
305
+ return named;
306
+ }
307
+ if (released === null) {
308
+ throw new Error("this build of the component carries no nixie-backup image, so backup.image names one");
309
+ }
310
+ return released;
311
+ }
312
+
313
+ // src/release-backup-image.ts
314
+ var releaseBackupImage = "ghcr.io/zgeoff/nixie-backup:0.61.0@sha256:f9b75e25889193b348159af6305dd0218c13b81b05f88fc67e5dbc6592712262";
315
+
245
316
  // src/create-nixie.ts
246
317
  var rolloutTimeouts = { create: "30m", update: "30m" };
247
318
  function createNixie(name, args, opts = {}) {
@@ -323,38 +394,39 @@ function createWebDeployment(args, api, opts) {
323
394
  }
324
395
  var backupScriptConfigMap = "nixie-backup-script";
325
396
  var backupEnvSecret = "nixie-backup";
397
+ var dataClaim = "data-nixie-0";
326
398
  function createBackupJob(namespace, backup, statefulSet, opts) {
327
399
  const env = new core.v1.Secret("nixie-backup", {
328
400
  metadata: { name: backupEnvSecret, namespace },
329
401
  stringData: backup.environment
330
402
  }, opts);
331
- const script = new core.v1.ConfigMap("nixie-backup-script", {
403
+ const image = pickBackupImage(backup.image, releaseBackupImage);
404
+ const script = backup.script === undefined ? null : new core.v1.ConfigMap("nixie-backup-script", {
332
405
  metadata: { name: backupScriptConfigMap, namespace },
333
406
  data: { "backup.sh": backup.script }
334
407
  }, opts);
408
+ const podSpec = script === null ? buildBackupJobPodSpec({
409
+ image,
410
+ claim: dataClaim,
411
+ envSecret: backupEnvSecret,
412
+ pullSecret: backup.pullSecret
413
+ }) : buildBackupPodSpec({
414
+ image,
415
+ claim: dataClaim,
416
+ scriptConfigMap: backupScriptConfigMap,
417
+ envSecret: backupEnvSecret,
418
+ pullSecret: backup.pullSecret
419
+ });
335
420
  return new batch.v1.CronJob("nixie-backup", {
336
421
  metadata: { name: "nixie-backup", namespace },
337
422
  spec: {
338
- schedule: backup.schedule,
339
- timeZone: backup.timeZone,
423
+ schedule: backup.schedule ?? "*/5 * * * *",
424
+ timeZone: backup.timeZone ?? "Etc/UTC",
340
425
  suspend: false,
341
426
  concurrencyPolicy: "Forbid",
342
- jobTemplate: {
343
- spec: {
344
- backoffLimit: 2,
345
- template: {
346
- spec: buildBackupPodSpec({
347
- image: backup.image,
348
- claim: "data-nixie-0",
349
- scriptConfigMap: backupScriptConfigMap,
350
- envSecret: backupEnvSecret,
351
- pullSecret: backup.pullSecret
352
- })
353
- }
354
- }
355
- }
427
+ jobTemplate: { spec: { backoffLimit: 2, template: { spec: podSpec } } }
356
428
  }
357
- }, { ...opts, dependsOn: [env, script, statefulSet] });
429
+ }, { ...opts, dependsOn: script === null ? [env, statefulSet] : [env, script, statefulSet] });
358
430
  }
359
431
  export {
360
432
  createNixie,
@@ -0,0 +1,2 @@
1
+ import type { Input } from '@pulumi/pulumi';
2
+ export declare function pickBackupImage(named: Input<string> | undefined, released: string | null): Input<string>;
@@ -0,0 +1 @@
1
+ export declare const releaseBackupImage: string | null;
package/dist/types.d.ts CHANGED
@@ -14,11 +14,11 @@ export interface NixieWebArgs {
14
14
  readonly image: Input<string>;
15
15
  }
16
16
  export interface NixieBackupArgs {
17
- readonly image: Input<string>;
17
+ readonly image?: Input<string>;
18
18
  readonly pullSecret: Input<string>;
19
- readonly script: Input<string>;
20
- readonly schedule: Input<string>;
21
- readonly timeZone: Input<string>;
19
+ readonly script?: Input<string>;
20
+ readonly schedule?: Input<string>;
21
+ readonly timeZone?: Input<string>;
22
22
  readonly environment: Record<string, Input<string>>;
23
23
  }
24
24
  export interface NixieDefinitionsArgs {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heynixie/pulumi-k8s",
3
- "version": "0.59.1",
3
+ "version": "0.61.0",
4
4
  "description": "A Pulumi component that runs nixie on Kubernetes",
5
5
  "license": "MIT",
6
6
  "repository": {