@mrsimpson/homelab-core-components 0.2.4 → 0.2.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"app-namespace.d.ts","sourceRoot":"","sources":["../src/app-namespace.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,qBAAqB,CAAC;AACtD,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAClD,eAAO,MAAM,aAAa,oCAAoC,CAAC;AAC/D,eAAO,MAAM,UAAU;;;;CAA2E,CAAC;AAEnG;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,qBAAqB;;;EA+BnF"}
1
+ {"version":3,"file":"app-namespace.d.ts","sourceRoot":"","sources":["../src/app-namespace.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,qBAAqB,CAAC;AACtD,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAClD,eAAO,MAAM,aAAa,oCAAoC,CAAC;AAC/D,eAAO,MAAM,UAAU;;;;CAA2E,CAAC;AAEnG;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,qBAAqB;;;EAqCnF"}
@@ -72,7 +72,9 @@ function createAppNamespace(name, opts) {
72
72
  roleRef: { apiGroup: "rbac.authorization.k8s.io", kind: "ClusterRole", name: exports.DEPLOYER_ROLE },
73
73
  subjects: [exports.CI_SUBJECT],
74
74
  }, { ...opts, dependsOn: [created] });
75
- const namespace = k8s.core.v1.Namespace.get(`${name}-ns-ready`, binding.metadata.namespace, {
75
+ // The ID comes from binding.id, which is unknown until the RoleBinding really exists, so a
76
+ // preview of a first deploy does not try to read a namespace that is not there yet.
77
+ const namespace = k8s.core.v1.Namespace.get(`${name}-ns-ready`, binding.id.apply(() => name), {
76
78
  ...opts,
77
79
  dependsOn: [binding],
78
80
  });
@@ -1 +1 @@
1
- {"version":3,"file":"app-namespace.js","sourceRoot":"","sources":["../src/app-namespace.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,gDA+BC;AArDD,wDAA0C;AAG1C;;;;GAIG;AACU,QAAA,mBAAmB,GAAG,kBAAkB,CAAC;AACzC,QAAA,mBAAmB,GAAG,cAAc,CAAC;AACrC,QAAA,aAAa,GAAG,iCAAiC,CAAC;AAClD,QAAA,UAAU,GAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AAEnG;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAAC,IAAY,EAAE,IAAmC;IAClF,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CACvC,GAAG,IAAI,KAAK,EACZ;QACE,QAAQ,EAAE;YACR,IAAI;YACJ,MAAM,EAAE;gBACN,CAAC,2BAAmB,CAAC,EAAE,2BAAmB;gBAC1C,wBAAwB,EAAE,IAAI;gBAC9B,oCAAoC,EAAE,YAAY;gBAClD,kCAAkC,EAAE,YAAY;gBAChD,iCAAiC,EAAE,YAAY;aAChD;SACF;KACF,EACD,IAAI,CACL,CAAC;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CACzC,GAAG,IAAI,WAAW,EAClB;QACE,QAAQ,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,SAAS,EAAE,IAAI,EAAE;QAC5D,OAAO,EAAE,EAAE,QAAQ,EAAE,2BAA2B,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI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O,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CACzC,GAAG,IAAI,WAAW,EAClB;QACE,QAAQ,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,SAAS,EAAE,IAAI,EAAE;QAC5D,OAAO,EAAE,EAAE,QAAQ,EAAE,2BAA2B,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,qBAAa,EAAE;QAC5F,QAAQ,EAAE,CAAC,kBAAU,CAAC;KACvB,EACD,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,CAClC,CAAC;IACF,2FAA2F;IAC3F,oFAAoF;IACpF,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CACzC,GAAG,IAAI,WAAW,EAClB,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAC5B;QACE,GAAG,IAAI;QACP,SAAS,EAAE,CAAC,OAAO,CAAC;KACrB,CACF,CAAC;IACF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AAChC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrsimpson/homelab-core-components",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Reusable Pulumi components for secure homelab infrastructure",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,32 @@
1
+ import * as pulumi from "@pulumi/pulumi";
2
+ import { beforeAll, describe, expect, it } from "vitest";
3
+
4
+ // Preview of a first deploy: nothing exists yet. The namespace reference must not be read with
5
+ // a known ID (a read of a namespace that does not exist fails the whole preview). With an
6
+ // unknown ID the engine skips the read in a preview.
7
+ const reads: string[] = [];
8
+
9
+ beforeAll(async () => {
10
+ pulumi.runtime.setMocks(
11
+ {
12
+ newResource: (args) => {
13
+ if (args.id && args.id !== pulumi.runtime.unknownValue) reads.push(args.name);
14
+ // In a preview, resources to be created have no ID yet.
15
+ return { id: args.id ?? "", state: args.inputs };
16
+ },
17
+ call: (args) => args.inputs,
18
+ },
19
+ "app",
20
+ "test",
21
+ true
22
+ );
23
+ const { createAppNamespace } = await import("./app-namespace");
24
+ createAppNamespace("gitea");
25
+ await new Promise((r) => setTimeout(r, 50));
26
+ });
27
+
28
+ describe("createAppNamespace in a preview", () => {
29
+ it("does not read the namespace before the RoleBinding exists", () => {
30
+ expect(reads).toEqual([]);
31
+ });
32
+ });
@@ -46,9 +46,15 @@ export function createAppNamespace(name: string, opts?: pulumi.CustomResourceOpt
46
46
  },
47
47
  { ...opts, dependsOn: [created] }
48
48
  );
49
- const namespace = k8s.core.v1.Namespace.get(`${name}-ns-ready`, binding.metadata.namespace, {
50
- ...opts,
51
- dependsOn: [binding],
52
- });
49
+ // The ID comes from binding.id, which is unknown until the RoleBinding really exists, so a
50
+ // preview of a first deploy does not try to read a namespace that is not there yet.
51
+ const namespace = k8s.core.v1.Namespace.get(
52
+ `${name}-ns-ready`,
53
+ binding.id.apply(() => name),
54
+ {
55
+ ...opts,
56
+ dependsOn: [binding],
57
+ }
58
+ );
53
59
  return { namespace, binding };
54
60
  }