1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2020-10-24 10:30:25 +03:00
parent 999b09a167
commit 4f6a9a9a3d
4 changed files with 41 additions and 43 deletions

View File

@ -58,37 +58,31 @@ export class MetricsFeature extends ClusterFeature.Feature {
sc.metadata?.annotations?.['storageclass.beta.kubernetes.io/is-default-class'] === 'true' sc.metadata?.annotations?.['storageclass.beta.kubernetes.io/is-default-class'] === 'true'
)); ));
const template = super.renderTemplates(path.join(__dirname, "../resources/")) super.applyResources(cluster, super.renderTemplates(path.join(__dirname, "../resources/")))
console.log(template)
super.applyResources(cluster, template)
} }
async upgrade(cluster: Store.Cluster): Promise<void> { async upgrade(cluster: Store.Cluster): Promise<void> {
return this.install(cluster) return this.install(cluster)
} }
async featureStatus(cluster: Store.Cluster): Promise<ClusterFeature.FeatureStatus> { async updateStatus(cluster: Store.Cluster): Promise<ClusterFeature.FeatureStatus> {
const status: ClusterFeature.FeatureStatus = {
currentVersion: null,
installed: false,
latestVersion: this.latestVersion,
canUpgrade: false, // Dunno yet
};
try { try {
const statefulSet = K8sApi.forCluster(cluster, K8sApi.StatefulSet) const statefulSet = K8sApi.forCluster(cluster, K8sApi.StatefulSet)
const prometheus = await statefulSet.get({name: "prometheus", namespace: "lens-metrics"}) const prometheus = await statefulSet.get({name: "prometheus", namespace: "lens-metrics"})
console.log("prom", cluster)
if (prometheus?.kind) { if (prometheus?.kind) {
status.installed = true; this.status.installed = true;
status.currentVersion = prometheus.spec.template.spec.containers[0].image.split(":")[1]; this.status.currentVersion = prometheus.spec.template.spec.containers[0].image.split(":")[1];
status.canUpgrade = semver.lt(status.currentVersion, this.latestVersion, true); this.status.canUpgrade = semver.lt(this.status.currentVersion, this.latestVersion, true);
} else {
this.status.installed = false
}
} catch(e) {
if (e?.error?.code === 404) {
this.status.installed = false
} }
} catch {
// ignore error
} }
return status; return this.status
} }
async uninstall(cluster: Store.Cluster): Promise<void> { async uninstall(cluster: Store.Cluster): Promise<void> {

View File

@ -1,7 +1,6 @@
import type { ClusterId, ClusterModel, ClusterPreferences } from "../common/cluster-store" import type { ClusterId, ClusterModel, ClusterPreferences } from "../common/cluster-store"
import type { IMetricsReqParams } from "../renderer/api/endpoints/metrics.api"; import type { IMetricsReqParams } from "../renderer/api/endpoints/metrics.api";
import type { WorkspaceId } from "../common/workspace-store"; import type { WorkspaceId } from "../common/workspace-store";
import type { FeatureStatusMap } from "./feature"
import { action, computed, observable, reaction, toJS, when } from "mobx"; import { action, computed, observable, reaction, toJS, when } from "mobx";
import { apiKubePrefix } from "../common/vars"; import { apiKubePrefix } from "../common/vars";
import { broadcastIpc } from "../common/ipc"; import { broadcastIpc } from "../common/ipc";

View File

@ -1,21 +1,13 @@
import fs from "fs"; import fs from "fs";
import path from "path" import path from "path"
import hb from "handlebars" import hb from "handlebars"
import { observable } from "mobx"
import { ResourceApplier } from "./resource-applier" import { ResourceApplier } from "./resource-applier"
import { Cluster } from "./cluster"; import { Cluster } from "./cluster";
import logger from "./logger"; import logger from "./logger";
import { app, remote } from "electron" import { app } from "electron"
import { clusterIpc } from "../common/cluster-ipc" import { clusterIpc } from "../common/cluster-ipc"
export type FeatureStatusMap = Record<string, FeatureStatus>
export type FeatureMap = Record<string, Feature>
export interface FeatureInstallRequest {
clusterId: string;
name: string;
config?: any;
}
export interface FeatureStatus { export interface FeatureStatus {
currentVersion: string; currentVersion: string;
installed: boolean; installed: boolean;
@ -24,9 +16,16 @@ export interface FeatureStatus {
} }
export abstract class Feature { export abstract class Feature {
public name: string; name: string;
public latestVersion: string; latestVersion: string;
public config: any; config: any;
@observable status: FeatureStatus = {
currentVersion: null,
installed: false,
latestVersion: null,
canUpgrade: false
}
abstract async install(cluster: Cluster): Promise<void>; abstract async install(cluster: Cluster): Promise<void>;
@ -34,7 +33,7 @@ export abstract class Feature {
abstract async uninstall(cluster: Cluster): Promise<void>; abstract async uninstall(cluster: Cluster): Promise<void>;
abstract async featureStatus(cluster: Cluster): Promise<FeatureStatus>; abstract async updateStatus(cluster: Cluster): Promise<FeatureStatus>;
protected async applyResources(cluster: Cluster, resources: string[]) { protected async applyResources(cluster: Cluster, resources: string[]) {
if (app) { if (app) {

View File

@ -5,7 +5,8 @@ import { Cluster } from "../../../../main/cluster";
import { Button } from "../../button"; import { Button } from "../../button";
import { Notifications } from "../../notifications"; import { Notifications } from "../../notifications";
import { Spinner } from "../../spinner"; import { Spinner } from "../../spinner";
import { Feature, FeatureStatus } from "../../../../main/feature"; import { Feature } from "../../../../main/feature";
import { interval } from "../../../utils";
interface Props { interface Props {
cluster: Cluster cluster: Cluster
@ -15,14 +16,21 @@ interface Props {
@observer @observer
export class InstallFeature extends React.Component<Props> { export class InstallFeature extends React.Component<Props> {
@observable loading = false; @observable loading = false;
@observable status: FeatureStatus
componentDidMount() { componentDidMount() {
this.props.feature.featureStatus(this.props.cluster).then((status) => { const feature = this.props.feature
this.status = status const cluster = this.props.cluster
const statusUpdate = interval(20, () => {
feature.updateStatus(cluster)
}) })
statusUpdate.start(true)
disposeOnUnmount(this, () => {
statusUpdate.stop()
})
disposeOnUnmount(this, disposeOnUnmount(this,
reaction(() => this.status, () => { reaction(() => feature.status.installed, () => {
this.loading = false; this.loading = false;
}, { equals: comparer.structural }) }, { equals: comparer.structural })
); );
@ -32,11 +40,9 @@ export class InstallFeature extends React.Component<Props> {
const { cluster, feature } = this.props; const { cluster, feature } = this.props;
const disabled = !cluster.isAdmin || this.loading; const disabled = !cluster.isAdmin || this.loading;
const loadingIcon = this.loading ? <Spinner/> : null; const loadingIcon = this.loading ? <Spinner/> : null;
const features = this.status
if (!features) return null
return ( return (
<div className="flex gaps align-center"> <div className="flex gaps align-center">
{features.canUpgrade && {feature.status.canUpgrade &&
<Button <Button
primary primary
disabled={disabled} disabled={disabled}
@ -47,7 +53,7 @@ export class InstallFeature extends React.Component<Props> {
Upgrade Upgrade
</Button> </Button>
} }
{features.installed && {feature.status.installed &&
<Button <Button
accent accent
disabled={disabled} disabled={disabled}
@ -58,7 +64,7 @@ export class InstallFeature extends React.Component<Props> {
Uninstall Uninstall
</Button> </Button>
} }
{!features.installed && !features.canUpgrade && {!feature.status.installed && !feature.status.canUpgrade &&
<Button <Button
primary primary
disabled={disabled} disabled={disabled}