various configs refactoring/fixes, building project optimizations

This commit is contained in:
Roman committed 2020-06-15 16:09:10 +03:00
1 parent 9fd004b214
commit bfd1a4e0b8
20 files changed
+181 -118

No files matched your search

@@ -1,5 +1,5 @@
import { compile } from "path-to-regexp";
import { apiKubeHelm } from "../index";
import { apiHelm } from "../index";
import { stringify } from "querystring";
import { autobind } from "../../utils";
@@ -21,7 +21,7 @@ const endpoint = compile(`/v2/charts/:repo?/:name?`) as (params?: {
export const helmChartsApi = {
list() {
return apiKubeHelm
return apiHelm
.get<IHelmChartList>(endpoint())
.then(data => {
return Object
@@ -33,7 +33,7 @@ export const helmChartsApi = {
get(repo: string, name: string, readmeVersion?: string) {
const path = endpoint({ repo, name });
return apiKubeHelm
return apiHelm
.get<IHelmChartDetails>(path + "?" + stringify({ version: readmeVersion }))
.then(data => {
const versions = data.versions.map(HelmChart.create);
@@ -46,7 +46,7 @@ export const helmChartsApi = {
},
getValues(repo: string, name: string, version: string) {
return apiKubeHelm
return apiHelm
.get<string>(`/v2/charts/${repo}/${name}/values?` + stringify({ version }));
}
};
@@ -2,7 +2,7 @@ import jsYaml from "js-yaml";
import { compile } from "path-to-regexp";
import { autobind, formatDuration } from "../../utils";
import capitalize from "lodash/capitalize";
import { apiKubeHelm } from "../index";
import { apiHelm } from "../index";
import { helmChartStore } from "../../components/+apps-helm-charts/helm-chart.store";
import { ItemObject } from "../../item.store";
import { KubeObject } from "../kube-object";
@@ -69,14 +69,14 @@ const endpoint = compile(`/v2/releases/:namespace?/:name?`) as (
export const helmReleasesApi = {
list(namespace?: string) {
return apiKubeHelm
return apiHelm
.get<HelmRelease[]>(endpoint({ namespace }))
.then(releases => releases.map(HelmRelease.create));
},
get(name: string, namespace: string) {
const path = endpoint({ name, namespace });
return apiKubeHelm.get<IReleaseRawDetails>(path).then(details => {
return apiHelm.get<IReleaseRawDetails>(path).then(details => {
const items: KubeObject[] = JSON.parse(details.resources).items;
const resources = items.map(item => KubeObject.create(item));
return {
@@ -90,34 +90,34 @@ export const helmReleasesApi = {
const { repo, ...data } = payload;
data.chart = `${repo}/${data.chart}`;
data.values = jsYaml.safeLoad(data.values);
return apiKubeHelm.post(endpoint(), { data });
return apiHelm.post(endpoint(), { data });
},
update(name: string, namespace: string, payload: IReleaseUpdatePayload): Promise<IReleaseUpdateDetails> {
const { repo, ...data } = payload;
data.chart = `${repo}/${data.chart}`;
data.values = jsYaml.safeLoad(data.values);
return apiKubeHelm.put(endpoint({ name, namespace }), { data });
return apiHelm.put(endpoint({ name, namespace }), { data });
},
async delete(name: string, namespace: string) {
const path = endpoint({ name, namespace });
return apiKubeHelm.del(path);
return apiHelm.del(path);
},
getValues(name: string, namespace: string) {
const path = endpoint({ name, namespace }) + "/values";
return apiKubeHelm.get<string>(path);
return apiHelm.get<string>(path);
},
getHistory(name: string, namespace: string): Promise<IReleaseRevision[]> {
const path = endpoint({ name, namespace }) + "/history";
return apiKubeHelm.get(path);
return apiHelm.get(path);
},
rollback(name: string, namespace: string, revision: number) {
const path = endpoint({ name, namespace }) + "/rollback";
return apiKubeHelm.put(path, {
return apiHelm.put(path, {
data: {
revision: revision
}
@@ -1,7 +1,7 @@
import jsYaml from "js-yaml"
import { KubeObject } from "../kube-object";
import { KubeJsonApiData } from "../kube-json-api";
import { apiKubeResourceApplier } from "../index";
import { apiResourceApplier } from "../index";
import { apiManager } from "../api-manager";
export const resourceApplierApi = {
@@ -13,7 +13,7 @@ export const resourceApplierApi = {
if (typeof resource === "string") {
resource = jsYaml.safeLoad(resource);
}
return apiKubeResourceApplier
return apiResourceApplier
.post<KubeJsonApiData[]>("/stack", { data: resource })
.then(data => {
const items = data.map(obj => {
+4 -9
View File
@@ -13,15 +13,11 @@ export const apiKube = new KubeJsonApi({
debug: isDevelopment,
apiPrefix: apiPrefix.KUBE_BASE,
});
export const apiKubeUsers = new KubeJsonApi({
debug: isDevelopment,
apiPrefix: apiPrefix.KUBE_USERS,
});
export const apiKubeHelm = new KubeJsonApi({
export const apiHelm = new KubeJsonApi({
debug: isDevelopment,
apiPrefix: apiPrefix.KUBE_HELM,
});
export const apiKubeResourceApplier = new KubeJsonApi({
export const apiResourceApplier = new KubeJsonApi({
debug: isDevelopment,
apiPrefix: apiPrefix.KUBE_RESOURCE_APPLIER,
});
@@ -38,6 +34,5 @@ function onApiError(error: JsonApiErrorParsed, res: Response) {
apiBase.onError.addListener(onApiError);
apiKube.onError.addListener(onApiError);
apiKubeUsers.onError.addListener(onApiError);
apiKubeHelm.onError.addListener(onApiError);
apiKubeResourceApplier.onError.addListener(onApiError);
apiHelm.onError.addListener(onApiError);
apiResourceApplier.onError.addListener(onApiError);
+3 -3
View File
@@ -8,6 +8,7 @@ import { KubeObjectStore } from "../kube-object.store";
import { KubeApi } from "./kube-api";
import { configStore } from "../config.store";
import { apiManager } from "./api-manager";
import { apiPrefix, isDevelopment } from "../../common/vars";
export interface IKubeWatchEvent<T = any> {
type: "ADDED" | "MODIFIED" | "DELETED";
@@ -28,9 +29,8 @@ export interface IKubeWatchRouteQuery {
export class KubeWatchApi {
protected evtSource: EventSource;
protected onData = new EventEmitter<[IKubeWatchEvent]>();
protected apiUrl = configStore.apiPrefix.BASE + "/watch";
protected apiUrl = apiPrefix.BASE + "/watch";
protected subscribers = observable.map<KubeApi, number>();
protected reconnectInterval = interval(60 * 5, this.reconnect); // background reconnect every 5min
protected reconnectTimeoutMs = 5000;
protected maxReconnectsOnError = 10;
protected reconnectAttempts = this.maxReconnectsOnError;
@@ -138,7 +138,7 @@ export class KubeWatchApi {
}
protected writeLog(...data: any[]) {
if (configStore.isDevelopment) {
if (isDevelopment) {
console.log('%cKUBE-WATCH-API:', `font-weight: bold`, ...data);
}
}
+8 -5
View File
@@ -3,6 +3,7 @@ import { autobind, base64, EventEmitter, interval } from "../utils";
import { WebSocketApi } from "./websocket-api";
import { configStore } from "../config.store";
import isEqual from "lodash/isEqual"
import { apiPrefix, isDevelopment } from "../../common/vars";
export enum TerminalChannels {
STDIN = 0,
@@ -40,26 +41,28 @@ export class TerminalApi extends WebSocketApi {
constructor(protected options: ITerminalApiOptions) {
super({
logging: configStore.isDevelopment,
logging: isDevelopment,
flushOnOpen: false,
pingIntervalSeconds: 30,
});
}
async getUrl(token: string) {
const { hostname, protocol } = location;
var { hostname, protocol, port } = location;
const prefix = apiPrefix.TERMINAL;
const { id, node } = this.options;
const apiPrefix = configStore.apiPrefix.TERMINAL;
const wss = `ws${protocol === "https:" ? "s" : ""}://`;
const queryParams = { token, id };
if (port) {
port = `:${port}`
}
if (node) {
Object.assign(queryParams, {
node: node,
type: "node"
});
}
return `${wss}${hostname}${configStore.serverPort}${apiPrefix}/api?${stringify(queryParams)}`;
return `${wss}${hostname}${port}${prefix}/api?${stringify(queryParams)}`;
}
async connect() {
@@ -5,9 +5,9 @@ import { reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react";
import { t, Trans } from "@lingui/macro";
import { Button } from "../button";
import { configStore } from "../../config.store";
import { navigation } from "../../navigation";
import { _i18n } from "../../i18n";
import { issuesTrackerUrl, slackUrl, buildVersion } from "../../../common/vars";
interface Props {
}
@@ -38,14 +38,14 @@ export class ErrorBoundary extends React.Component<Props, State> {
render() {
const { error, errorInfo } = this.state;
if (error) {
const slackLink = <a href="https://join.slack.com/t/k8slens/shared_invite/enQtOTc5NjAyNjYyOTk4LWU1NDQ0ZGFkOWJkNTRhYTc2YjVmZDdkM2FkNGM5MjhiYTRhMDU2NDQ1MzIyMDA4ZGZlNmExOTc0N2JmY2M3ZGI" target="_blank">Slack</a>
const githubLink = <a href="https://github.com/lensapp/lens/issues" target="_blank">Github</a>
const slackLink = <a href={slackUrl} target="_blank">Slack</a>
const githubLink = <a href={issuesTrackerUrl} target="_blank">Github</a>
const pageUrl = location.href;
return (
<div className="ErrorBoundary flex column gaps">
<h5>
<Trans>App crash at <span className="contrast">{pageUrl}</span></Trans>
{configStore.buildVersion && <p><Trans>Build version</Trans>: {configStore.buildVersion}</p>}
{buildVersion && <p><Trans>Build version</Trans>: {buildVersion}</p>}
</h5>
<p>
<Trans>
-10
View File
@@ -1,15 +1,10 @@
import { observable, when } from "mobx";
import type { IConfigRoutePayload } from "../main/routes/config";
import { apiPrefix, buildVersion, isDevelopment } from "../common/vars";
import { autobind, interval } from "./utils";
import { configApi } from "./api/endpoints";
@autobind()
export class ConfigStore {
readonly isDevelopment = isDevelopment;
readonly buildVersion = buildVersion;
readonly apiPrefix = apiPrefix;
protected updater = interval(60, this.load);
@observable config: Partial<IConfigRoutePayload> = {};
@@ -32,11 +27,6 @@ export class ConfigStore {
return this.config.token;
}
get serverPort() {
const port = location.port;
return port ? `:${port}` : "";
}
get allowedNamespaces() {
return this.config.allowedNamespaces || [];
}