@oondemand/oon-core-back 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oondemand/oon-core-back",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/oondemand/oon-platform.git",
@@ -17,6 +17,14 @@ function randomSecret(bytes = 32) { return crypto.randomBytes(bytes).toString("b
17
17
  function dnsLabel(value, max = 63) {
18
18
  return String(value || "").toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, max).replace(/-+$/, "");
19
19
  }
20
+ function kubernetesLabelValue(value, max = 63) {
21
+ const source = String(value || "");
22
+ const normalized = dnsLabel(source, Number.MAX_SAFE_INTEGER) || "value";
23
+ if (normalized.length <= max) return normalized;
24
+ const digest = crypto.createHash("sha256").update(source).digest("hex").slice(0, 12);
25
+ const prefix = normalized.slice(0, max - digest.length - 1).replace(/-+$/, "");
26
+ return `${prefix}-${digest}`;
27
+ }
20
28
  function applyYaml(yaml) {
21
29
  const result = spawnSync("kubectl", ["apply", "-f", "-"], { input: yaml, encoding: "utf8", stdio: ["pipe", "inherit", "inherit"] });
22
30
  if (result.status !== 0) throw new Error("kubectl apply falhou.");
@@ -75,6 +83,8 @@ spec:
75
83
 
76
84
  function runtimeManifest({ context, infra, imageRef, profile = "small" }) {
77
85
  const resources = RESOURCE_PROFILES[profile] || RESOURCE_PROFILES.small;
86
+ const releaseLabel = kubernetesLabelValue(context.releaseId);
87
+ const releaseAnnotation = JSON.stringify(String(context.releaseId));
78
88
  return `apiVersion: apps/v1
79
89
  kind: Deployment
80
90
  metadata:
@@ -89,7 +99,9 @@ spec:
89
99
  labels:
90
100
  app.kubernetes.io/name: ${context.appCode}
91
101
  app.kubernetes.io/part-of: oon-central
92
- oon.dev/release-id: ${context.releaseId}
102
+ oon.dev/release-id: ${releaseLabel}
103
+ annotations:
104
+ oon.dev/release-id: ${releaseAnnotation}
93
105
  spec:
94
106
  serviceAccountName: oon-runtime
95
107
  imagePullSecrets: [{ name: ${infra.REGISTRY_PULL_SECRET_NAME || "ghcr-oon"} }]
@@ -280,4 +292,4 @@ async function activateMember(context) {
280
292
  return data;
281
293
  }
282
294
 
283
- module.exports = { RESOURCE_PROFILES, randomSecret, dnsLabel, provisionMongo, validateMongoUri, baselineManifest, runtimeManifest, provisionRuntime, deployRuntime, waitHttp, activateMember };
295
+ module.exports = { RESOURCE_PROFILES, randomSecret, dnsLabel, kubernetesLabelValue, provisionMongo, validateMongoUri, baselineManifest, runtimeManifest, provisionRuntime, deployRuntime, waitHttp, activateMember };