mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Refactor k8s api to common (#3553)
* refactor kube api to common Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor more utils to common Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor more utils to common Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * switch to use node-fetch on both sides Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * improve logger Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix lint errors Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix/improve tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix node-fetch require error on prod build Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * preload fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * read serverAddress from apiBase Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
476aa74101
commit
58a446bd45
250 files changed
+1244
-644
No files matched your search
@@ -25,7 +25,7 @@ import { HelmRepo, HelmRepoManager } from "./helm-repo-manager";
|
||||
import logger from "../logger";
|
||||
import { promiseExec } from "../promise-exec";
|
||||
import { helmCli } from "./helm-cli";
|
||||
import type { RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api";
|
||||
import type { RepoHelmChartList } from "../../common/k8s-api/endpoints/helm-charts.api";
|
||||
|
||||
type CachedYaml = {
|
||||
entries: RepoHelmChartList
|
||||
|
||||
@@ -24,7 +24,7 @@ import type { Cluster } from "../cluster";
|
||||
import logger from "../logger";
|
||||
import { HelmRepoManager } from "./helm-repo-manager";
|
||||
import { HelmChartManager } from "./helm-chart-manager";
|
||||
import type { HelmChart, HelmChartList, RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api";
|
||||
import type { HelmChart, HelmChartList, RepoHelmChartList } from "../../common/k8s-api/endpoints/helm-charts.api";
|
||||
import { deleteRelease, getHistory, getRelease, getValues, installChart, listReleases, rollback, upgradeRelease } from "./helm-release-manager";
|
||||
import { iter, sortCompareChartVersions } from "../../common/utils";
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
import request, { RequestPromiseOptions } from "request-promise-native";
|
||||
import { apiKubePrefix } from "../common/vars";
|
||||
import type { IMetricsReqParams } from "../renderer/api/endpoints/metrics.api";
|
||||
import type { IMetricsReqParams } from "../common/k8s-api/endpoints/metrics.api";
|
||||
import { LensProxy } from "./lens-proxy";
|
||||
import type { Cluster } from "./cluster";
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ export class LensProxy extends Singleton {
|
||||
});
|
||||
|
||||
this.port = port;
|
||||
process.env.LENS_PROXY_PORT = port.toString();
|
||||
resolve();
|
||||
})
|
||||
.once("error", (error) => {
|
||||
|
||||
+2
-91
@@ -19,95 +19,6 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { app, remote } from "electron";
|
||||
import winston from "winston";
|
||||
import Transport from "winston-transport";
|
||||
import { isDebugging, isTestEnv } from "../common/vars";
|
||||
import { LEVEL } from "triple-beam";
|
||||
import { Severity } from "@sentry/browser";
|
||||
import * as Sentry from "@sentry/electron";
|
||||
import logger from "../common/logger";
|
||||
|
||||
const SENTRY_LEVELS_MAP = {
|
||||
silly: Severity.Debug,
|
||||
verbose: Severity.Debug,
|
||||
debug: Severity.Debug,
|
||||
info: Severity.Info,
|
||||
warn: Severity.Warning,
|
||||
error: Severity.Error,
|
||||
};
|
||||
const WINSTON_CMP: Record<WinstonLevel, Set<WinstonLevel>> = {
|
||||
silly: new Set(["silly", "verbose", "debug", "info", "warn", "error"]),
|
||||
verbose: new Set(["verbose", "debug", "info", "warn", "error"]),
|
||||
debug: new Set(["debug", "info", "warn", "error"]),
|
||||
info: new Set(["info", "warn", "error"]),
|
||||
warn: new Set(["warn", "error"]),
|
||||
error: new Set(["error"]),
|
||||
};
|
||||
|
||||
type WinstonLevel = keyof typeof SENTRY_LEVELS_MAP;
|
||||
|
||||
class SentryTransport extends Transport {
|
||||
logLevels: Set<WinstonLevel>;
|
||||
|
||||
constructor(minWinstonLevel: WinstonLevel) {
|
||||
super();
|
||||
|
||||
this.logLevels = WINSTON_CMP[minWinstonLevel];
|
||||
}
|
||||
|
||||
log(info: any, next: () => void) {
|
||||
setImmediate(() => {
|
||||
this.emit("logged", info);
|
||||
});
|
||||
|
||||
const { message, level: _, tags, user, ...extra } = info;
|
||||
const winstonLevel: WinstonLevel = info[LEVEL];
|
||||
const level = SENTRY_LEVELS_MAP[winstonLevel];
|
||||
|
||||
try {
|
||||
if (this.logLevels.has(winstonLevel)) {
|
||||
Sentry.captureMessage(message, {
|
||||
level,
|
||||
tags,
|
||||
extra,
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface CreateLoggerOpts extends winston.LoggerOptions {
|
||||
transports?: Transport[];
|
||||
}
|
||||
|
||||
const logLevel = process.env.LOG_LEVEL || (isDebugging ? "debug" : "info");
|
||||
|
||||
const loggerOpts: CreateLoggerOpts = {
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.simple(),
|
||||
),
|
||||
transports: [
|
||||
new SentryTransport("error"),
|
||||
new winston.transports.Console({
|
||||
handleExceptions: false,
|
||||
level: logLevel,
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
if (!isTestEnv) {
|
||||
loggerOpts.transports.push(new winston.transports.File({
|
||||
handleExceptions: false,
|
||||
level: logLevel,
|
||||
filename: "lens.log",
|
||||
dirname: (app ?? remote?.app)?.getPath("logs"),
|
||||
maxsize: 16 * 1024,
|
||||
maxFiles: 16,
|
||||
tailable: true,
|
||||
}));
|
||||
}
|
||||
|
||||
export default winston.createLogger(loggerOpts);
|
||||
export default logger;
|
||||
@@ -31,6 +31,7 @@ import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
||||
import logger from "./logger";
|
||||
import { productName } from "../common/vars";
|
||||
import { LensProxy } from "./lens-proxy";
|
||||
import * as path from "path";
|
||||
|
||||
function isHideable(window: BrowserWindow | null): boolean {
|
||||
return Boolean(window && !window.isDestroyed());
|
||||
@@ -84,6 +85,7 @@ export class WindowManager extends Singleton {
|
||||
titleBarStyle: "hidden",
|
||||
backgroundColor: "#1e2124",
|
||||
webPreferences: {
|
||||
preload: path.join(__static, "build", "preload.js"),
|
||||
nodeIntegration: true,
|
||||
nodeIntegrationInSubFrames: true,
|
||||
enableRemoteModule: true,
|
||||
|
||||
Reference in new issue
Block a user