pepr 0.47.0-nightly.9 → 0.48.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/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "!src/fixtures/**",
17
17
  "!dist/**/*.test.d.ts*"
18
18
  ],
19
- "version": "0.47.0-nightly.9",
19
+ "version": "0.48.0",
20
20
  "main": "dist/lib.js",
21
21
  "types": "dist/lib.d.ts",
22
22
  "scripts": {
@@ -54,7 +54,7 @@
54
54
  "heredoc": "^1.3.1",
55
55
  "http-status-codes": "^2.3.0",
56
56
  "json-pointer": "^0.6.2",
57
- "kubernetes-fluent-client": "3.4.7",
57
+ "kubernetes-fluent-client": "3.4.10",
58
58
  "pino": "9.6.0",
59
59
  "pino-pretty": "13.0.0",
60
60
  "prom-client": "15.1.3",
@@ -97,4 +97,4 @@
97
97
  "typescript": "5.7.3",
98
98
  "uuid": "11.0.5"
99
99
  }
100
- }
100
+ }
@@ -0,0 +1,56 @@
1
+ import { DataStore, Storage } from "../core/storage";
2
+ import { startsWith } from "ramda";
3
+ import Log, { redactedStore } from "../telemetry/logger";
4
+ import { K8s } from "kubernetes-fluent-client";
5
+ import { Store } from "../k8s";
6
+ import { Operation } from "fast-json-patch";
7
+ import { fillStoreCache, sendUpdatesAndFlushCache } from "./storeCache";
8
+
9
+ export interface StoreMigration {
10
+ name: string;
11
+ namespace: string;
12
+ store: Store;
13
+ stores: Record<string, Storage>;
14
+ setupWatch: () => void;
15
+ }
16
+
17
+ export async function migrateAndSetupWatch(storeData: StoreMigration): Promise<void> {
18
+ const { store, namespace, name, stores, setupWatch } = storeData;
19
+
20
+ Log.debug(redactedStore(store), "Pepr Store migration");
21
+ // Add cacheID label to store
22
+ await K8s(Store, { namespace, name }).Patch([
23
+ {
24
+ op: "add",
25
+ path: "/metadata/labels/pepr.dev-cacheID",
26
+ value: `${Date.now()}`,
27
+ },
28
+ ]);
29
+
30
+ const data: DataStore = store.data;
31
+ let storeCache: Record<string, Operation> = {};
32
+
33
+ for (const name of Object.keys(stores)) {
34
+ // Get the prefix offset for the keys
35
+ const offset = `${name}-`.length;
36
+
37
+ // Loop over each key in the store
38
+ for (const key of Object.keys(data)) {
39
+ // Match on the capability name as a prefix for non v2 keys
40
+ if (startsWith(name, key) && !startsWith(`${name}-v2`, key)) {
41
+ // populate migrate cache
42
+ storeCache = fillStoreCache(storeCache, name, "remove", {
43
+ key: [key.slice(offset)],
44
+ value: data[key],
45
+ });
46
+ storeCache = fillStoreCache(storeCache, name, "add", {
47
+ key: [key.slice(offset)],
48
+ value: data[key],
49
+ version: "v2",
50
+ });
51
+ }
52
+ }
53
+ }
54
+ storeCache = await sendUpdatesAndFlushCache(storeCache, namespace, name);
55
+ setupWatch();
56
+ }
@@ -10,6 +10,7 @@ import { Store } from "../k8s";
10
10
  import Log, { redactedPatch, redactedStore } from "../telemetry/logger";
11
11
  import { DataOp, DataSender, DataStore, Storage } from "../core/storage";
12
12
  import { fillStoreCache, sendUpdatesAndFlushCache } from "./storeCache";
13
+ import { migrateAndSetupWatch } from "./migrateStore";
13
14
 
14
15
  const namespace = "pepr-system";
15
16
  const debounceBackoffReceive = 1000;
@@ -56,7 +57,16 @@ export class StoreController {
56
57
  K8s(Store)
57
58
  .InNamespace(namespace)
58
59
  .Get(this.#name)
59
- .then(async (store: Store) => await this.#migrateAndSetupWatch(store))
60
+ .then(
61
+ async (store: Store) =>
62
+ await migrateAndSetupWatch({
63
+ name,
64
+ namespace,
65
+ store,
66
+ stores: this.#stores,
67
+ setupWatch: this.#setupWatch,
68
+ }),
69
+ )
60
70
  .catch(this.#createStoreResource),
61
71
  Math.random() * 3000, // Add a jitter to the Store creation to avoid collisions
62
72
  );
@@ -67,45 +77,6 @@ export class StoreController {
67
77
  watcher.start().catch(e => Log.error(e, "Error starting Pepr store watch"));
68
78
  };
69
79
 
70
- #migrateAndSetupWatch = async (store: Store): Promise<void> => {
71
- Log.debug(redactedStore(store), "Pepr Store migration");
72
- // Add cacheID label to store
73
- await K8s(Store, { namespace, name: this.#name }).Patch([
74
- {
75
- op: "add",
76
- path: "/metadata/labels/pepr.dev-cacheID",
77
- value: `${Date.now()}`,
78
- },
79
- ]);
80
-
81
- const data: DataStore = store.data || {};
82
- let storeCache: Record<string, Operation> = {};
83
-
84
- for (const name of Object.keys(this.#stores)) {
85
- // Get the prefix offset for the keys
86
- const offset = `${name}-`.length;
87
-
88
- // Loop over each key in the store
89
- for (const key of Object.keys(data)) {
90
- // Match on the capability name as a prefix for non v2 keys
91
- if (startsWith(name, key) && !startsWith(`${name}-v2`, key)) {
92
- // populate migrate cache
93
- storeCache = fillStoreCache(storeCache, name, "remove", {
94
- key: [key.slice(offset)],
95
- value: data[key],
96
- });
97
- storeCache = fillStoreCache(storeCache, name, "add", {
98
- key: [key.slice(offset)],
99
- value: data[key],
100
- version: "v2",
101
- });
102
- }
103
- }
104
- }
105
- storeCache = await sendUpdatesAndFlushCache(storeCache, namespace, this.#name);
106
- this.#setupWatch();
107
- };
108
-
109
80
  #receive = (store: Store): void => {
110
81
  Log.debug(redactedStore(store), "Pepr Store update");
111
82