@ankhorage/kubernetes 0.7.1 → 0.7.2

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,5 +1,5 @@
1
1
  import type { InfraReconcileResult, InfraResult } from '@ankhorage/contracts/infra';
2
2
  import type { KubernetesDriverOptions, KubernetesDriverRequest } from '../../../../types/kubernetesDriver';
3
- /*** Apply desired changes and prune only obsolete, non-persistent Infra-owned resources. */
3
+ /*** Apply desired changes dependency-first and prune only obsolete, non-persistent Infra resources. */
4
4
  export declare function reconcileKubernetesResourcesAsync(options: KubernetesDriverOptions, request: KubernetesDriverRequest): Promise<InfraResult<InfraReconcileResult>>;
5
5
  //# sourceMappingURL=reconcileKubernetesResourcesAsync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reconcileKubernetesResourcesAsync.d.ts","sourceRoot":"","sources":["../../../../../src/features/workload-reconciliation/application/use-cases/reconcileKubernetesResourcesAsync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,oBAAoB,EACpB,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,oCAAoC,CAAC;AAM5C,4FAA4F;AAC5F,wBAAsB,iCAAiC,CACrD,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,CA+C5C"}
1
+ {"version":3,"file":"reconcileKubernetesResourcesAsync.d.ts","sourceRoot":"","sources":["../../../../../src/features/workload-reconciliation/application/use-cases/reconcileKubernetesResourcesAsync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,oBAAoB,EACpB,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,oCAAoC,CAAC;AAe5C,uGAAuG;AACvG,wBAAsB,iCAAiC,CACrD,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,CAuC5C"}
@@ -1,51 +1,114 @@
1
+ import { KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS, KUBERNETES_READINESS_KINDS, } from '../../constants';
1
2
  import { getKubernetesResourceReference } from '../../utils/getKubernetesResourceReference';
2
3
  import { readKubernetesOwnedResource } from '../../utils/readKubernetesOwnedResource';
3
4
  import { getKubernetesOutputsAsync } from './getKubernetesOutputsAsync';
4
5
  import { prepareKubernetesChangesAsync } from './prepareKubernetesChangesAsync';
5
- /*** Apply desired changes and prune only obsolete, non-persistent Infra-owned resources. */
6
+ /*** Apply desired changes dependency-first and prune only obsolete, non-persistent Infra resources. */
6
7
  export async function reconcileKubernetesResourcesAsync(options, request) {
7
8
  const prepared = await prepareKubernetesChangesAsync(options, request);
8
9
  if (!prepared.ok)
9
10
  return prepared;
11
+ const desiredByResourceId = new Map(prepared.value.projection.resources.map((desired) => [
12
+ desired.owner.identity.resourceId,
13
+ desired,
14
+ ]));
15
+ const timeoutSeconds = options.defaultReadinessTimeoutSeconds ?? KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS;
16
+ const deadline = Date.now() + timeoutSeconds * 1_000;
10
17
  try {
11
- const retained = [];
12
- for (const change of prepared.value.changes) {
13
- if ((change.action.operation === 'create' || change.action.operation === 'update') &&
14
- change.desired !== undefined) {
15
- await options.api.applyAsync(change.desired.resource, request.context.signal);
16
- }
17
- if (change.action.operation === 'delete' && change.actual !== undefined) {
18
- await options.api.deleteAsync(getKubernetesResourceReference(change.actual), request.context.signal);
19
- }
20
- if (change.action.operation === 'retain' && change.actual !== undefined) {
21
- const owner = readKubernetesOwnedResource(change.actual, request);
22
- if (owner !== undefined)
23
- retained.push(owner);
24
- }
25
- }
18
+ const reconciled = await applyKubernetesChangesAsync(options, request, prepared.value.changes, desiredByResourceId, deadline);
19
+ if (!reconciled.ok)
20
+ return reconciled;
26
21
  const outputs = await getKubernetesOutputsAsync(options, request);
27
22
  if (!outputs.ok)
28
23
  return outputs;
29
24
  return {
30
25
  ok: true,
31
26
  value: {
32
- resources: [...prepared.value.projection.resources.map(({ owner }) => owner), ...retained],
27
+ resources: [
28
+ ...prepared.value.projection.resources.map(({ owner }) => owner),
29
+ ...reconciled.value,
30
+ ],
33
31
  outputs: outputs.value,
34
32
  },
35
33
  diagnostics: [],
36
34
  };
37
35
  }
38
36
  catch {
39
- return {
40
- ok: false,
41
- diagnostics: [
42
- {
43
- severity: 'error',
44
- code: 'kubernetes-reconcile-failed',
45
- message: 'Kubernetes resources could not be reconciled safely.',
46
- },
47
- ],
48
- };
37
+ return createReconcileFailure();
49
38
  }
50
39
  }
40
+ /*** Apply prepared changes while enforcing readiness-relevant dependency gates. */
41
+ async function applyKubernetesChangesAsync(options, request, changes, desiredByResourceId, deadline) {
42
+ const retained = [];
43
+ for (const change of changes) {
44
+ if ((change.action.operation === 'create' || change.action.operation === 'update') &&
45
+ change.desired !== undefined) {
46
+ const dependencyFailure = await waitForDependenciesAsync(options, request, change.desired, desiredByResourceId, deadline);
47
+ if (dependencyFailure !== undefined) {
48
+ return { ok: false, diagnostics: [dependencyFailure] };
49
+ }
50
+ await options.api.applyAsync(change.desired.resource, request.context.signal);
51
+ }
52
+ if (change.action.operation === 'delete' && change.actual !== undefined) {
53
+ await options.api.deleteAsync(getKubernetesResourceReference(change.actual), request.context.signal);
54
+ }
55
+ if (change.action.operation === 'retain' && change.actual !== undefined) {
56
+ const owner = readKubernetesOwnedResource(change.actual, request);
57
+ if (owner !== undefined)
58
+ retained.push(owner);
59
+ }
60
+ }
61
+ return { ok: true, value: retained, diagnostics: [] };
62
+ }
63
+ /*** Wait for readiness-relevant dependencies before applying one desired Kubernetes resource. */
64
+ async function waitForDependenciesAsync(options, request, desired, desiredByResourceId, deadline) {
65
+ for (const dependencyOwner of desired.owner.dependsOn) {
66
+ const dependency = desiredByResourceId.get(dependencyOwner.resourceId);
67
+ if (dependency === undefined || !KUBERNETES_READINESS_KINDS.has(dependency.resource.kind)) {
68
+ continue;
69
+ }
70
+ const observation = await waitForDependencyAsync(options, request, dependency, deadline);
71
+ if (observation.state !== 'ready') {
72
+ return createDependencyReadinessDiagnostic(dependency, observation);
73
+ }
74
+ }
75
+ return undefined;
76
+ }
77
+ /*** Wait for one dependency within the reconciliation pass shared readiness deadline. */
78
+ function waitForDependencyAsync(options, request, dependency, deadline) {
79
+ const remainingSeconds = Math.max(0, Math.ceil((deadline - Date.now()) / 1_000));
80
+ if (remainingSeconds === 0) {
81
+ return Promise.resolve({
82
+ state: 'degraded',
83
+ detail: 'The shared Kubernetes readiness deadline expired.',
84
+ });
85
+ }
86
+ return options.api.waitUntilReadyAsync(getKubernetesResourceReference(dependency.resource), {
87
+ timeoutSeconds: remainingSeconds,
88
+ ...(request.context.signal === undefined ? {} : { signal: request.context.signal }),
89
+ });
90
+ }
91
+ /*** Create an actionable diagnostic for a dependency that did not become ready. */
92
+ function createDependencyReadinessDiagnostic(dependency, observation) {
93
+ const detail = observation.detail === undefined ? '' : ` ${observation.detail}`;
94
+ return {
95
+ severity: 'error',
96
+ code: 'kubernetes-dependency-readiness-failed',
97
+ message: `Kubernetes dependency ${dependency.owner.identity.resourceId} is ${observation.state}.${detail}`,
98
+ owner: dependency.owner.identity,
99
+ };
100
+ }
101
+ /*** Create the generic failure returned when reconciliation throws unexpectedly. */
102
+ function createReconcileFailure() {
103
+ return {
104
+ ok: false,
105
+ diagnostics: [
106
+ {
107
+ severity: 'error',
108
+ code: 'kubernetes-reconcile-failed',
109
+ message: 'Kubernetes resources could not be reconciled safely.',
110
+ },
111
+ ],
112
+ };
113
+ }
51
114
  //# sourceMappingURL=reconcileKubernetesResourcesAsync.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reconcileKubernetesResourcesAsync.js","sourceRoot":"","sources":["../../../../../src/features/workload-reconciliation/application/use-cases/reconcileKubernetesResourcesA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AAS,EAAE,CAAC;gBACxE,MAAM,KAAK,GAAG,2BAA2B,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAClE,IAAI,KAAK,KAAK,SAAS;oBAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAClE,IAAI,CAAC,OAAO,CAAC,EAAE;YAAE,OAAO,OAAO,CAAC;QAChC,OAAO;YACL,EAAE,EAAE,IAAI;YACR,KAAK,EAAE;gBACL,SAAS,EAAE,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,QAAQ,CAAC;gBAC1F,OAAO,EAAE,OAAO,CAAC,KAAK;aACvB;YACD,WAAW,EAAE,EAAE;SAChB,CAAC;IACJ,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,sDAAsD;iBAChE;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type {\n InfraOwnedResource,\n InfraReconcileResult,\n InfraResult,\n} from '@ankhorage/contracts/infra';\n\nimport type {\n KubernetesDriverOptions,\n KubernetesDriverRequest,\n} from '../../../../types/kubernetesDriver';\nimport { getKubernetesResourceReference } from '../../utils/getKubernetesResourceReference';\nimport { readKubernetesOwnedResource } from '../../utils/readKubernetesOwnedResource';\nimport { getKubernetesOutputsAsync } from './getKubernetesOutputsAsync';\nimport { prepareKubernetesChangesAsync } from './prepareKubernetesChangesAsync';\n\n/*** Apply desired changes and prune only obsolete, non-persistent Infra-owned resources. */\nexport async function reconcileKubernetesResourcesAsync(\n options: KubernetesDriverOptions,\n request: KubernetesDriverRequest,\n): Promise<InfraResult<InfraReconcileResult>> {\n const prepared = await prepareKubernetesChangesAsync(options, request);\n if (!prepared.ok) return prepared;\n\n try {\n const retained: InfraOwnedResource[] = [];\n for (const change of prepared.value.changes) {\n if (\n (change.action.operation === 'create' || change.action.operation === 'update') &&\n change.desired !== undefined\n ) {\n await options.api.applyAsync(change.desired.resource, request.context.signal);\n }\n if (change.action.operation === 'delete' && change.actual !== undefined) {\n await options.api.deleteAsync(\n getKubernetesResourceReference(change.actual),\n request.context.signal,\n );\n }\n if (change.action.operation === 'retain' && change.actual !== undefined) {\n const owner = readKubernetesOwnedResource(change.actual, request);\n if (owner !== undefined) retained.push(owner);\n }\n }\n\n const outputs = await getKubernetesOutputsAsync(options, request);\n if (!outputs.ok) return outputs;\n return {\n ok: true,\n value: {\n resources: [...prepared.value.projection.resources.map(({ owner }) => owner), ...retained],\n outputs: outputs.value,\n },\n diagnostics: [],\n };\n } catch {\n return {\n ok: false,\n diagnostics: [\n {\n severity: 'error',\n code: 'kubernetes-reconcile-failed',\n message: 'Kubernetes resources could not be reconciled safely.',\n },\n ],\n };\n }\n}\n"]}
1
+ {"version":3,"file":"reconcileKubernetesResourcesAsync.js","sourceRoot":"","sources":["../../../../../src/features/workload-reconciliation/application/use-cases/reconcileKubernetesResourcesAsync.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,4CAA4C,EAC5C,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,OAAgC,EAChC,OAAgC;I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MAAM,EAAE,mDAAmD;SAC5D,CAAC,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,8BAA8B,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC1F,cAAc,EAAE,gBAAgB;QAChC,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,CAAC;AACL,CAAC;AAED,mFAAmF;AACnF,SAAS,mCAAmC,CAC1C,UAAqC,EACrC,WAA0C;IAE1C,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;IAChF,OAAO;QACL,QAAQ,EAAE,OAAO;QACjB,IAAI,EAAE,wCAAwC;QAC9C,OAAO,EAAE,yBAAyB,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,OAAO,WAAW,CAAC,KAAK,IAAI,MAAM,EAAE;QAC1G,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,QAAQ;KACjC,CAAC;AACJ,CAAC;AAED,oFAAoF;AACpF,SAAS,sBAAsB;IAC7B,OAAO;QACL,EAAE,EAAE,KAAK;QACT,WAAW,EAAE;YACX;gBACE,QAAQ,EAAE,OAAO;gBACjB,IAAI,EAAE,6BAA6B;gBACnC,OAAO,EAAE,sDAAsD;aAChE;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n InfraDiagnostic,\n InfraOwnedResource,\n InfraReconcileResult,\n InfraResult,\n} from '@ankhorage/contracts/infra';\n\nimport type {\n KubernetesDriverOptions,\n KubernetesDriverRequest,\n} from '../../../../types/kubernetesDriver';\nimport type {\n KubernetesDesiredResource,\n KubernetesPreparedChange,\n KubernetesResourceObservation,\n} from '../../../../types/kubernetesResources';\nimport {\n KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS,\n KUBERNETES_READINESS_KINDS,\n} from '../../constants';\nimport { getKubernetesResourceReference } from '../../utils/getKubernetesResourceReference';\nimport { readKubernetesOwnedResource } from '../../utils/readKubernetesOwnedResource';\nimport { getKubernetesOutputsAsync } from './getKubernetesOutputsAsync';\nimport { prepareKubernetesChangesAsync } from './prepareKubernetesChangesAsync';\n\n/*** Apply desired changes dependency-first and prune only obsolete, non-persistent Infra resources. */\nexport async function reconcileKubernetesResourcesAsync(\n options: KubernetesDriverOptions,\n request: KubernetesDriverRequest,\n): Promise<InfraResult<InfraReconcileResult>> {\n const prepared = await prepareKubernetesChangesAsync(options, request);\n if (!prepared.ok) return prepared;\n\n const desiredByResourceId = new Map(\n prepared.value.projection.resources.map((desired) => [\n desired.owner.identity.resourceId,\n desired,\n ]),\n );\n const timeoutSeconds =\n options.defaultReadinessTimeoutSeconds ?? KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS;\n const deadline = Date.now() + timeoutSeconds * 1_000;\n\n try {\n const reconciled = await applyKubernetesChangesAsync(\n options,\n request,\n prepared.value.changes,\n desiredByResourceId,\n deadline,\n );\n if (!reconciled.ok) return reconciled;\n const outputs = await getKubernetesOutputsAsync(options, request);\n if (!outputs.ok) return outputs;\n return {\n ok: true,\n value: {\n resources: [\n ...prepared.value.projection.resources.map(({ owner }) => owner),\n ...reconciled.value,\n ],\n outputs: outputs.value,\n },\n diagnostics: [],\n };\n } catch {\n return createReconcileFailure();\n }\n}\n\n/*** Apply prepared changes while enforcing readiness-relevant dependency gates. */\nasync function applyKubernetesChangesAsync(\n options: KubernetesDriverOptions,\n request: KubernetesDriverRequest,\n changes: readonly KubernetesPreparedChange[],\n desiredByResourceId: ReadonlyMap<string, KubernetesDesiredResource>,\n deadline: number,\n): Promise<InfraResult<readonly InfraOwnedResource[]>> {\n const retained: InfraOwnedResource[] = [];\n for (const change of changes) {\n if (\n (change.action.operation === 'create' || change.action.operation === 'update') &&\n change.desired !== undefined\n ) {\n const dependencyFailure = await waitForDependenciesAsync(\n options,\n request,\n change.desired,\n desiredByResourceId,\n deadline,\n );\n if (dependencyFailure !== undefined) {\n return { ok: false, diagnostics: [dependencyFailure] };\n }\n await options.api.applyAsync(change.desired.resource, request.context.signal);\n }\n if (change.action.operation === 'delete' && change.actual !== undefined) {\n await options.api.deleteAsync(\n getKubernetesResourceReference(change.actual),\n request.context.signal,\n );\n }\n if (change.action.operation === 'retain' && change.actual !== undefined) {\n const owner = readKubernetesOwnedResource(change.actual, request);\n if (owner !== undefined) retained.push(owner);\n }\n }\n return { ok: true, value: retained, diagnostics: [] };\n}\n\n/*** Wait for readiness-relevant dependencies before applying one desired Kubernetes resource. */\nasync function waitForDependenciesAsync(\n options: KubernetesDriverOptions,\n request: KubernetesDriverRequest,\n desired: KubernetesDesiredResource,\n desiredByResourceId: ReadonlyMap<string, KubernetesDesiredResource>,\n deadline: number,\n): Promise<InfraDiagnostic | undefined> {\n for (const dependencyOwner of desired.owner.dependsOn) {\n const dependency = desiredByResourceId.get(dependencyOwner.resourceId);\n if (dependency === undefined || !KUBERNETES_READINESS_KINDS.has(dependency.resource.kind)) {\n continue;\n }\n const observation = await waitForDependencyAsync(options, request, dependency, deadline);\n if (observation.state !== 'ready') {\n return createDependencyReadinessDiagnostic(dependency, observation);\n }\n }\n return undefined;\n}\n\n/*** Wait for one dependency within the reconciliation pass shared readiness deadline. */\nfunction waitForDependencyAsync(\n options: KubernetesDriverOptions,\n request: KubernetesDriverRequest,\n dependency: KubernetesDesiredResource,\n deadline: number,\n): Promise<KubernetesResourceObservation> {\n const remainingSeconds = Math.max(0, Math.ceil((deadline - Date.now()) / 1_000));\n if (remainingSeconds === 0) {\n return Promise.resolve({\n state: 'degraded',\n detail: 'The shared Kubernetes readiness deadline expired.',\n });\n }\n return options.api.waitUntilReadyAsync(getKubernetesResourceReference(dependency.resource), {\n timeoutSeconds: remainingSeconds,\n ...(request.context.signal === undefined ? {} : { signal: request.context.signal }),\n });\n}\n\n/*** Create an actionable diagnostic for a dependency that did not become ready. */\nfunction createDependencyReadinessDiagnostic(\n dependency: KubernetesDesiredResource,\n observation: KubernetesResourceObservation,\n): InfraDiagnostic {\n const detail = observation.detail === undefined ? '' : ` ${observation.detail}`;\n return {\n severity: 'error',\n code: 'kubernetes-dependency-readiness-failed',\n message: `Kubernetes dependency ${dependency.owner.identity.resourceId} is ${observation.state}.${detail}`,\n owner: dependency.owner.identity,\n };\n}\n\n/*** Create the generic failure returned when reconciliation throws unexpectedly. */\nfunction createReconcileFailure(): InfraResult<InfraReconcileResult> {\n return {\n ok: false,\n diagnostics: [\n {\n severity: 'error',\n code: 'kubernetes-reconcile-failed',\n message: 'Kubernetes resources could not be reconciled safely.',\n },\n ],\n };\n}\n"]}
@@ -1 +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;AAiB5C,gFAAgF;AAChF,wBAAsB,+BAA+B,CACnD,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,WAAW,CAAC,SAAS,mBAAmB,EAAE,CAAC,CAAC,CA8BtD"}
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,CA8BtD"}
@@ -1,24 +1,17 @@
1
+ import { KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS, KUBERNETES_READINESS_KINDS, } from '../../constants';
1
2
  import { getKubernetesResourceReference } from '../../utils/getKubernetesResourceReference';
2
3
  import { projectKubernetesResourcesAsync } from './projectKubernetesResourcesAsync';
3
- const READINESS_KINDS = new Set([
4
- 'Namespace',
5
- 'PersistentVolumeClaim',
6
- 'Deployment',
7
- 'Service',
8
- 'Ingress',
9
- ]);
10
- const DEFAULT_READINESS_TIMEOUT_SECONDS = 300;
11
4
  /*** Wait dependency-first for required Kubernetes resources to report ready. */
12
5
  export async function waitForKubernetesReadinessAsync(options, request) {
13
6
  const projection = await projectKubernetesResourcesAsync(request);
14
7
  if (!projection.ok)
15
8
  return projection;
16
- const timeoutSeconds = options.defaultReadinessTimeoutSeconds ?? DEFAULT_READINESS_TIMEOUT_SECONDS;
9
+ const timeoutSeconds = options.defaultReadinessTimeoutSeconds ?? KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS;
17
10
  const deadline = Date.now() + timeoutSeconds * 1_000;
18
11
  try {
19
12
  const statuses = [];
20
13
  for (const desired of projection.value.resources) {
21
- if (!READINESS_KINDS.has(desired.resource.kind))
14
+ if (!KUBERNETES_READINESS_KINDS.has(desired.resource.kind))
22
15
  continue;
23
16
  const observation = await waitForDesiredResourceAsync(options, request, desired, deadline);
24
17
  statuses.push(createReadinessStatus(desired, observation));
@@ -1 +1 @@
1
- {"version":3,"file":"waitForKubernetesReadinessAsync.js","sourceRoot":"","sources":["../../../../../src/features/workload-reconciliation/application/use-cases/waitForKubernetesReadinessAsync.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,8BAA8B,EAAE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AM,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC;KAC5E,CAAC;AACJ,CAAC;AAED,sFAAsF;AACtF,SAAS,yBAAyB,CAChC,OAAkC,EAClC,WAA0C;IAE1C,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;IAChF,OAAO;QACL,QAAQ,EAAE,OAAO;QACjB,IAAI,EAAE,6BAA6B;QACnC,OAAO,EAAE,uBAAuB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,OAAO,WAAW,CAAC,KAAK,IAAI,MAAM,EAAE;QACrG,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import type { InfraDiagnostic, InfraResourceStatus, InfraResult } from '@ankhorage/contracts/infra';\n\nimport type {\n KubernetesDriverOptions,\n KubernetesDriverRequest,\n} from '../../../../types/kubernetesDriver';\nimport type {\n KubernetesDesiredResource,\n KubernetesResourceObservation,\n} from '../../../../types/kubernetesResources';\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]);\nconst DEFAULT_READINESS_TIMEOUT_SECONDS = 300;\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 const timeoutSeconds =\n options.defaultReadinessTimeoutSeconds ?? DEFAULT_READINESS_TIMEOUT_SECONDS;\n const deadline = Date.now() + timeoutSeconds * 1_000;\n try {\n const statuses: InfraResourceStatus[] = [];\n for (const desired of projection.value.resources) {\n if (!READINESS_KINDS.has(desired.resource.kind)) continue;\n const observation = await waitForDesiredResourceAsync(options, request, desired, deadline);\n statuses.push(createReadinessStatus(desired, observation));\n if (observation.state !== 'ready') {\n return { ok: false, diagnostics: [createReadinessDiagnostic(desired, observation)] };\n }\n }\n return { 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\n/*** Wait for one resource within the remaining shared readiness deadline. */\nasync function waitForDesiredResourceAsync(\n options: KubernetesDriverOptions,\n request: KubernetesDriverRequest,\n desired: KubernetesDesiredResource,\n deadline: number,\n): Promise<KubernetesResourceObservation> {\n const remainingSeconds = Math.max(0, Math.ceil((deadline - Date.now()) / 1_000));\n if (remainingSeconds === 0) {\n return {\n state: 'degraded',\n detail: 'The shared Kubernetes readiness deadline expired.',\n };\n }\n return options.api.waitUntilReadyAsync(getKubernetesResourceReference(desired.resource), {\n timeoutSeconds: remainingSeconds,\n ...(request.context.signal === undefined ? {} : { signal: request.context.signal }),\n });\n}\n\n/*** Map one observation to the resource status returned by the driver. */\nfunction createReadinessStatus(\n desired: KubernetesDesiredResource,\n observation: KubernetesResourceObservation,\n): InfraResourceStatus {\n return {\n owner: desired.owner.identity,\n state: observation.state,\n ...(observation.detail === undefined ? {} : { detail: observation.detail }),\n };\n}\n\n/*** Create the first actionable readiness diagnostic for dependency-first failure. */\nfunction createReadinessDiagnostic(\n desired: KubernetesDesiredResource,\n observation: KubernetesResourceObservation,\n): InfraDiagnostic {\n const detail = observation.detail === undefined ? '' : ` ${observation.detail}`;\n return {\n severity: 'error',\n code: 'kubernetes-readiness-failed',\n message: `Kubernetes resource ${desired.owner.identity.resourceId} is ${observation.state}.${detail}`,\n owner: desired.owner.identity,\n };\n}\n"]}
1
+ {"version":3,"file":"waitForKubernetesReadinessAsync.js","source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CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC;KAC5E,CAAC;AACJ,CAAC;AAED,sFAAsF;AACtF,SAAS,yBAAyB,CAChC,OAAkC,EAClC,WAA0C;IAE1C,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;IAChF,OAAO;QACL,QAAQ,EAAE,OAAO;QACjB,IAAI,EAAE,6BAA6B;QACnC,OAAO,EAAE,uBAAuB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,OAAO,WAAW,CAAC,KAAK,IAAI,MAAM,EAAE;QACrG,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import type { InfraDiagnostic, InfraResourceStatus, InfraResult } from '@ankhorage/contracts/infra';\n\nimport type {\n KubernetesDriverOptions,\n KubernetesDriverRequest,\n} from '../../../../types/kubernetesDriver';\nimport type {\n KubernetesDesiredResource,\n KubernetesResourceObservation,\n} from '../../../../types/kubernetesResources';\nimport {\n KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS,\n KUBERNETES_READINESS_KINDS,\n} from '../../constants';\nimport { getKubernetesResourceReference } from '../../utils/getKubernetesResourceReference';\nimport { projectKubernetesResourcesAsync } from './projectKubernetesResourcesAsync';\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 const timeoutSeconds =\n options.defaultReadinessTimeoutSeconds ?? KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS;\n const deadline = Date.now() + timeoutSeconds * 1_000;\n try {\n const statuses: InfraResourceStatus[] = [];\n for (const desired of projection.value.resources) {\n if (!KUBERNETES_READINESS_KINDS.has(desired.resource.kind)) continue;\n const observation = await waitForDesiredResourceAsync(options, request, desired, deadline);\n statuses.push(createReadinessStatus(desired, observation));\n if (observation.state !== 'ready') {\n return { ok: false, diagnostics: [createReadinessDiagnostic(desired, observation)] };\n }\n }\n return { 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\n/*** Wait for one resource within the remaining shared readiness deadline. */\nasync function waitForDesiredResourceAsync(\n options: KubernetesDriverOptions,\n request: KubernetesDriverRequest,\n desired: KubernetesDesiredResource,\n deadline: number,\n): Promise<KubernetesResourceObservation> {\n const remainingSeconds = Math.max(0, Math.ceil((deadline - Date.now()) / 1_000));\n if (remainingSeconds === 0) {\n return {\n state: 'degraded',\n detail: 'The shared Kubernetes readiness deadline expired.',\n };\n }\n return options.api.waitUntilReadyAsync(getKubernetesResourceReference(desired.resource), {\n timeoutSeconds: remainingSeconds,\n ...(request.context.signal === undefined ? {} : { signal: request.context.signal }),\n });\n}\n\n/*** Map one observation to the resource status returned by the driver. */\nfunction createReadinessStatus(\n desired: KubernetesDesiredResource,\n observation: KubernetesResourceObservation,\n): InfraResourceStatus {\n return {\n owner: desired.owner.identity,\n state: observation.state,\n ...(observation.detail === undefined ? {} : { detail: observation.detail }),\n };\n}\n\n/*** Create the first actionable readiness diagnostic for dependency-first failure. */\nfunction createReadinessDiagnostic(\n desired: KubernetesDesiredResource,\n observation: KubernetesResourceObservation,\n): InfraDiagnostic {\n const detail = observation.detail === undefined ? '' : ` ${observation.detail}`;\n return {\n severity: 'error',\n code: 'kubernetes-readiness-failed',\n message: `Kubernetes resource ${desired.owner.identity.resourceId} is ${observation.state}.${detail}`,\n owner: desired.owner.identity,\n };\n}\n"]}
@@ -11,4 +11,6 @@ export declare const KUBERNETES_OWNERSHIP: {
11
11
  readonly retentionAnnotation: "infra.ankhorage.dev/retention";
12
12
  readonly dependenciesAnnotation: "infra.ankhorage.dev/depends-on";
13
13
  };
14
+ export declare const KUBERNETES_READINESS_KINDS: ReadonlySet<string>;
15
+ export declare const KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS = 300;
14
16
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/features/workload-reconciliation/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;CAYvB,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/features/workload-reconciliation/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;CAYvB,CAAC;AAEX,eAAO,MAAM,0BAA0B,EAAE,WAAW,CAAC,MAAM,CAMzD,CAAC;AAEH,eAAO,MAAM,4CAA4C,MAAM,CAAC"}
@@ -11,4 +11,12 @@ export const KUBERNETES_OWNERSHIP = {
11
11
  retentionAnnotation: 'infra.ankhorage.dev/retention',
12
12
  dependenciesAnnotation: 'infra.ankhorage.dev/depends-on',
13
13
  };
14
+ export const KUBERNETES_READINESS_KINDS = new Set([
15
+ 'Namespace',
16
+ 'PersistentVolumeClaim',
17
+ 'Deployment',
18
+ 'Service',
19
+ 'Ingress',
20
+ ]);
21
+ export const KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS = 300;
14
22
  //# sourceMappingURL=constants.js.map
@@ -1 +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"]}
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;AAEX,MAAM,CAAC,MAAM,0BAA0B,GAAwB,IAAI,GAAG,CAAC;IACrE,WAAW;IACX,uBAAuB;IACvB,YAAY;IACZ,SAAS;IACT,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,4CAA4C,GAAG,GAAG,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\nexport const KUBERNETES_READINESS_KINDS: ReadonlySet<string> = new Set([\n 'Namespace',\n 'PersistentVolumeClaim',\n 'Deployment',\n 'Service',\n 'Ingress',\n]);\n\nexport const KUBERNETES_DEFAULT_READINESS_TIMEOUT_SECONDS = 300;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ankhorage/kubernetes",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Shared Kubernetes workload driver for provider-neutral Ankhorage infrastructure.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",