Fix kubeconfig-sync sometimes producing multiple identical entities

- This happens when there is an overlapping sync of a folder and a file
  within that folder both producing the same entities

- This also fixes the LED not showing up on some KubernetesCluster
  instances because of this duplication the connected status was being
  set on the first instance, but renderer would use the second (because
  JS's Map constructor deduplicates its constructor initializer by
  taking the last)

- Added some tests to cover this case

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2022-10-03 08:21:11 -04:00
1 parent 52b4c45e46
commit 8f3e851237
16 files changed
+657 -342

No files matched your search

@@ -0,0 +1,21 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { ClusterId } from "../cluster-types";
import type { Cluster } from "../cluster/cluster";
import clusterStoreInjectable from "./cluster-store.injectable";
export type GetClusterById = (id: ClusterId) => Cluster | undefined;
const getClusterByIdInjectable = getInjectable({
id: "get-cluster-by-id",
instantiate: (di): GetClusterById => {
const store = di.inject(clusterStoreInjectable);
return (id) => store.getById(id);
},
});
export default getClusterByIdInjectable;
+14
View File
@@ -0,0 +1,14 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { watch } from "chokidar";
const watchInjectable = getInjectable({
id: "watch",
instantiate: () => watch,
causesSideEffects: true,
});
export default watchInjectable;
@@ -0,0 +1,37 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import type { Logger } from "../logger";
import loggerInjectable from "../logger.injectable";
const childLoggerInjectable = getInjectable({
id: "child-logger",
instantiate: (di, prefix): Logger => {
const logger = di.inject(loggerInjectable);
return {
debug: (message, ...args) => {
logger.debug(`[${prefix}]: ${message}`, ...args);
},
error: (message, ...args) => {
logger.error(`[${prefix}]: ${message}`, ...args);
},
info: (message, ...args) => {
logger.info(`[${prefix}]: ${message}`, ...args);
},
silly: (message, ...args) => {
logger.silly(`[${prefix}]: ${message}`, ...args);
},
warn: (message, ...args) => {
logger.warn(`[${prefix}]: ${message}`, ...args);
},
};
},
lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, prefix: string) => prefix,
}),
});
export default childLoggerInjectable;
@@ -0,0 +1,17 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import userStoreInjectable from "./user-store.injectable";
const kubeconfigSyncsInjectable = getInjectable({
id: "kubeconfig-syncs",
instantiate: (di) => {
const store = di.inject(userStoreInjectable);
return store.syncKubeconfigEntries;
},
});
export default kubeconfigSyncsInjectable;
+2
View File
@@ -11,6 +11,7 @@ interface Iterator<T> {
find(fn: (val: T) => unknown): T | undefined;
collect<U>(fn: (values: Iterable<T>) => U): U;
map<U>(fn: (val: T) => U): Iterator<U>;
flatMap<U>(fn: (val: T) => U[]): Iterator<U>;
join(sep?: string): string;
}
@@ -19,6 +20,7 @@ export function pipeline<T>(src: IterableIterator<T>): Iterator<T> {
filter: (fn) => pipeline(filter(src, fn)),
filterMap: (fn) => pipeline(filterMap(src, fn)),
map: (fn) => pipeline(map(src, fn)),
flatMap: (fn) => pipeline(flatMap(src, fn)),
find: (fn) => find(src, fn),
join: (sep) => join(src, sep),
collect: (fn) => fn(src),