mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix integration test due to incorrect casting
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
97bf4ae129
commit
883bd36028
@ -5,25 +5,44 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { Patch } from "rfc6902";
|
import type { Patch } from "rfc6902";
|
||||||
import apiBaseInjectable from "../../api-base.injectable";
|
import apiBaseInjectable from "../../api-base.injectable";
|
||||||
|
import type { AsyncResult } from "../../../utils/async-result";
|
||||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||||
|
|
||||||
export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | undefined, patch: Patch) => Promise<KubeJsonApiData>;
|
export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | undefined, patch: Patch) => Promise<AsyncResult<KubeJsonApiData, string>>;
|
||||||
|
|
||||||
const requestKubeObjectPatchInjectable = getInjectable({
|
const requestKubeObjectPatchInjectable = getInjectable({
|
||||||
id: "request-kube-object-patch",
|
id: "request-kube-object-patch",
|
||||||
instantiate: (di): RequestKubeObjectPatch => {
|
instantiate: (di): RequestKubeObjectPatch => {
|
||||||
const apiBase = di.inject(apiBaseInjectable);
|
const apiBase = di.inject(apiBaseInjectable);
|
||||||
|
|
||||||
return (name, kind, ns, patch) => (
|
return async (name, kind, ns, patch) => {
|
||||||
apiBase.patch("/stack", {
|
const result = await apiBase.patch("/stack", {
|
||||||
data: {
|
data: {
|
||||||
name,
|
name,
|
||||||
kind,
|
kind,
|
||||||
ns,
|
ns,
|
||||||
patch,
|
patch,
|
||||||
},
|
},
|
||||||
})
|
}) as AsyncResult<string, string>;
|
||||||
);
|
|
||||||
|
if (!result.callWasSuccessful) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = JSON.parse(result.response);
|
||||||
|
|
||||||
|
return {
|
||||||
|
callWasSuccessful: true,
|
||||||
|
response,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: String(error),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -4,16 +4,37 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import apiBaseInjectable from "../../api-base.injectable";
|
import apiBaseInjectable from "../../api-base.injectable";
|
||||||
|
import type { AsyncResult } from "../../../utils/async-result";
|
||||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||||
|
|
||||||
export type RequestKubeObjectCreation = (resourceDescriptor: string) => Promise<KubeJsonApiData>;
|
export type RequestKubeObjectCreation = (resourceDescriptor: string) => Promise<AsyncResult<KubeJsonApiData, string>>;
|
||||||
|
|
||||||
const requestKubeObjectCreationInjectable = getInjectable({
|
const requestKubeObjectCreationInjectable = getInjectable({
|
||||||
id: "request-kube-object-creation",
|
id: "request-kube-object-creation",
|
||||||
instantiate: (di): RequestKubeObjectCreation => {
|
instantiate: (di): RequestKubeObjectCreation => {
|
||||||
const apiBase = di.inject(apiBaseInjectable);
|
const apiBase = di.inject(apiBaseInjectable);
|
||||||
|
|
||||||
return (data) => apiBase.post("/stack", { data });
|
return async (data) => {
|
||||||
|
const result = await apiBase.post("/stack", { data }) as AsyncResult<string, string>;
|
||||||
|
|
||||||
|
if (!result.callWasSuccessful) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = JSON.parse(result.response);
|
||||||
|
|
||||||
|
return {
|
||||||
|
callWasSuccessful: true,
|
||||||
|
response,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: String(error),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -645,8 +645,13 @@ export class KubeObject<
|
|||||||
}
|
}
|
||||||
|
|
||||||
const requestKubeObjectPatch = asLegacyGlobalFunctionForExtensionApi(requestKubeObjectPatchInjectable);
|
const requestKubeObjectPatch = asLegacyGlobalFunctionForExtensionApi(requestKubeObjectPatchInjectable);
|
||||||
|
const result = await requestKubeObjectPatch(this.getName(), this.kind, this.getNs(), patch);
|
||||||
|
|
||||||
return requestKubeObjectPatch(this.getName(), this.kind, this.getNs(), patch);
|
if (!result.callWasSuccessful) {
|
||||||
|
throw new Error(result.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -665,7 +670,13 @@ export class KubeObject<
|
|||||||
...data,
|
...data,
|
||||||
});
|
});
|
||||||
|
|
||||||
return requestKubeObjectCreation(descriptor);
|
const result = await requestKubeObjectCreation(descriptor);
|
||||||
|
|
||||||
|
if (!result.callWasSuccessful) {
|
||||||
|
throw new Error(result.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -9,13 +9,23 @@ import { loggerTransportInjectionToken } from "./logger/transports";
|
|||||||
|
|
||||||
const loggerInjectable = getInjectable({
|
const loggerInjectable = getInjectable({
|
||||||
id: "logger",
|
id: "logger",
|
||||||
instantiate: (di): Logger => createLogger({
|
instantiate: (di): Logger => {
|
||||||
|
const baseLogger = createLogger({
|
||||||
format: format.combine(
|
format: format.combine(
|
||||||
format.splat(),
|
format.splat(),
|
||||||
format.simple(),
|
format.simple(),
|
||||||
),
|
),
|
||||||
transports: di.injectMany(loggerTransportInjectionToken),
|
transports: di.injectMany(loggerTransportInjectionToken),
|
||||||
}),
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
debug: (message, ...data) => baseLogger.debug(message, ...data),
|
||||||
|
info: (message, ...data) => baseLogger.info(message, ...data),
|
||||||
|
warn: (message, ...data) => baseLogger.warn(message, ...data),
|
||||||
|
error: (message, ...data) => baseLogger.error(message, ...data),
|
||||||
|
silly: (message, ...data) => baseLogger.silly(message, ...data),
|
||||||
|
};
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default loggerInjectable;
|
export default loggerInjectable;
|
||||||
|
|||||||
@ -17,4 +17,6 @@ export interface Logger {
|
|||||||
/**
|
/**
|
||||||
* @deprecated use `di.inject(loggerInjectable)` instead
|
* @deprecated use `di.inject(loggerInjectable)` instead
|
||||||
*/
|
*/
|
||||||
export default asLegacyGlobalForExtensionApi(loggerInjectable);
|
const logger = asLegacyGlobalForExtensionApi(loggerInjectable);
|
||||||
|
|
||||||
|
export default logger;
|
||||||
|
|||||||
@ -13,8 +13,8 @@ import { observer } from "mobx-react";
|
|||||||
import type { CreateResourceTabStore } from "./store";
|
import type { CreateResourceTabStore } from "./store";
|
||||||
import { EditorPanel } from "../editor-panel";
|
import { EditorPanel } from "../editor-panel";
|
||||||
import { InfoPanel } from "../info-panel";
|
import { InfoPanel } from "../info-panel";
|
||||||
import { Notifications } from "../../notifications";
|
import type { ShowNotification } from "../../notifications";
|
||||||
import logger from "../../../../common/logger";
|
import type { Logger } from "../../../../common/logger";
|
||||||
import type { ApiManager } from "../../../../common/k8s-api/api-manager";
|
import type { ApiManager } from "../../../../common/k8s-api/api-manager";
|
||||||
import { isObject, prevDefault } from "../../../utils";
|
import { isObject, prevDefault } from "../../../utils";
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
@ -29,6 +29,10 @@ import getDetailsUrlInjectable from "../../kube-detail-params/get-details-url.in
|
|||||||
import navigateInjectable from "../../../navigation/navigate.injectable";
|
import navigateInjectable from "../../../navigation/navigate.injectable";
|
||||||
import type { RequestKubeObjectCreation } from "../../../../common/k8s-api/endpoints/resource-applier.api/request-update.injectable";
|
import type { RequestKubeObjectCreation } from "../../../../common/k8s-api/endpoints/resource-applier.api/request-update.injectable";
|
||||||
import requestKubeObjectCreationInjectable from "../../../../common/k8s-api/endpoints/resource-applier.api/request-update.injectable";
|
import requestKubeObjectCreationInjectable from "../../../../common/k8s-api/endpoints/resource-applier.api/request-update.injectable";
|
||||||
|
import loggerInjectable from "../../../../common/logger.injectable";
|
||||||
|
import type { ShowCheckedErrorNotification } from "../../notifications/show-checked-error.injectable";
|
||||||
|
import showSuccessNotificationInjectable from "../../notifications/show-success-notification.injectable";
|
||||||
|
import showCheckedErrorNotificationInjectable from "../../notifications/show-checked-error.injectable";
|
||||||
|
|
||||||
export interface CreateResourceProps {
|
export interface CreateResourceProps {
|
||||||
tabId: string;
|
tabId: string;
|
||||||
@ -38,9 +42,12 @@ interface Dependencies {
|
|||||||
createResourceTemplates: IComputedValue<GroupBase<{ label: string; value: string }>[]>;
|
createResourceTemplates: IComputedValue<GroupBase<{ label: string; value: string }>[]>;
|
||||||
createResourceTabStore: CreateResourceTabStore;
|
createResourceTabStore: CreateResourceTabStore;
|
||||||
apiManager: ApiManager;
|
apiManager: ApiManager;
|
||||||
|
logger: Logger;
|
||||||
navigate: Navigate;
|
navigate: Navigate;
|
||||||
getDetailsUrl: GetDetailsUrl;
|
getDetailsUrl: GetDetailsUrl;
|
||||||
requestKubeObjectCreation: RequestKubeObjectCreation;
|
requestKubeObjectCreation: RequestKubeObjectCreation;
|
||||||
|
showSuccessNotification: ShowNotification;
|
||||||
|
showCheckedErrorNotification: ShowCheckedErrorNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -81,34 +88,38 @@ class NonInjectedCreateResource extends React.Component<CreateResourceProps & De
|
|||||||
const resources = yaml.loadAll(this.data).filter(isObject);
|
const resources = yaml.loadAll(this.data).filter(isObject);
|
||||||
|
|
||||||
if (resources.length === 0) {
|
if (resources.length === 0) {
|
||||||
return void logger.info("Nothing to create");
|
return this.props.logger.info("Nothing to create");
|
||||||
}
|
}
|
||||||
|
|
||||||
const creatingResources = resources.map(async (resource) => {
|
const creatingResources = resources.map(async (resource) => {
|
||||||
try {
|
const result = await requestKubeObjectCreation(dump(resource));
|
||||||
const data = await requestKubeObjectCreation(dump(resource));
|
|
||||||
const { kind, apiVersion, metadata: { name, namespace }} = data;
|
|
||||||
|
|
||||||
const showDetails = () => {
|
if (!result.callWasSuccessful) {
|
||||||
|
this.props.logger.warn("Failed to create resource", { resource }, result.error);
|
||||||
|
this.props.showCheckedErrorNotification(result.error, "Unknown error occured while creating resources");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { kind, apiVersion, metadata: { name, namespace }} = result.response;
|
||||||
|
|
||||||
|
const close = this.props.showSuccessNotification((
|
||||||
|
<p>
|
||||||
|
{kind}
|
||||||
|
{" "}
|
||||||
|
<a
|
||||||
|
onClick={prevDefault(() => {
|
||||||
const resourceLink = apiManager.lookupApiLink({ kind, apiVersion, name, namespace });
|
const resourceLink = apiManager.lookupApiLink({ kind, apiVersion, name, namespace });
|
||||||
|
|
||||||
navigate(getDetailsUrl(resourceLink));
|
navigate(getDetailsUrl(resourceLink));
|
||||||
close();
|
close();
|
||||||
};
|
})}
|
||||||
|
>
|
||||||
const close = Notifications.ok(
|
|
||||||
<p>
|
|
||||||
{kind}
|
|
||||||
{" "}
|
|
||||||
<a onClick={prevDefault(showDetails)}>
|
|
||||||
{name}
|
{name}
|
||||||
</a>
|
</a>
|
||||||
{" successfully created."}
|
{" successfully created."}
|
||||||
</p>,
|
</p>
|
||||||
);
|
));
|
||||||
} catch (error) {
|
|
||||||
Notifications.checkedError(error, "Unknown error occured while creating resources");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.allSettled(creatingResources);
|
await Promise.allSettled(creatingResources);
|
||||||
@ -168,8 +179,11 @@ export const CreateResource = withInjectables<Dependencies, CreateResourceProps>
|
|||||||
createResourceTabStore: di.inject(createResourceTabStoreInjectable),
|
createResourceTabStore: di.inject(createResourceTabStoreInjectable),
|
||||||
createResourceTemplates: await di.inject(createResourceTemplatesInjectable),
|
createResourceTemplates: await di.inject(createResourceTemplatesInjectable),
|
||||||
apiManager: di.inject(apiManagerInjectable),
|
apiManager: di.inject(apiManagerInjectable),
|
||||||
|
logger: di.inject(loggerInjectable),
|
||||||
getDetailsUrl: di.inject(getDetailsUrlInjectable),
|
getDetailsUrl: di.inject(getDetailsUrlInjectable),
|
||||||
navigate: di.inject(navigateInjectable),
|
navigate: di.inject(navigateInjectable),
|
||||||
requestKubeObjectCreation: di.inject(requestKubeObjectCreationInjectable),
|
requestKubeObjectCreation: di.inject(requestKubeObjectCreationInjectable),
|
||||||
|
showSuccessNotification: di.inject(showSuccessNotificationInjectable),
|
||||||
|
showCheckedErrorNotification: di.inject(showCheckedErrorNotificationInjectable),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user