@mrsimpson/homelab-core-components 0.2.3 → 0.2.4
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/app-namespace.d.ts
CHANGED
|
@@ -14,7 +14,12 @@ export declare const CI_SUBJECT: {
|
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Creates an app's namespace (pod-security restricted, owned by the CI) and grants the CI
|
|
17
|
-
* its deployer rights there.
|
|
17
|
+
* its deployer rights there.
|
|
18
|
+
*
|
|
19
|
+
* Use the returned `namespace` for everything else the app creates (e.g. ExposedWebApp's
|
|
20
|
+
* `namespace`, `dependsOn: [namespace]`). It is a reference that resolves only after the
|
|
21
|
+
* RoleBinding exists, so no resource is sent to the cluster before the CI may create it.
|
|
22
|
+
* (`dependsOn` on a component does not reach its children; a data dependency does.)
|
|
18
23
|
*/
|
|
19
24
|
export declare function createAppNamespace(name: string, opts?: pulumi.CustomResourceOptions): {
|
|
20
25
|
namespace: import("@pulumi/kubernetes/core/v1/namespace").Namespace;
|
|
@@ -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
|
|
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"}
|
package/dist/app-namespace.js
CHANGED
|
@@ -47,10 +47,15 @@ exports.DEPLOYER_ROLE = "ci-access:homelab-apps:deployer";
|
|
|
47
47
|
exports.CI_SUBJECT = { kind: "ServiceAccount", name: "homelab-apps", namespace: "ci-access" };
|
|
48
48
|
/**
|
|
49
49
|
* Creates an app's namespace (pod-security restricted, owned by the CI) and grants the CI
|
|
50
|
-
* its deployer rights there.
|
|
50
|
+
* its deployer rights there.
|
|
51
|
+
*
|
|
52
|
+
* Use the returned `namespace` for everything else the app creates (e.g. ExposedWebApp's
|
|
53
|
+
* `namespace`, `dependsOn: [namespace]`). It is a reference that resolves only after the
|
|
54
|
+
* RoleBinding exists, so no resource is sent to the cluster before the CI may create it.
|
|
55
|
+
* (`dependsOn` on a component does not reach its children; a data dependency does.)
|
|
51
56
|
*/
|
|
52
57
|
function createAppNamespace(name, opts) {
|
|
53
|
-
const
|
|
58
|
+
const created = new k8s.core.v1.Namespace(`${name}-ns`, {
|
|
54
59
|
metadata: {
|
|
55
60
|
name,
|
|
56
61
|
labels: {
|
|
@@ -66,7 +71,11 @@ function createAppNamespace(name, opts) {
|
|
|
66
71
|
metadata: { name: "homelab-apps:deployer", namespace: name },
|
|
67
72
|
roleRef: { apiGroup: "rbac.authorization.k8s.io", kind: "ClusterRole", name: exports.DEPLOYER_ROLE },
|
|
68
73
|
subjects: [exports.CI_SUBJECT],
|
|
69
|
-
}, { ...opts, dependsOn: [
|
|
74
|
+
}, { ...opts, dependsOn: [created] });
|
|
75
|
+
const namespace = k8s.core.v1.Namespace.get(`${name}-ns-ready`, binding.metadata.namespace, {
|
|
76
|
+
...opts,
|
|
77
|
+
dependsOn: [binding],
|
|
78
|
+
});
|
|
70
79
|
return { namespace, binding };
|
|
71
80
|
}
|
|
72
81
|
//# sourceMappingURL=app-namespace.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-namespace.js","sourceRoot":"","sources":["../src/app-namespace.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
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,EAAE,qBAAa,EAAE;QAC5F,QAAQ,EAAE,CAAC,kBAAU,CAAC;KACvB,EACD,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,CAClC,CAAC;IACF,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE;QAC1F,GAAG,IAAI;QACP,SAAS,EAAE,CAAC,OAAO,CAAC;KACrB,CAAC,CAAC;IACH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import * as pulumi from "@pulumi/pulumi";
|
|
2
2
|
import { beforeAll, describe, expect, it } from "vitest";
|
|
3
3
|
|
|
4
|
-
const created: Array<{
|
|
4
|
+
const created: Array<{
|
|
5
|
+
type: string;
|
|
6
|
+
name: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
inputs: Record<string, unknown>;
|
|
9
|
+
}> = [];
|
|
10
|
+
let result: { namespace: pulumi.Resource } | undefined;
|
|
5
11
|
|
|
6
12
|
beforeAll(async () => {
|
|
7
13
|
pulumi.runtime.setMocks(
|
|
8
14
|
{
|
|
9
15
|
newResource: (args) => {
|
|
10
|
-
created.push({ type: args.type, name: args.name, inputs: args.inputs });
|
|
16
|
+
created.push({ type: args.type, name: args.name, id: args.id, inputs: args.inputs });
|
|
11
17
|
return { id: `${args.name}-id`, state: args.inputs };
|
|
12
18
|
},
|
|
13
19
|
call: (args) => args.inputs,
|
|
@@ -17,11 +23,11 @@ beforeAll(async () => {
|
|
|
17
23
|
false
|
|
18
24
|
);
|
|
19
25
|
const { createAppNamespace } = await import("./app-namespace");
|
|
20
|
-
createAppNamespace("gitea");
|
|
26
|
+
result = createAppNamespace("gitea");
|
|
21
27
|
await new Promise((r) => setTimeout(r, 50));
|
|
22
28
|
});
|
|
23
29
|
|
|
24
|
-
const of = (type: string) => created.find((c) => c.type === type);
|
|
30
|
+
const of = (type: string) => created.find((c) => c.type === type && !c.id);
|
|
25
31
|
|
|
26
32
|
describe("createAppNamespace", () => {
|
|
27
33
|
it("creates the namespace owned by the CI, pod-security restricted", () => {
|
|
@@ -51,4 +57,18 @@ describe("createAppNamespace", () => {
|
|
|
51
57
|
{ kind: "ServiceAccount", name: "homelab-apps", namespace: "ci-access" },
|
|
52
58
|
]);
|
|
53
59
|
});
|
|
60
|
+
|
|
61
|
+
it("hands out the namespace only once the CI may deploy into it", async () => {
|
|
62
|
+
// Pulumi does not pass a component's dependsOn on to its children, so an app's resources
|
|
63
|
+
// must reach the namespace through something that waits for the RoleBinding.
|
|
64
|
+
const read = created.findIndex((c) => c.type === "kubernetes:core/v1:Namespace" && c.id);
|
|
65
|
+
const binding = created.findIndex(
|
|
66
|
+
(c) => c.type === "kubernetes:rbac.authorization.k8s.io/v1:RoleBinding"
|
|
67
|
+
);
|
|
68
|
+
expect(binding).toBeGreaterThanOrEqual(0);
|
|
69
|
+
expect(read).toBeGreaterThan(binding);
|
|
70
|
+
expect(created[read].id).toBe("gitea");
|
|
71
|
+
const urn = await new Promise((r) => (result?.namespace.urn as pulumi.Output<string>).apply(r));
|
|
72
|
+
expect(urn).toContain("gitea-ns-ready");
|
|
73
|
+
});
|
|
54
74
|
});
|
package/src/app-namespace.ts
CHANGED
|
@@ -13,10 +13,15 @@ export const CI_SUBJECT = { kind: "ServiceAccount", name: "homelab-apps", namesp
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Creates an app's namespace (pod-security restricted, owned by the CI) and grants the CI
|
|
16
|
-
* its deployer rights there.
|
|
16
|
+
* its deployer rights there.
|
|
17
|
+
*
|
|
18
|
+
* Use the returned `namespace` for everything else the app creates (e.g. ExposedWebApp's
|
|
19
|
+
* `namespace`, `dependsOn: [namespace]`). It is a reference that resolves only after the
|
|
20
|
+
* RoleBinding exists, so no resource is sent to the cluster before the CI may create it.
|
|
21
|
+
* (`dependsOn` on a component does not reach its children; a data dependency does.)
|
|
17
22
|
*/
|
|
18
23
|
export function createAppNamespace(name: string, opts?: pulumi.CustomResourceOptions) {
|
|
19
|
-
const
|
|
24
|
+
const created = new k8s.core.v1.Namespace(
|
|
20
25
|
`${name}-ns`,
|
|
21
26
|
{
|
|
22
27
|
metadata: {
|
|
@@ -39,7 +44,11 @@ export function createAppNamespace(name: string, opts?: pulumi.CustomResourceOpt
|
|
|
39
44
|
roleRef: { apiGroup: "rbac.authorization.k8s.io", kind: "ClusterRole", name: DEPLOYER_ROLE },
|
|
40
45
|
subjects: [CI_SUBJECT],
|
|
41
46
|
},
|
|
42
|
-
{ ...opts, dependsOn: [
|
|
47
|
+
{ ...opts, dependsOn: [created] }
|
|
43
48
|
);
|
|
49
|
+
const namespace = k8s.core.v1.Namespace.get(`${name}-ns-ready`, binding.metadata.namespace, {
|
|
50
|
+
...opts,
|
|
51
|
+
dependsOn: [binding],
|
|
52
|
+
});
|
|
44
53
|
return { namespace, binding };
|
|
45
54
|
}
|