@ankhorage/kubernetes 0.1.0 → 0.2.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 +6 -6
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesController.d.ts +13 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesController.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesController.js +130 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesController.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesExposure.d.ts +12 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesExposure.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesExposure.js +89 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesExposure.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesPrerequisites.d.ts +18 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesPrerequisites.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesPrerequisites.js +98 -0
- package/dist/features/workload-reconciliation/application/use-cases/createKubernetesPrerequisites.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/getKubernetesOutputsAsync.d.ts +5 -0
- package/dist/features/workload-reconciliation/application/use-cases/getKubernetesOutputsAsync.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/getKubernetesOutputsAsync.js +33 -0
- package/dist/features/workload-reconciliation/application/use-cases/getKubernetesOutputsAsync.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/getKubernetesStatusAsync.d.ts +5 -0
- package/dist/features/workload-reconciliation/application/use-cases/getKubernetesStatusAsync.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/getKubernetesStatusAsync.js +35 -0
- package/dist/features/workload-reconciliation/application/use-cases/getKubernetesStatusAsync.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/materializeKubernetesSecretsAsync.d.ts +6 -0
- package/dist/features/workload-reconciliation/application/use-cases/materializeKubernetesSecretsAsync.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/materializeKubernetesSecretsAsync.js +32 -0
- package/dist/features/workload-reconciliation/application/use-cases/materializeKubernetesSecretsAsync.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/planKubernetesResourcesAsync.d.ts +5 -0
- package/dist/features/workload-reconciliation/application/use-cases/planKubernetesResourcesAsync.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/planKubernetesResourcesAsync.js +9 -0
- package/dist/features/workload-reconciliation/application/use-cases/planKubernetesResourcesAsync.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/prepareKubernetesChangesAsync.d.ts +6 -0
- package/dist/features/workload-reconciliation/application/use-cases/prepareKubernetesChangesAsync.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/prepareKubernetesChangesAsync.js +84 -0
- package/dist/features/workload-reconciliation/application/use-cases/prepareKubernetesChangesAsync.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/projectKubernetesResourcesAsync.d.ts +11 -0
- package/dist/features/workload-reconciliation/application/use-cases/projectKubernetesResourcesAsync.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/projectKubernetesResourcesAsync.js +53 -0
- package/dist/features/workload-reconciliation/application/use-cases/projectKubernetesResourcesAsync.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/projectKubernetesWorkload.d.ts +12 -0
- package/dist/features/workload-reconciliation/application/use-cases/projectKubernetesWorkload.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/projectKubernetesWorkload.js +45 -0
- package/dist/features/workload-reconciliation/application/use-cases/projectKubernetesWorkload.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/reconcileKubernetesResourcesAsync.d.ts +5 -0
- package/dist/features/workload-reconciliation/application/use-cases/reconcileKubernetesResourcesAsync.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/reconcileKubernetesResourcesAsync.js +51 -0
- package/dist/features/workload-reconciliation/application/use-cases/reconcileKubernetesResourcesAsync.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/removeKubernetesResourcesAsync.d.ts +5 -0
- package/dist/features/workload-reconciliation/application/use-cases/removeKubernetesResourcesAsync.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/removeKubernetesResourcesAsync.js +75 -0
- package/dist/features/workload-reconciliation/application/use-cases/removeKubernetesResourcesAsync.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/resolveKubernetesWorkloadValues.d.ts +5 -0
- package/dist/features/workload-reconciliation/application/use-cases/resolveKubernetesWorkloadValues.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/resolveKubernetesWorkloadValues.js +45 -0
- package/dist/features/workload-reconciliation/application/use-cases/resolveKubernetesWorkloadValues.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/validateKubernetesWorkloads.d.ts +4 -0
- package/dist/features/workload-reconciliation/application/use-cases/validateKubernetesWorkloads.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/validateKubernetesWorkloads.js +26 -0
- package/dist/features/workload-reconciliation/application/use-cases/validateKubernetesWorkloads.js.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/waitForKubernetesReadinessAsync.d.ts +5 -0
- package/dist/features/workload-reconciliation/application/use-cases/waitForKubernetesReadinessAsync.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/application/use-cases/waitForKubernetesReadinessAsync.js +56 -0
- package/dist/features/workload-reconciliation/application/use-cases/waitForKubernetesReadinessAsync.js.map +1 -0
- package/dist/features/workload-reconciliation/composition/createKubernetesDriver.d.ts +4 -4
- package/dist/features/workload-reconciliation/composition/createKubernetesDriver.d.ts.map +1 -1
- package/dist/features/workload-reconciliation/composition/createKubernetesDriver.js +20 -4
- package/dist/features/workload-reconciliation/composition/createKubernetesDriver.js.map +1 -1
- package/dist/features/workload-reconciliation/constants.d.ts +14 -0
- package/dist/features/workload-reconciliation/constants.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/constants.js +14 -0
- package/dist/features/workload-reconciliation/constants.js.map +1 -0
- package/dist/features/workload-reconciliation/utils/areKubernetesResourcesEquivalent.d.ts +4 -0
- package/dist/features/workload-reconciliation/utils/areKubernetesResourcesEquivalent.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/utils/areKubernetesResourcesEquivalent.js +41 -0
- package/dist/features/workload-reconciliation/utils/areKubernetesResourcesEquivalent.js.map +1 -0
- package/dist/features/workload-reconciliation/utils/createKubernetesDesiredResource.d.ts +14 -0
- package/dist/features/workload-reconciliation/utils/createKubernetesDesiredResource.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/utils/createKubernetesDesiredResource.js +45 -0
- package/dist/features/workload-reconciliation/utils/createKubernetesDesiredResource.js.map +1 -0
- package/dist/features/workload-reconciliation/utils/createKubernetesIdentity.d.ts +5 -0
- package/dist/features/workload-reconciliation/utils/createKubernetesIdentity.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/utils/createKubernetesIdentity.js +10 -0
- package/dist/features/workload-reconciliation/utils/createKubernetesIdentity.js.map +1 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesOwnershipQuery.d.ts +5 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesOwnershipQuery.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesOwnershipQuery.js +16 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesOwnershipQuery.js.map +1 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesResourceKey.d.ts +4 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesResourceKey.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesResourceKey.js +5 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesResourceKey.js.map +1 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesResourceReference.d.ts +4 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesResourceReference.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesResourceReference.js +12 -0
- package/dist/features/workload-reconciliation/utils/getKubernetesResourceReference.js.map +1 -0
- package/dist/features/workload-reconciliation/utils/readKubernetesOwnedResource.d.ts +6 -0
- package/dist/features/workload-reconciliation/utils/readKubernetesOwnedResource.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/utils/readKubernetesOwnedResource.js +49 -0
- package/dist/features/workload-reconciliation/utils/readKubernetesOwnedResource.js.map +1 -0
- package/dist/features/workload-reconciliation/utils/sortKubernetesResourcesForRemoval.d.ts +9 -0
- package/dist/features/workload-reconciliation/utils/sortKubernetesResourcesForRemoval.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/utils/sortKubernetesResourcesForRemoval.js +21 -0
- package/dist/features/workload-reconciliation/utils/sortKubernetesResourcesForRemoval.js.map +1 -0
- package/dist/features/workload-reconciliation/utils/toKubernetesName.d.ts +3 -0
- package/dist/features/workload-reconciliation/utils/toKubernetesName.d.ts.map +1 -0
- package/dist/features/workload-reconciliation/utils/toKubernetesName.js +21 -0
- package/dist/features/workload-reconciliation/utils/toKubernetesName.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/kubernetesDriver.d.ts +21 -1
- package/dist/types/kubernetesDriver.d.ts.map +1 -1
- package/dist/types/kubernetesDriver.js.map +1 -1
- package/dist/types/kubernetesResources.d.ts +87 -0
- package/dist/types/kubernetesResources.d.ts.map +1 -0
- package/dist/types/kubernetesResources.js +2 -0
- package/dist/types/kubernetesResources.js.map +1 -0
- package/package.json +1 -1
package/dist/features/workload-reconciliation/application/use-cases/validateKubernetesWorkloads.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*** Validate portable invariants required for deterministic Kubernetes projection. */
|
|
2
|
+
export function validateKubernetesWorkloads(workloads) {
|
|
3
|
+
const diagnostics = [];
|
|
4
|
+
const ids = new Set();
|
|
5
|
+
for (const workload of workloads) {
|
|
6
|
+
if (ids.has(workload.id)) {
|
|
7
|
+
diagnostics.push({
|
|
8
|
+
severity: 'error',
|
|
9
|
+
code: 'kubernetes-workload-duplicate',
|
|
10
|
+
message: `Workload ID ${workload.id} is duplicated.`,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
ids.add(workload.id);
|
|
14
|
+
for (const dependency of workload.dependsOn ?? []) {
|
|
15
|
+
if (!workloads.some((candidate) => candidate.id === dependency)) {
|
|
16
|
+
diagnostics.push({
|
|
17
|
+
severity: 'error',
|
|
18
|
+
code: 'kubernetes-workload-dependency-missing',
|
|
19
|
+
message: `Workload ${workload.id} depends on missing workload ${dependency}.`,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return diagnostics;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=validateKubernetesWorkloads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateKubernetesWorkloads.js","sourceRoot":"","sources":["../../../../../src/features/workload-reconciliation/application/use-cases/validateKubernetesWorkloads.ts"],"names":[],"mappings":"AAEA,sFAAsF;AACtF,MAAM,UAAU,2BAA2B,CACzC,SAAuC;IAEvC,MAAM,WAAW,GAAsB,EAAE,CAAC;IAC1C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YACzB,WAAW,CAAC,IAAI,CAAC;gBACf,QAAQ,EAAE,OAAO;gBACjB,IAAI,EAAE,+BAA+B;gBACrC,OAAO,EAAE,eAAe,QAAQ,CAAC,EAAE,iBAAiB;aACrD,CAAC,CAAC;QACL,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACrB,KAAK,MAAM,UAAU,IAAI,QAAQ,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC;YAClD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,UAAU,CAAC,EAAE,CAAC;gBAChE,WAAW,CAAC,IAAI,CAAC;oBACf,QAAQ,EAAE,OAAO;oBACjB,IAAI,EAAE,wCAAwC;oBAC9C,OAAO,EAAE,YAAY,QAAQ,CAAC,EAAE,gCAAgC,UAAU,GAAG;iBAC9E,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import type { InfraDiagnostic, InfraWorkloadSpec } from '@ankhorage/contracts/infra';\n\n/*** Validate portable invariants required for deterministic Kubernetes projection. */\nexport function validateKubernetesWorkloads(\n workloads: readonly InfraWorkloadSpec[],\n): readonly InfraDiagnostic[] {\n const diagnostics: InfraDiagnostic[] = [];\n const ids = new Set<string>();\n for (const workload of workloads) {\n if (ids.has(workload.id)) {\n diagnostics.push({\n severity: 'error',\n code: 'kubernetes-workload-duplicate',\n message: `Workload ID ${workload.id} is duplicated.`,\n });\n }\n ids.add(workload.id);\n for (const dependency of workload.dependsOn ?? []) {\n if (!workloads.some((candidate) => candidate.id === dependency)) {\n diagnostics.push({\n severity: 'error',\n code: 'kubernetes-workload-dependency-missing',\n message: `Workload ${workload.id} depends on missing workload ${dependency}.`,\n });\n }\n }\n }\n return diagnostics;\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { InfraResourceStatus, InfraResult } from '@ankhorage/contracts/infra';
|
|
2
|
+
import type { KubernetesDriverOptions, KubernetesDriverRequest } from '../../../../types/kubernetesDriver';
|
|
3
|
+
/*** Wait dependency-first for required Kubernetes resources to report ready. */
|
|
4
|
+
export declare function waitForKubernetesReadinessAsync(options: KubernetesDriverOptions, request: KubernetesDriverRequest): Promise<InfraResult<readonly InfraResourceStatus[]>>;
|
|
5
|
+
//# sourceMappingURL=waitForKubernetesReadinessAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waitForKubernetesReadinessAsync.d.ts","sourceRoot":"","sources":["../../../../../src/features/workload-reconciliation/application/use-cases/waitForKubernetesReadinessAsync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,mBAAmB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEpG,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,oCAAoC,CAAC;AAY5C,gFAAgF;AAChF,wBAAsB,+BAA+B,CACnD,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,WAAW,CAAC,SAAS,mBAAmB,EAAE,CAAC,CAAC,CA6CtD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getKubernetesResourceReference } from '../../utils/getKubernetesResourceReference';
|
|
2
|
+
import { projectKubernetesResourcesAsync } from './projectKubernetesResourcesAsync';
|
|
3
|
+
const READINESS_KINDS = new Set([
|
|
4
|
+
'Namespace',
|
|
5
|
+
'PersistentVolumeClaim',
|
|
6
|
+
'Deployment',
|
|
7
|
+
'Service',
|
|
8
|
+
'Ingress',
|
|
9
|
+
]);
|
|
10
|
+
/*** Wait dependency-first for required Kubernetes resources to report ready. */
|
|
11
|
+
export async function waitForKubernetesReadinessAsync(options, request) {
|
|
12
|
+
const projection = await projectKubernetesResourcesAsync(request);
|
|
13
|
+
if (!projection.ok)
|
|
14
|
+
return projection;
|
|
15
|
+
try {
|
|
16
|
+
const statuses = [];
|
|
17
|
+
const diagnostics = [];
|
|
18
|
+
for (const desired of projection.value.resources) {
|
|
19
|
+
if (!READINESS_KINDS.has(desired.resource.kind))
|
|
20
|
+
continue;
|
|
21
|
+
const observation = await options.api.waitUntilReadyAsync(getKubernetesResourceReference(desired.resource), {
|
|
22
|
+
timeoutSeconds: options.defaultReadinessTimeoutSeconds ?? 300,
|
|
23
|
+
...(request.context.signal === undefined ? {} : { signal: request.context.signal }),
|
|
24
|
+
});
|
|
25
|
+
statuses.push({
|
|
26
|
+
owner: desired.owner.identity,
|
|
27
|
+
state: observation.state,
|
|
28
|
+
...(observation.detail === undefined ? {} : { detail: observation.detail }),
|
|
29
|
+
});
|
|
30
|
+
if (observation.state !== 'ready') {
|
|
31
|
+
diagnostics.push({
|
|
32
|
+
severity: 'error',
|
|
33
|
+
code: 'kubernetes-readiness-failed',
|
|
34
|
+
message: `Kubernetes resource ${desired.owner.identity.resourceId} is ${observation.state}.`,
|
|
35
|
+
owner: desired.owner.identity,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return diagnostics.length > 0
|
|
40
|
+
? { ok: false, diagnostics }
|
|
41
|
+
: { ok: true, value: statuses, diagnostics: [] };
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return {
|
|
45
|
+
ok: false,
|
|
46
|
+
diagnostics: [
|
|
47
|
+
{
|
|
48
|
+
severity: 'error',
|
|
49
|
+
code: 'kubernetes-readiness-failed',
|
|
50
|
+
message: 'Kubernetes readiness could not be established.',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=waitForKubernetesReadinessAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waitForKubernetesReadinessAsync.js","sourceRoot":"","sources":["../../../../../src/features/workload-reconciliation/application/use-cases/waitForKubernetesReadinessAsync.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AAEpF,MAAM,eAAe,GAAG,IAAI,GAAG,CAA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AAW,CAAC,IAAI,CAAC;oBACf,QAAQ,EAAE,OAAO;oBACjB,IAAI,EAAE,6BAA6B;oBACnC,OAAO,EAAE,uBAAuB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,OAAO,WAAW,CAAC,KAAK,GAAG;oBAC5F,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ;iBAC9B,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC;YAC3B,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE;YAC5B,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;YACL,EAAE,EAAE,KAAK;YACT,WAAW,EAAE;gBACX;oBACE,QAAQ,EAAE,OAAO;oBACjB,IAAI,EAAE,6BAA6B;oBACnC,OAAO,EAAE,gDAAgD;iBAC1D;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type { InfraDiagnostic, InfraResourceStatus, InfraResult } from '@ankhorage/contracts/infra';\n\nimport type {\n KubernetesDriverOptions,\n KubernetesDriverRequest,\n} from '../../../../types/kubernetesDriver';\nimport { getKubernetesResourceReference } from '../../utils/getKubernetesResourceReference';\nimport { projectKubernetesResourcesAsync } from './projectKubernetesResourcesAsync';\n\nconst READINESS_KINDS = new Set([\n 'Namespace',\n 'PersistentVolumeClaim',\n 'Deployment',\n 'Service',\n 'Ingress',\n]);\n\n/*** Wait dependency-first for required Kubernetes resources to report ready. */\nexport async function waitForKubernetesReadinessAsync(\n options: KubernetesDriverOptions,\n request: KubernetesDriverRequest,\n): Promise<InfraResult<readonly InfraResourceStatus[]>> {\n const projection = await projectKubernetesResourcesAsync(request);\n if (!projection.ok) return projection;\n\n try {\n const statuses: InfraResourceStatus[] = [];\n const diagnostics: InfraDiagnostic[] = [];\n for (const desired of projection.value.resources) {\n if (!READINESS_KINDS.has(desired.resource.kind)) continue;\n const observation = await options.api.waitUntilReadyAsync(\n getKubernetesResourceReference(desired.resource),\n {\n timeoutSeconds: options.defaultReadinessTimeoutSeconds ?? 300,\n ...(request.context.signal === undefined ? {} : { signal: request.context.signal }),\n },\n );\n statuses.push({\n owner: desired.owner.identity,\n state: observation.state,\n ...(observation.detail === undefined ? {} : { detail: observation.detail }),\n });\n if (observation.state !== 'ready') {\n diagnostics.push({\n severity: 'error',\n code: 'kubernetes-readiness-failed',\n message: `Kubernetes resource ${desired.owner.identity.resourceId} is ${observation.state}.`,\n owner: desired.owner.identity,\n });\n }\n }\n return diagnostics.length > 0\n ? { ok: false, diagnostics }\n : { ok: true, value: statuses, diagnostics: [] };\n } catch {\n return {\n ok: false,\n diagnostics: [\n {\n severity: 'error',\n code: 'kubernetes-readiness-failed',\n message: 'Kubernetes readiness could not be established.',\n },\n ],\n };\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { KubernetesDriver } from '../../../types/kubernetesDriver';
|
|
1
|
+
import type { KubernetesDriver, KubernetesDriverOptions } from '../../../types/kubernetesDriver';
|
|
2
2
|
/***
|
|
3
3
|
* Create the shared Kubernetes workload driver entrypoint.
|
|
4
4
|
*
|
|
5
5
|
* Kubernetes is an implementation dependency for runtime adapters, not a selectable Infra
|
|
6
|
-
* provider.
|
|
7
|
-
*
|
|
6
|
+
* provider. The supplied API port is already authenticated cluster access; the driver adds only
|
|
7
|
+
* standard Kubernetes workload projection and lifecycle semantics.
|
|
8
8
|
*
|
|
9
9
|
* @readme
|
|
10
10
|
*/
|
|
11
|
-
export declare function createKubernetesDriver(): KubernetesDriver;
|
|
11
|
+
export declare function createKubernetesDriver(options: KubernetesDriverOptions): KubernetesDriver;
|
|
12
12
|
//# sourceMappingURL=createKubernetesDriver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createKubernetesDriver.d.ts","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/composition/createKubernetesDriver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"createKubernetesDriver.d.ts","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/composition/createKubernetesDriver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AASjG;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB,CAWzF"}
|
|
@@ -1,13 +1,29 @@
|
|
|
1
|
+
import { getKubernetesOutputsAsync } from '../application/use-cases/getKubernetesOutputsAsync';
|
|
2
|
+
import { getKubernetesStatusAsync } from '../application/use-cases/getKubernetesStatusAsync';
|
|
3
|
+
import { planKubernetesResourcesAsync } from '../application/use-cases/planKubernetesResourcesAsync';
|
|
4
|
+
import { projectKubernetesResourcesAsync } from '../application/use-cases/projectKubernetesResourcesAsync';
|
|
5
|
+
import { reconcileKubernetesResourcesAsync } from '../application/use-cases/reconcileKubernetesResourcesAsync';
|
|
6
|
+
import { removeKubernetesResourcesAsync } from '../application/use-cases/removeKubernetesResourcesAsync';
|
|
7
|
+
import { waitForKubernetesReadinessAsync } from '../application/use-cases/waitForKubernetesReadinessAsync';
|
|
1
8
|
/***
|
|
2
9
|
* Create the shared Kubernetes workload driver entrypoint.
|
|
3
10
|
*
|
|
4
11
|
* Kubernetes is an implementation dependency for runtime adapters, not a selectable Infra
|
|
5
|
-
* provider.
|
|
6
|
-
*
|
|
12
|
+
* provider. The supplied API port is already authenticated cluster access; the driver adds only
|
|
13
|
+
* standard Kubernetes workload projection and lifecycle semantics.
|
|
7
14
|
*
|
|
8
15
|
* @readme
|
|
9
16
|
*/
|
|
10
|
-
export function createKubernetesDriver() {
|
|
11
|
-
return {
|
|
17
|
+
export function createKubernetesDriver(options) {
|
|
18
|
+
return {
|
|
19
|
+
kind: 'kubernetes',
|
|
20
|
+
projectAsync: projectKubernetesResourcesAsync,
|
|
21
|
+
planAsync: (request) => planKubernetesResourcesAsync(options, request),
|
|
22
|
+
reconcileAsync: (request) => reconcileKubernetesResourcesAsync(options, request),
|
|
23
|
+
removeAsync: (request, destroy) => removeKubernetesResourcesAsync(options, request, destroy),
|
|
24
|
+
statusAsync: (request) => getKubernetesStatusAsync(options, request),
|
|
25
|
+
waitUntilReadyAsync: (request) => waitForKubernetesReadinessAsync(options, request),
|
|
26
|
+
outputsAsync: (request) => getKubernetesOutputsAsync(options, request),
|
|
27
|
+
};
|
|
12
28
|
}
|
|
13
29
|
//# sourceMappingURL=createKubernetesDriver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createKubernetesDriver.js","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/composition/createKubernetesDriver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createKubernetesDriver.js","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/composition/createKubernetesDriver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAC/F,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAC7F,OAAO,EAAE,4BAA4B,EAAE,MAAM,uDAAuD,CAAC;AACrG,OAAO,EAAE,+BAA+B,EAAE,MAAM,0DAA0D,CAAC;AAC3G,OAAO,EAAE,iCAAiC,EAAE,MAAM,4DAA4D,CAAC;AAC/G,OAAO,EAAE,8BAA8B,EAAE,MAAM,yDAAyD,CAAC;AACzG,OAAO,EAAE,+BAA+B,EAAE,MAAM,0DAA0D,CAAC;AAE3G;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgC;IACrE,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,YAAY,EAAE,+BAA+B;QAC7C,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,4BAA4B,CAAC,OAAO,EAAE,OAAO,CAAC;QACtE,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,iCAAiC,CAAC,OAAO,EAAE,OAAO,CAAC;QAChF,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,8BAA8B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;QAC5F,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC;QACpE,mBAAmB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,+BAA+B,CAAC,OAAO,EAAE,OAAO,CAAC;QACnF,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC;KACvE,CAAC;AACJ,CAAC","sourcesContent":["import type { KubernetesDriver, KubernetesDriverOptions } from '../../../types/kubernetesDriver';\nimport { getKubernetesOutputsAsync } from '../application/use-cases/getKubernetesOutputsAsync';\nimport { getKubernetesStatusAsync } from '../application/use-cases/getKubernetesStatusAsync';\nimport { planKubernetesResourcesAsync } from '../application/use-cases/planKubernetesResourcesAsync';\nimport { projectKubernetesResourcesAsync } from '../application/use-cases/projectKubernetesResourcesAsync';\nimport { reconcileKubernetesResourcesAsync } from '../application/use-cases/reconcileKubernetesResourcesAsync';\nimport { removeKubernetesResourcesAsync } from '../application/use-cases/removeKubernetesResourcesAsync';\nimport { waitForKubernetesReadinessAsync } from '../application/use-cases/waitForKubernetesReadinessAsync';\n\n/***\n * Create the shared Kubernetes workload driver entrypoint.\n *\n * Kubernetes is an implementation dependency for runtime adapters, not a selectable Infra\n * provider. The supplied API port is already authenticated cluster access; the driver adds only\n * standard Kubernetes workload projection and lifecycle semantics.\n *\n * @readme\n */\nexport function createKubernetesDriver(options: KubernetesDriverOptions): KubernetesDriver {\n return {\n kind: 'kubernetes',\n projectAsync: projectKubernetesResourcesAsync,\n planAsync: (request) => planKubernetesResourcesAsync(options, request),\n reconcileAsync: (request) => reconcileKubernetesResourcesAsync(options, request),\n removeAsync: (request, destroy) => removeKubernetesResourcesAsync(options, request, destroy),\n statusAsync: (request) => getKubernetesStatusAsync(options, request),\n waitUntilReadyAsync: (request) => waitForKubernetesReadinessAsync(options, request),\n outputsAsync: (request) => getKubernetesOutputsAsync(options, request),\n };\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const KUBERNETES_OWNERSHIP: {
|
|
2
|
+
readonly managedByLabel: "app.kubernetes.io/managed-by";
|
|
3
|
+
readonly managedByValue: "ankhorage-infra";
|
|
4
|
+
readonly projectLabel: "infra.ankhorage.dev/project";
|
|
5
|
+
readonly environmentLabel: "infra.ankhorage.dev/environment";
|
|
6
|
+
readonly projectAnnotation: "infra.ankhorage.dev/project-id";
|
|
7
|
+
readonly environmentAnnotation: "infra.ankhorage.dev/environment";
|
|
8
|
+
readonly adapterAnnotation: "infra.ankhorage.dev/adapter";
|
|
9
|
+
readonly resourceAnnotation: "infra.ankhorage.dev/resource-id";
|
|
10
|
+
readonly persistentAnnotation: "infra.ankhorage.dev/persistent";
|
|
11
|
+
readonly retentionAnnotation: "infra.ankhorage.dev/retention";
|
|
12
|
+
readonly dependenciesAnnotation: "infra.ankhorage.dev/depends-on";
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/features/workload-reconciliation/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;CAYvB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const KUBERNETES_OWNERSHIP = {
|
|
2
|
+
managedByLabel: 'app.kubernetes.io/managed-by',
|
|
3
|
+
managedByValue: 'ankhorage-infra',
|
|
4
|
+
projectLabel: 'infra.ankhorage.dev/project',
|
|
5
|
+
environmentLabel: 'infra.ankhorage.dev/environment',
|
|
6
|
+
projectAnnotation: 'infra.ankhorage.dev/project-id',
|
|
7
|
+
environmentAnnotation: 'infra.ankhorage.dev/environment',
|
|
8
|
+
adapterAnnotation: 'infra.ankhorage.dev/adapter',
|
|
9
|
+
resourceAnnotation: 'infra.ankhorage.dev/resource-id',
|
|
10
|
+
persistentAnnotation: 'infra.ankhorage.dev/persistent',
|
|
11
|
+
retentionAnnotation: 'infra.ankhorage.dev/retention',
|
|
12
|
+
dependenciesAnnotation: 'infra.ankhorage.dev/depends-on',
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/features/workload-reconciliation/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,cAAc,EAAE,8BAA8B;IAC9C,cAAc,EAAE,iBAAiB;IACjC,YAAY,EAAE,6BAA6B;IAC3C,gBAAgB,EAAE,iCAAiC;IACnD,iBAAiB,EAAE,gCAAgC;IACnD,qBAAqB,EAAE,iCAAiC;IACxD,iBAAiB,EAAE,6BAA6B;IAChD,kBAAkB,EAAE,iCAAiC;IACrD,oBAAoB,EAAE,gCAAgC;IACtD,mBAAmB,EAAE,+BAA+B;IACpD,sBAAsB,EAAE,gCAAgC;CAChD,CAAC","sourcesContent":["export const KUBERNETES_OWNERSHIP = {\n managedByLabel: 'app.kubernetes.io/managed-by',\n managedByValue: 'ankhorage-infra',\n projectLabel: 'infra.ankhorage.dev/project',\n environmentLabel: 'infra.ankhorage.dev/environment',\n projectAnnotation: 'infra.ankhorage.dev/project-id',\n environmentAnnotation: 'infra.ankhorage.dev/environment',\n adapterAnnotation: 'infra.ankhorage.dev/adapter',\n resourceAnnotation: 'infra.ankhorage.dev/resource-id',\n persistentAnnotation: 'infra.ankhorage.dev/persistent',\n retentionAnnotation: 'infra.ankhorage.dev/retention',\n dependenciesAnnotation: 'infra.ankhorage.dev/depends-on',\n} as const;\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { KubernetesResource } from '../../../types/kubernetesResources';
|
|
2
|
+
/*** Compare desired and observed Kubernetes resources while ignoring server-owned metadata. */
|
|
3
|
+
export declare function areKubernetesResourcesEquivalent(desired: KubernetesResource, actual: KubernetesResource): boolean;
|
|
4
|
+
//# sourceMappingURL=areKubernetesResourcesEquivalent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"areKubernetesResourcesEquivalent.d.ts","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/areKubernetesResourcesEquivalent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E,+FAA+F;AAC/F,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,kBAAkB,EAC3B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAET"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*** Compare desired and observed Kubernetes resources while ignoring server-owned metadata. */
|
|
2
|
+
export function areKubernetesResourcesEquivalent(desired, actual) {
|
|
3
|
+
return stableSerialize(normalize(desired)) === stableSerialize(normalize(actual));
|
|
4
|
+
}
|
|
5
|
+
/*** Normalize write-only Secret data and recursively order object keys. */
|
|
6
|
+
function normalize(resource) {
|
|
7
|
+
const { stringData } = resource;
|
|
8
|
+
const data = stringData === undefined
|
|
9
|
+
? resource.data
|
|
10
|
+
: Object.fromEntries(Object.entries(stringData).map(([key, value]) => [
|
|
11
|
+
key,
|
|
12
|
+
Buffer.from(value).toString('base64'),
|
|
13
|
+
]));
|
|
14
|
+
return {
|
|
15
|
+
apiVersion: resource.apiVersion,
|
|
16
|
+
kind: resource.kind,
|
|
17
|
+
metadata: {
|
|
18
|
+
name: resource.metadata.name,
|
|
19
|
+
...(resource.metadata.namespace === undefined
|
|
20
|
+
? {}
|
|
21
|
+
: { namespace: resource.metadata.namespace }),
|
|
22
|
+
labels: resource.metadata.labels,
|
|
23
|
+
annotations: resource.metadata.annotations,
|
|
24
|
+
},
|
|
25
|
+
...(data === undefined ? {} : { data }),
|
|
26
|
+
...(resource.spec === undefined ? {} : { spec: resource.spec }),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/*** Serialize plain Kubernetes desired data with stable recursive key ordering. */
|
|
30
|
+
function stableSerialize(value) {
|
|
31
|
+
if (Array.isArray(value))
|
|
32
|
+
return `[${value.map(stableSerialize).join(',')}]`;
|
|
33
|
+
if (value !== null && typeof value === 'object') {
|
|
34
|
+
return `{${Object.entries(value)
|
|
35
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
36
|
+
.map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item)}`)
|
|
37
|
+
.join(',')}}`;
|
|
38
|
+
}
|
|
39
|
+
return JSON.stringify(value);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=areKubernetesResourcesEquivalent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"areKubernetesResourcesEquivalent.js","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/areKubernetesResourcesEquivalent.ts"],"names":[],"mappings":"AAEA,+FAA+F;AAC/F,MAAM,UAAU,gCAAgC,CAC9C,OAA2B,EAC3B,MAA0B;IAE1B,OAAO,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AACpF,CAAC;AAED,2EAA2E;AAC3E,SAAS,SAAS,CAAC,QAA4B;IAC7C,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC;IAChC,MAAM,IAAI,GACR,UAAU,KAAK,SAAS;QACtB,CAAC,CAAC,QAAQ,CAAC,IAAI;QACf,CAAC,CAAC,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,C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AC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;aACtC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;aACvE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import type { KubernetesResource } from '../../../types/kubernetesResources';\n\n/*** Compare desired and observed Kubernetes resources while ignoring server-owned metadata. */\nexport function areKubernetesResourcesEquivalent(\n desired: KubernetesResource,\n actual: KubernetesResource,\n): boolean {\n return stableSerialize(normalize(desired)) === stableSerialize(normalize(actual));\n}\n\n/*** Normalize write-only Secret data and recursively order object keys. */\nfunction normalize(resource: KubernetesResource): unknown {\n const { stringData } = resource;\n const data =\n stringData === undefined\n ? resource.data\n : Object.fromEntries(\n Object.entries(stringData).map(([key, value]) => [\n key,\n Buffer.from(value).toString('base64'),\n ]),\n );\n return {\n apiVersion: resource.apiVersion,\n kind: resource.kind,\n metadata: {\n name: resource.metadata.name,\n ...(resource.metadata.namespace === undefined\n ? {}\n : { namespace: resource.metadata.namespace }),\n labels: resource.metadata.labels,\n annotations: resource.metadata.annotations,\n },\n ...(data === undefined ? {} : { data }),\n ...(resource.spec === undefined ? {} : { spec: resource.spec }),\n };\n}\n\n/*** Serialize plain Kubernetes desired data with stable recursive key ordering. */\nfunction stableSerialize(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(stableSerialize).join(',')}]`;\n if (value !== null && typeof value === 'object') {\n return `{${Object.entries(value)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item)}`)\n .join(',')}}`;\n }\n return JSON.stringify(value);\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InfraOwnedResource, InfraResourceIdentity } from '@ankhorage/contracts/infra';
|
|
2
|
+
import type { KubernetesDriverRequest } from '../../../types/kubernetesDriver';
|
|
3
|
+
import type { KubernetesDesiredResource, KubernetesResource } from '../../../types/kubernetesResources';
|
|
4
|
+
/*** Attach canonical Infra ownership to a standard Kubernetes desired resource. */
|
|
5
|
+
export declare function createKubernetesDesiredResource(request: KubernetesDriverRequest, input: CreateKubernetesDesiredResourceInput): KubernetesDesiredResource;
|
|
6
|
+
interface CreateKubernetesDesiredResourceInput {
|
|
7
|
+
readonly resourceId: string;
|
|
8
|
+
readonly resource: KubernetesResource;
|
|
9
|
+
readonly persistent?: boolean;
|
|
10
|
+
readonly retention?: InfraOwnedResource['retention'];
|
|
11
|
+
readonly dependsOn?: readonly InfraResourceIdentity[];
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=createKubernetesDesiredResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createKubernetesDesiredResource.d.ts","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/createKubernetesDesiredResource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAE5F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,EACV,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAM5C,mFAAmF;AACnF,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,EAChC,KAAK,EAAE,oCAAoC,GAC1C,yBAAyB,CAyC3B;AAED,UAAU,oCAAoC;IAC5C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC;IACrD,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACvD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { KUBERNETES_OWNERSHIP } from '../constants';
|
|
2
|
+
import { getKubernetesResourceKey } from './getKubernetesResourceKey';
|
|
3
|
+
import { getKubernetesResourceReference } from './getKubernetesResourceReference';
|
|
4
|
+
import { toKubernetesName } from './toKubernetesName';
|
|
5
|
+
/*** Attach canonical Infra ownership to a standard Kubernetes desired resource. */
|
|
6
|
+
export function createKubernetesDesiredResource(request, input) {
|
|
7
|
+
const identity = {
|
|
8
|
+
projectId: request.context.projectId,
|
|
9
|
+
environment: request.context.environment,
|
|
10
|
+
adapter: request.ownerAdapter,
|
|
11
|
+
resourceId: input.resourceId,
|
|
12
|
+
};
|
|
13
|
+
const dependsOn = input.dependsOn ?? [];
|
|
14
|
+
const resource = {
|
|
15
|
+
...input.resource,
|
|
16
|
+
metadata: {
|
|
17
|
+
...input.resource.metadata,
|
|
18
|
+
labels: {
|
|
19
|
+
...input.resource.metadata.labels,
|
|
20
|
+
[KUBERNETES_OWNERSHIP.managedByLabel]: KUBERNETES_OWNERSHIP.managedByValue,
|
|
21
|
+
[KUBERNETES_OWNERSHIP.projectLabel]: toKubernetesName(request.context.projectId),
|
|
22
|
+
[KUBERNETES_OWNERSHIP.environmentLabel]: request.context.environment,
|
|
23
|
+
},
|
|
24
|
+
annotations: {
|
|
25
|
+
...input.resource.metadata.annotations,
|
|
26
|
+
[KUBERNETES_OWNERSHIP.projectAnnotation]: request.context.projectId,
|
|
27
|
+
[KUBERNETES_OWNERSHIP.environmentAnnotation]: request.context.environment,
|
|
28
|
+
[KUBERNETES_OWNERSHIP.adapterAnnotation]: request.ownerAdapter,
|
|
29
|
+
[KUBERNETES_OWNERSHIP.resourceAnnotation]: input.resourceId,
|
|
30
|
+
[KUBERNETES_OWNERSHIP.persistentAnnotation]: String(input.persistent ?? false),
|
|
31
|
+
[KUBERNETES_OWNERSHIP.retentionAnnotation]: input.retention ?? 'retain',
|
|
32
|
+
[KUBERNETES_OWNERSHIP.dependenciesAnnotation]: JSON.stringify(dependsOn.map((dependency) => dependency.resourceId)),
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const owner = {
|
|
37
|
+
identity,
|
|
38
|
+
externalId: getKubernetesResourceKey(getKubernetesResourceReference(resource)),
|
|
39
|
+
persistent: input.persistent ?? false,
|
|
40
|
+
retention: input.retention ?? 'retain',
|
|
41
|
+
dependsOn,
|
|
42
|
+
};
|
|
43
|
+
return { resource, owner };
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=createKubernetesDesiredResource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createKubernetesDesiredResource.js","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/createKubernetesDesiredResource.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,mFAAmF;AACnF,MAAM,UAAU,+BAA+B,CAC7C,OAAgC,EAChC,KAA2C;IAE3C,MAAM,QAAQ,GAA0B;QACtC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS;QACpC,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW;QACxC,OAAO,EAAE,OAAO,CAAC,YAAY;QAC7B,UAAU,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC;IACF,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,EAAE,CA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AAC,8BAA8B,CAAC,QAAQ,CAAC,CAAC;QAC9E,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,KAAK;QACrC,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,QAAQ;QACtC,SAAS;KACV,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["import type { InfraOwnedResource, InfraResourceIdentity } from '@ankhorage/contracts/infra';\n\nimport type { KubernetesDriverRequest } from '../../../types/kubernetesDriver';\nimport type {\n KubernetesDesiredResource,\n KubernetesResource,\n} from '../../../types/kubernetesResources';\nimport { KUBERNETES_OWNERSHIP } from '../constants';\nimport { getKubernetesResourceKey } from './getKubernetesResourceKey';\nimport { getKubernetesResourceReference } from './getKubernetesResourceReference';\nimport { toKubernetesName } from './toKubernetesName';\n\n/*** Attach canonical Infra ownership to a standard Kubernetes desired resource. */\nexport function createKubernetesDesiredResource(\n request: KubernetesDriverRequest,\n input: CreateKubernetesDesiredResourceInput,\n): KubernetesDesiredResource {\n const identity: InfraResourceIdentity = {\n projectId: request.context.projectId,\n environment: request.context.environment,\n adapter: request.ownerAdapter,\n resourceId: input.resourceId,\n };\n const dependsOn = input.dependsOn ?? [];\n const resource: KubernetesResource = {\n ...input.resource,\n metadata: {\n ...input.resource.metadata,\n labels: {\n ...input.resource.metadata.labels,\n [KUBERNETES_OWNERSHIP.managedByLabel]: KUBERNETES_OWNERSHIP.managedByValue,\n [KUBERNETES_OWNERSHIP.projectLabel]: toKubernetesName(request.context.projectId),\n [KUBERNETES_OWNERSHIP.environmentLabel]: request.context.environment,\n },\n annotations: {\n ...input.resource.metadata.annotations,\n [KUBERNETES_OWNERSHIP.projectAnnotation]: request.context.projectId,\n [KUBERNETES_OWNERSHIP.environmentAnnotation]: request.context.environment,\n [KUBERNETES_OWNERSHIP.adapterAnnotation]: request.ownerAdapter,\n [KUBERNETES_OWNERSHIP.resourceAnnotation]: input.resourceId,\n [KUBERNETES_OWNERSHIP.persistentAnnotation]: String(input.persistent ?? false),\n [KUBERNETES_OWNERSHIP.retentionAnnotation]: input.retention ?? 'retain',\n [KUBERNETES_OWNERSHIP.dependenciesAnnotation]: JSON.stringify(\n dependsOn.map((dependency) => dependency.resourceId),\n ),\n },\n },\n };\n\n const owner: InfraOwnedResource = {\n identity,\n externalId: getKubernetesResourceKey(getKubernetesResourceReference(resource)),\n persistent: input.persistent ?? false,\n retention: input.retention ?? 'retain',\n dependsOn,\n };\n return { resource, owner };\n}\n\ninterface CreateKubernetesDesiredResourceInput {\n readonly resourceId: string;\n readonly resource: KubernetesResource;\n readonly persistent?: boolean;\n readonly retention?: InfraOwnedResource['retention'];\n readonly dependsOn?: readonly InfraResourceIdentity[];\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { InfraResourceIdentity } from '@ankhorage/contracts/infra';
|
|
2
|
+
import type { KubernetesDriverRequest } from '../../../types/kubernetesDriver';
|
|
3
|
+
/*** Create a runtime-owned Infra identity without provider-specific assumptions. */
|
|
4
|
+
export declare function createKubernetesIdentity(request: KubernetesDriverRequest, resourceId: string): InfraResourceIdentity;
|
|
5
|
+
//# sourceMappingURL=createKubernetesIdentity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createKubernetesIdentity.d.ts","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/createKubernetesIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE/E,oFAAoF;AACpF,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,uBAAuB,EAChC,UAAU,EAAE,MAAM,GACjB,qBAAqB,CAOvB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*** Create a runtime-owned Infra identity without provider-specific assumptions. */
|
|
2
|
+
export function createKubernetesIdentity(request, resourceId) {
|
|
3
|
+
return {
|
|
4
|
+
projectId: request.context.projectId,
|
|
5
|
+
environment: request.context.environment,
|
|
6
|
+
adapter: request.ownerAdapter,
|
|
7
|
+
resourceId,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=createKubernetesIdentity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createKubernetesIdentity.js","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/createKubernetesIdentity.ts"],"names":[],"mappings":"AAIA,oFAAoF;AACpF,MAAM,UAAU,wBAAwB,CACtC,OAAgC,EAChC,UAAkB;IAElB,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS;QACpC,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW;QACxC,OAAO,EAAE,OAAO,CAAC,YAAY;QAC7B,UAAU;KACX,CAAC;AACJ,CAAC","sourcesContent":["import type { InfraResourceIdentity } from '@ankhorage/contracts/infra';\n\nimport type { KubernetesDriverRequest } from '../../../types/kubernetesDriver';\n\n/*** Create a runtime-owned Infra identity without provider-specific assumptions. */\nexport function createKubernetesIdentity(\n request: KubernetesDriverRequest,\n resourceId: string,\n): InfraResourceIdentity {\n return {\n projectId: request.context.projectId,\n environment: request.context.environment,\n adapter: request.ownerAdapter,\n resourceId,\n };\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { KubernetesDriverRequest } from '../../../types/kubernetesDriver';
|
|
2
|
+
import type { KubernetesOwnershipQuery } from '../../../types/kubernetesResources';
|
|
3
|
+
/*** Build the narrow ownership selector used for every read and prune operation. */
|
|
4
|
+
export declare function getKubernetesOwnershipQuery(request: KubernetesDriverRequest): KubernetesOwnershipQuery;
|
|
5
|
+
//# sourceMappingURL=getKubernetesOwnershipQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getKubernetesOwnershipQuery.d.ts","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/getKubernetesOwnershipQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAInF,oFAAoF;AACpF,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,uBAAuB,GAC/B,wBAAwB,CAY1B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { KUBERNETES_OWNERSHIP } from '../constants';
|
|
2
|
+
import { toKubernetesName } from './toKubernetesName';
|
|
3
|
+
/*** Build the narrow ownership selector used for every read and prune operation. */
|
|
4
|
+
export function getKubernetesOwnershipQuery(request) {
|
|
5
|
+
return {
|
|
6
|
+
namespace: request.namespace ??
|
|
7
|
+
toKubernetesName(`${request.context.projectId}-${request.context.environment}`),
|
|
8
|
+
labels: {
|
|
9
|
+
[KUBERNETES_OWNERSHIP.managedByLabel]: KUBERNETES_OWNERSHIP.managedByValue,
|
|
10
|
+
[KUBERNETES_OWNERSHIP.projectLabel]: toKubernetesName(request.context.projectId),
|
|
11
|
+
[KUBERNETES_OWNERSHIP.environmentLabel]: request.context.environment,
|
|
12
|
+
},
|
|
13
|
+
...(request.context.signal === undefined ? {} : { signal: request.context.signal }),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getKubernetesOwnershipQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getKubernetesOwnershipQuery.js","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/getKubernetesOwnershipQuery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,oFAAoF;AACpF,MAAM,UAAU,2BAA2B,CACzC,OAAgC;IAEhC,OAAO;QACL,SAAS,EACP,OAAO,CAAC,SAAS;YACjB,gBAAgB,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACjF,MAAM,EAAE;YACN,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,oBAAoB,CAAC,cAAc;YAC1E,CAAC,oBAAoB,CAAC,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;YAChF,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW;SACrE;QACD,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;KACpF,CAAC;AACJ,CAAC","sourcesContent":["import type { KubernetesDriverRequest } from '../../../types/kubernetesDriver';\nimport type { KubernetesOwnershipQuery } from '../../../types/kubernetesResources';\nimport { KUBERNETES_OWNERSHIP } from '../constants';\nimport { toKubernetesName } from './toKubernetesName';\n\n/*** Build the narrow ownership selector used for every read and prune operation. */\nexport function getKubernetesOwnershipQuery(\n request: KubernetesDriverRequest,\n): KubernetesOwnershipQuery {\n return {\n namespace:\n request.namespace ??\n toKubernetesName(`${request.context.projectId}-${request.context.environment}`),\n labels: {\n [KUBERNETES_OWNERSHIP.managedByLabel]: KUBERNETES_OWNERSHIP.managedByValue,\n [KUBERNETES_OWNERSHIP.projectLabel]: toKubernetesName(request.context.projectId),\n [KUBERNETES_OWNERSHIP.environmentLabel]: request.context.environment,\n },\n ...(request.context.signal === undefined ? {} : { signal: request.context.signal }),\n };\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { KubernetesResourceReference } from '../../../types/kubernetesResources';
|
|
2
|
+
/*** Build a stable comparison key for a Kubernetes resource identity. */
|
|
3
|
+
export declare function getKubernetesResourceKey(resource: KubernetesResourceReference): string;
|
|
4
|
+
//# sourceMappingURL=getKubernetesResourceKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getKubernetesResourceKey.d.ts","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/getKubernetesResourceKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEtF,yEAAyE;AACzE,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,2BAA2B,GAAG,MAAM,CAEtF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*** Build a stable comparison key for a Kubernetes resource identity. */
|
|
2
|
+
export function getKubernetesResourceKey(resource) {
|
|
3
|
+
return [resource.apiVersion, resource.kind, resource.namespace ?? '', resource.name].join('/');
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=getKubernetesResourceKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getKubernetesResourceKey.js","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/getKubernetesResourceKey.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,MAAM,UAAU,wBAAwB,CAAC,QAAqC;IAC5E,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,IAAI,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjG,CAAC","sourcesContent":["import type { KubernetesResourceReference } from '../../../types/kubernetesResources';\n\n/*** Build a stable comparison key for a Kubernetes resource identity. */\nexport function getKubernetesResourceKey(resource: KubernetesResourceReference): string {\n return [resource.apiVersion, resource.kind, resource.namespace ?? '', resource.name].join('/');\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { KubernetesResource, KubernetesResourceReference } from '../../../types/kubernetesResources';
|
|
2
|
+
/*** Return the immutable Kubernetes identity of a desired or observed resource. */
|
|
3
|
+
export declare function getKubernetesResourceReference(resource: KubernetesResource): KubernetesResourceReference;
|
|
4
|
+
//# sourceMappingURL=getKubernetesResourceReference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getKubernetesResourceReference.d.ts","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/getKubernetesResourceReference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,2BAA2B,EAC5B,MAAM,oCAAoC,CAAC;AAE5C,mFAAmF;AACnF,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,kBAAkB,GAC3B,2BAA2B,CAS7B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*** Return the immutable Kubernetes identity of a desired or observed resource. */
|
|
2
|
+
export function getKubernetesResourceReference(resource) {
|
|
3
|
+
return {
|
|
4
|
+
apiVersion: resource.apiVersion,
|
|
5
|
+
kind: resource.kind,
|
|
6
|
+
name: resource.metadata.name,
|
|
7
|
+
...(resource.metadata.namespace === undefined
|
|
8
|
+
? {}
|
|
9
|
+
: { namespace: resource.metadata.namespace }),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=getKubernetesResourceReference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getKubernetesResourceReference.js","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/getKubernetesResourceReference.ts"],"names":[],"mappings":"AAKA,mFAAmF;AACnF,MAAM,UAAU,8BAA8B,CAC5C,QAA4B;IAE5B,OAAO;QACL,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI;QAC5B,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,KAAK,SAAS;YAC3C,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;KAChD,CAAC;AACJ,CAAC","sourcesContent":["import type {\n KubernetesResource,\n KubernetesResourceReference,\n} from '../../../types/kubernetesResources';\n\n/*** Return the immutable Kubernetes identity of a desired or observed resource. */\nexport function getKubernetesResourceReference(\n resource: KubernetesResource,\n): KubernetesResourceReference {\n return {\n apiVersion: resource.apiVersion,\n kind: resource.kind,\n name: resource.metadata.name,\n ...(resource.metadata.namespace === undefined\n ? {}\n : { namespace: resource.metadata.namespace }),\n };\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InfraOwnedResource } from '@ankhorage/contracts/infra';
|
|
2
|
+
import type { KubernetesDriverRequest } from '../../../types/kubernetesDriver';
|
|
3
|
+
import type { KubernetesResource } from '../../../types/kubernetesResources';
|
|
4
|
+
/*** Read trusted ownership metadata, rejecting resources outside the active Infra identity. */
|
|
5
|
+
export declare function readKubernetesOwnedResource(resource: KubernetesResource, request: KubernetesDriverRequest): InfraOwnedResource | undefined;
|
|
6
|
+
//# sourceMappingURL=readKubernetesOwnedResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readKubernetesOwnedResource.d.ts","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/readKubernetesOwnedResource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAyB,MAAM,4BAA4B,CAAC;AAE5F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAK7E,+FAA+F;AAC/F,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,uBAAuB,GAC/B,kBAAkB,GAAG,SAAS,CAmChC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { KUBERNETES_OWNERSHIP } from '../constants';
|
|
2
|
+
import { getKubernetesResourceKey } from './getKubernetesResourceKey';
|
|
3
|
+
import { getKubernetesResourceReference } from './getKubernetesResourceReference';
|
|
4
|
+
/*** Read trusted ownership metadata, rejecting resources outside the active Infra identity. */
|
|
5
|
+
export function readKubernetesOwnedResource(resource, request) {
|
|
6
|
+
const { annotations } = resource.metadata;
|
|
7
|
+
if (annotations[KUBERNETES_OWNERSHIP.projectAnnotation] !== request.context.projectId ||
|
|
8
|
+
annotations[KUBERNETES_OWNERSHIP.environmentAnnotation] !== request.context.environment ||
|
|
9
|
+
annotations[KUBERNETES_OWNERSHIP.adapterAnnotation] !== request.ownerAdapter) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const resourceId = annotations[KUBERNETES_OWNERSHIP.resourceAnnotation];
|
|
13
|
+
if (resourceId === undefined || resourceId.length === 0)
|
|
14
|
+
return undefined;
|
|
15
|
+
const identity = {
|
|
16
|
+
projectId: request.context.projectId,
|
|
17
|
+
environment: request.context.environment,
|
|
18
|
+
adapter: request.ownerAdapter,
|
|
19
|
+
resourceId,
|
|
20
|
+
};
|
|
21
|
+
const dependencies = readDependencies(annotations[KUBERNETES_OWNERSHIP.dependenciesAnnotation], identity);
|
|
22
|
+
if (dependencies === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
return {
|
|
25
|
+
identity,
|
|
26
|
+
externalId: getKubernetesResourceKey(getKubernetesResourceReference(resource)),
|
|
27
|
+
persistent: annotations[KUBERNETES_OWNERSHIP.persistentAnnotation] === 'true',
|
|
28
|
+
retention: annotations[KUBERNETES_OWNERSHIP.retentionAnnotation] === 'delete-on-destroy'
|
|
29
|
+
? 'delete-on-destroy'
|
|
30
|
+
: 'retain',
|
|
31
|
+
dependsOn: dependencies,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/*** Decode dependency IDs without trusting arbitrary serialized identity objects. */
|
|
35
|
+
function readDependencies(value, identity) {
|
|
36
|
+
if (value === undefined)
|
|
37
|
+
return [];
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(value);
|
|
40
|
+
if (!Array.isArray(parsed) || !parsed.every((item) => typeof item === 'string')) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return parsed.map((resourceId) => ({ ...identity, resourceId }));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=readKubernetesOwnedResource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readKubernetesOwnedResource.js","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/readKubernetesOwnedResource.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAElF,+FAA+F;AAC/F,MAAM,UAAU,2BAA2B,CACzC,QAA4B,EAC5B,OAAgC;IAEhC,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC,QAAQ,CAAC;IAC1C,IACE,WAAW,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,SAAS;QACjF,WAAW,CAAC,oBAAoB,CAAC,qBAAqB,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,WAAW;QACvF,WAAW,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,KAAK,OAAO,CAAC,YAAY,EAC5E,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,UAAU,GAAG,WAAW,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,CAAC;IACxE,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAE1E,MAAM,QA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CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import type { InfraOwnedResource, InfraResourceIdentity } from '@ankhorage/contracts/infra';\n\nimport type { KubernetesDriverRequest } from '../../../types/kubernetesDriver';\nimport type { KubernetesResource } from '../../../types/kubernetesResources';\nimport { KUBERNETES_OWNERSHIP } from '../constants';\nimport { getKubernetesResourceKey } from './getKubernetesResourceKey';\nimport { getKubernetesResourceReference } from './getKubernetesResourceReference';\n\n/*** Read trusted ownership metadata, rejecting resources outside the active Infra identity. */\nexport function readKubernetesOwnedResource(\n resource: KubernetesResource,\n request: KubernetesDriverRequest,\n): InfraOwnedResource | undefined {\n const { annotations } = resource.metadata;\n if (\n annotations[KUBERNETES_OWNERSHIP.projectAnnotation] !== request.context.projectId ||\n annotations[KUBERNETES_OWNERSHIP.environmentAnnotation] !== request.context.environment ||\n annotations[KUBERNETES_OWNERSHIP.adapterAnnotation] !== request.ownerAdapter\n ) {\n return undefined;\n }\n\n const resourceId = annotations[KUBERNETES_OWNERSHIP.resourceAnnotation];\n if (resourceId === undefined || resourceId.length === 0) return undefined;\n\n const identity: InfraResourceIdentity = {\n projectId: request.context.projectId,\n environment: request.context.environment,\n adapter: request.ownerAdapter,\n resourceId,\n };\n const dependencies = readDependencies(\n annotations[KUBERNETES_OWNERSHIP.dependenciesAnnotation],\n identity,\n );\n if (dependencies === undefined) return undefined;\n\n return {\n identity,\n externalId: getKubernetesResourceKey(getKubernetesResourceReference(resource)),\n persistent: annotations[KUBERNETES_OWNERSHIP.persistentAnnotation] === 'true',\n retention:\n annotations[KUBERNETES_OWNERSHIP.retentionAnnotation] === 'delete-on-destroy'\n ? 'delete-on-destroy'\n : 'retain',\n dependsOn: dependencies,\n };\n}\n\n/*** Decode dependency IDs without trusting arbitrary serialized identity objects. */\nfunction readDependencies(\n value: string | undefined,\n identity: InfraResourceIdentity,\n): readonly InfraResourceIdentity[] | undefined {\n if (value === undefined) return [];\n try {\n const parsed: unknown = JSON.parse(value);\n if (!Array.isArray(parsed) || !parsed.every((item) => typeof item === 'string')) {\n return undefined;\n }\n return parsed.map((resourceId) => ({ ...identity, resourceId }));\n } catch {\n return undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InfraOwnedResource } from '@ankhorage/contracts/infra';
|
|
2
|
+
import type { KubernetesResource } from '../../../types/kubernetesResources';
|
|
3
|
+
export interface OwnedKubernetesResource {
|
|
4
|
+
readonly resource: KubernetesResource;
|
|
5
|
+
readonly owner: InfraOwnedResource;
|
|
6
|
+
}
|
|
7
|
+
/*** Sort owned resources deterministically with dependents before their dependencies. */
|
|
8
|
+
export declare function sortKubernetesResourcesForRemoval(resources: readonly OwnedKubernetesResource[]): readonly OwnedKubernetesResource[];
|
|
9
|
+
//# sourceMappingURL=sortKubernetesResourcesForRemoval.d.ts.map
|
package/dist/features/workload-reconciliation/utils/sortKubernetesResourcesForRemoval.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortKubernetesResourcesForRemoval.d.ts","sourceRoot":"","sources":["../../../../src/features/workload-reconciliation/utils/sortKubernetesResourcesForRemoval.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAErE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;CACpC;AAED,yFAAyF;AACzF,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,SAAS,uBAAuB,EAAE,GAC5C,SAAS,uBAAuB,EAAE,CAkBpC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*** Sort owned resources deterministically with dependents before their dependencies. */
|
|
2
|
+
export function sortKubernetesResourcesForRemoval(resources) {
|
|
3
|
+
const remaining = new Map(resources.map((item) => [item.owner.identity.resourceId, item]));
|
|
4
|
+
const ordered = [];
|
|
5
|
+
while (remaining.size > 0) {
|
|
6
|
+
const leaves = [...remaining.values()]
|
|
7
|
+
.filter(({ owner }) => ![...remaining.values()].some(({ owner: candidate }) => candidate.dependsOn.some(({ resourceId }) => resourceId === owner.identity.resourceId)))
|
|
8
|
+
.sort(compareResourceKeys);
|
|
9
|
+
const selected = leaves.at(0) ?? [...remaining.values()].sort(compareResourceKeys).at(0);
|
|
10
|
+
if (selected === undefined)
|
|
11
|
+
break;
|
|
12
|
+
ordered.push(selected);
|
|
13
|
+
remaining.delete(selected.owner.identity.resourceId);
|
|
14
|
+
}
|
|
15
|
+
return ordered;
|
|
16
|
+
}
|
|
17
|
+
/*** Compare owned resources by stable external resource identity. */
|
|
18
|
+
function compareResourceKeys(left, right) {
|
|
19
|
+
return (left.owner.externalId ?? '').localeCompare(right.owner.externalId ?? '');
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=sortKubernetesResourcesForRemoval.js.map
|