Fix behaviour of auto generated CRD KubeApis and KubeObjectStores (#7384)

* Simplify CRD KubeApi registrations

- Switch to auto injectable registrations

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Make sure that stores can still be retrieved

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Cleanup get extension fake to simplify impl

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Simplify logic for extensionInjectable

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix test in differencing registrator

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Cleanup code style

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix some tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix HPA details tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

---------

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2023-03-22 17:51:26 +02:00
1 parent 8a80607d85
commit 4b1d740d61
17 files changed
+315 -189

No files matched your search

@@ -0,0 +1,25 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { iter } from "@k8slens/utilities";
import type { DiContainerForInjection, Injectable } from "@ogre-tools/injectable";
// Register new injectables and deregister removed injectables by id
export const injectableDifferencingRegistratorWith = (di: DiContainerForInjection) => (
(rawCurrent: Injectable<any, any, any>[], rawPrevious: Injectable<any, any, any>[] = []) => {
const current = new Map(rawCurrent.map(inj => [inj.id, inj]));
const previous = new Map(rawPrevious.map(inj => [inj.id, inj]));
const toAdd = iter.chain(current.entries())
.filter(([id]) => !previous.has(id))
.collect(entries => new Map(entries));
const toRemove = iter.chain(previous.entries())
.filter(([id]) => !current.has(id))
.collect(entries => new Map(entries));
di.deregister(...toRemove.values());
di.register(...toAdd.values());
}
);