1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Make node shell image configurable (#3249)

Signed-off-by: vshakirova <vshakirova@mirantis.com>
This commit is contained in:
Violetta Shakirova 2021-07-12 19:21:46 +04:00 committed by GitHub
parent 26fb2e796e
commit 621f5ba0b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 153 additions and 1 deletions

View File

@ -101,6 +101,8 @@ export interface ClusterPreferences extends ClusterPrometheusPreferences {
icon?: string; icon?: string;
httpsProxy?: string; httpsProxy?: string;
hiddenMetrics?: string[]; hiddenMetrics?: string[];
nodeShellImage?: string;
imagePullSecret?: string;
} }
export interface ClusterPrometheusPreferences { export interface ClusterPrometheusPreferences {
@ -117,6 +119,8 @@ export interface ClusterPrometheusPreferences {
const initialStates = "cluster:states"; const initialStates = "cluster:states";
export const initialNodeShellImage = "docker.io/alpine:3.13";
export class ClusterStore extends BaseStore<ClusterStoreModel> { export class ClusterStore extends BaseStore<ClusterStoreModel> {
private static StateChannel = "cluster:state"; private static StateChannel = "cluster:state";

View File

@ -34,6 +34,7 @@ import { VersionDetector } from "./cluster-detectors/version-detector";
import { detectorRegistry } from "./cluster-detectors/detector-registry"; import { detectorRegistry } from "./cluster-detectors/detector-registry";
import plimit from "p-limit"; import plimit from "p-limit";
import { toJS } from "../common/utils"; import { toJS } from "../common/utils";
import { initialNodeShellImage } from "../common/cluster-store";
export enum ClusterStatus { export enum ClusterStatus {
AccessGranted = 2, AccessGranted = 2,
@ -745,4 +746,12 @@ export class Cluster implements ClusterModel, ClusterState {
isMetricHidden(resource: ClusterMetricsResourceType): boolean { isMetricHidden(resource: ClusterMetricsResourceType): boolean {
return Boolean(this.preferences.hiddenMetrics?.includes(resource)); return Boolean(this.preferences.hiddenMetrics?.includes(resource));
} }
get nodeShellImage(): string {
return this.preferences.nodeShellImage || initialNodeShellImage;
}
get imagePullSecret(): string {
return this.preferences.imagePullSecret || "";
}
} }

View File

@ -77,13 +77,16 @@ export class NodeShellSession extends ShellSession {
}], }],
containers: [{ containers: [{
name: "shell", name: "shell",
image: "docker.io/alpine:3.13", image: this.cluster.nodeShellImage,
securityContext: { securityContext: {
privileged: true, privileged: true,
}, },
command: ["nsenter"], command: ["nsenter"],
args: ["-t", "1", "-m", "-u", "-i", "-n", "sleep", "14000"] args: ["-t", "1", "-m", "-u", "-i", "-n", "sleep", "14000"]
}], }],
imagePullSecrets: [{
name: this.cluster.imagePullSecret,
}]
} }
}); });
} }

View File

@ -118,3 +118,17 @@ export function MetricsSettings({ entity }: EntitySettingViewProps) {
</section> </section>
); );
} }
export function NodeShellSettings({entity}: EntitySettingViewProps) {
const cluster = getClusterForEntity(entity);
if(!cluster) {
return null;
}
return (
<section>
<components.ClusterNodeShellSetting cluster={cluster} />
</section>
);
}

View File

@ -0,0 +1,112 @@
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import type { Cluster } from "../../../../main/cluster";
import { autorun, makeObservable, observable } from "mobx";
import { SubTitle } from "../../layout/sub-title";
import React from "react";
import { Input } from "../../input/input";
import { disposeOnUnmount, observer } from "mobx-react";
import { Icon } from "../../icon/icon";
import { initialNodeShellImage } from "../../../../common/cluster-store";
interface Props {
cluster: Cluster;
}
@observer
export class ClusterNodeShellSetting extends React.Component<Props> {
@observable nodeShellImage = "";
@observable imagePullSecret = "";
constructor(props: Props) {
super(props);
makeObservable(this);
}
componentDidMount() {
disposeOnUnmount(this,
autorun(() => {
this.nodeShellImage = this.props.cluster.nodeShellImage;
this.imagePullSecret = this.props.cluster.imagePullSecret;
})
);
}
onImageChange = (value: string) => {
this.nodeShellImage = value;
};
onSecretChange = (value: string) => {
this.imagePullSecret = value;
};
saveImage = () => {
this.props.cluster.preferences.nodeShellImage = this.nodeShellImage;
};
saveSecret = () => {
this.props.cluster.preferences.imagePullSecret = this.imagePullSecret;
};
resetImage = () => {
this.nodeShellImage = initialNodeShellImage; //revert to default
};
clearSecret = () => {
this.imagePullSecret = "";
};
render() {
return (
<>
<section>
<SubTitle title="Node shell image" id="node-shell-image"/>
<Input
theme="round-black"
value={this.nodeShellImage}
onChange={this.onImageChange}
onBlur={this.saveImage}
iconRight={<Icon small material="close" onClick={this.resetImage} tooltip="Reset"/>}
/>
<small className="hint">
Node shell image. Used for creating node shell pod.
</small>
</section>
<section>
<SubTitle title="Image pull secret" id="image-pull-secret"/>
<Input
placeholder={"Add a secret name..."}
theme="round-black"
value={this.imagePullSecret}
onChange={this.onSecretChange}
onBlur={this.saveSecret}
iconRight={<Icon small material="close" onClick={this.clearSecret} tooltip="Clear"/>}
/>
<small className="hint">
Name of a pre-existing secret (optional). Used for pulling image from a private registry.
</small>
</section>
</>
);
}
}

View File

@ -28,3 +28,4 @@ export * from "./cluster-prometheus-setting";
export * from "./cluster-proxy-setting"; export * from "./cluster-proxy-setting";
export * from "./cluster-show-metrics"; export * from "./cluster-show-metrics";
export * from "./cluster-icon-settings"; export * from "./cluster-icon-settings";
export * from "./cluster-node-shell-setting";

View File

@ -70,6 +70,15 @@ export function initEntitySettingsRegistry() {
components: { components: {
View: clusterSettings.MetricsSettings, View: clusterSettings.MetricsSettings,
} }
},
{
apiVersions: ["entity.k8slens.dev/v1alpha1"],
kind: "KubernetesCluster",
title: "Node Shell",
group: "Settings",
components: {
View: clusterSettings.NodeShellSettings,
}
} }
]); ]);
} }