1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/kubectl/delete-all-handler.injectable.ts
Sebastian Malton 6142aad5ab
Make ResourceStack fully injectable (#6591)
Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-11-24 08:46:53 -05:00

40 lines
1.4 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import emitAppEventInjectable from "../../common/app-event-bus/emit-event.injectable";
import getClusterByIdInjectable from "../../common/cluster-store/get-by-id.injectable";
import { kubectlDeleteAllChannel } from "../../common/kube-helpers/channels";
import createResourceApplierInjectable from "../resource-applier/create-resource-applier.injectable";
import { getRequestChannelListenerInjectable } from "../utils/channel/channel-listeners/listener-tokens";
const kubectlDeleteAllChannelHandlerInjectable = getRequestChannelListenerInjectable({
channel: kubectlDeleteAllChannel,
handler: (di) => {
const emitAppEvent = di.inject(emitAppEventInjectable);
const getClusterById = di.inject(getClusterByIdInjectable);
const createResourceApplier = di.inject(createResourceApplierInjectable);
return async ({
clusterId,
extraArgs,
resources,
}) => {
emitAppEvent({ name: "cluster", action: "kubectl-delete-all" });
const cluster = getClusterById(clusterId);
if (!cluster) {
return {
callWasSuccessful: false,
error: `No cluster found for clusterId="${clusterId}"`,
};
}
return createResourceApplier(cluster).kubectlDeleteAll(resources, extraArgs);
};
},
});
export default kubectlDeleteAllChannelHandlerInjectable;