mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix node shell secret pulling (#3668)
- On some KE errors are thrown if trying to get a secret with an empty name, instead of just ignoring the entry - Clean up the node shell settings Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
36b64f73bc
commit
d132a4c7e7
@ -706,10 +706,10 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get nodeShellImage(): string {
|
get nodeShellImage(): string {
|
||||||
return this.preferences.nodeShellImage || initialNodeShellImage;
|
return this.preferences?.nodeShellImage || initialNodeShellImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
get imagePullSecret(): string {
|
get imagePullSecret(): string | undefined {
|
||||||
return this.preferences.imagePullSecret || "";
|
return this.preferences?.imagePullSecret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import * as k8s from "@kubernetes/client-node";
|
|||||||
import type { KubeConfig } from "@kubernetes/client-node";
|
import type { KubeConfig } from "@kubernetes/client-node";
|
||||||
import type { Cluster } from "../cluster";
|
import type { Cluster } from "../cluster";
|
||||||
import { ShellOpenError, ShellSession } from "./shell-session";
|
import { ShellOpenError, ShellSession } from "./shell-session";
|
||||||
|
import { get } from "lodash";
|
||||||
|
|
||||||
export class NodeShellSession extends ShellSession {
|
export class NodeShellSession extends ShellSession {
|
||||||
ShellType = "node-shell";
|
ShellType = "node-shell";
|
||||||
@ -49,7 +50,7 @@ export class NodeShellSession extends ShellSession {
|
|||||||
await this.waitForRunningPod();
|
await this.waitForRunningPod();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.deleteNodeShellPod();
|
this.deleteNodeShellPod();
|
||||||
this.sendResponse("Error occurred. ");
|
this.sendResponse(`Error occurred: ${get(error, "response.body.message", error?.toString() || "unknown error")}`);
|
||||||
|
|
||||||
throw new ShellOpenError("failed to create node pod", error);
|
throw new ShellOpenError("failed to create node pod", error);
|
||||||
}
|
}
|
||||||
@ -57,10 +58,16 @@ export class NodeShellSession extends ShellSession {
|
|||||||
const args = ["exec", "-i", "-t", "-n", "kube-system", this.podId, "--", "sh", "-c", "((clear && bash) || (clear && ash) || (clear && sh))"];
|
const args = ["exec", "-i", "-t", "-n", "kube-system", this.podId, "--", "sh", "-c", "((clear && bash) || (clear && ash) || (clear && sh))"];
|
||||||
const env = await this.getCachedShellEnv();
|
const env = await this.getCachedShellEnv();
|
||||||
|
|
||||||
super.open(shell, args, env);
|
await super.open(shell, args, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected createNodeShellPod() {
|
protected createNodeShellPod() {
|
||||||
|
const imagePullSecrets = this.cluster.imagePullSecret
|
||||||
|
? [{
|
||||||
|
name: this.cluster.imagePullSecret,
|
||||||
|
}]
|
||||||
|
: undefined;
|
||||||
|
|
||||||
return this
|
return this
|
||||||
.kc
|
.kc
|
||||||
.makeApiClient(k8s.CoreV1Api)
|
.makeApiClient(k8s.CoreV1Api)
|
||||||
@ -88,9 +95,7 @@ export class NodeShellSession extends ShellSession {
|
|||||||
command: ["nsenter"],
|
command: ["nsenter"],
|
||||||
args: ["-t", "1", "-m", "-u", "-i", "-n", "sleep", "14000"]
|
args: ["-t", "1", "-m", "-u", "-i", "-n", "sleep", "14000"]
|
||||||
}],
|
}],
|
||||||
imagePullSecrets: [{
|
imagePullSecrets,
|
||||||
name: this.cluster.imagePullSecret,
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,11 +20,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Cluster } from "../../../../main/cluster";
|
import type { Cluster } from "../../../../main/cluster";
|
||||||
import { autorun, makeObservable, observable } from "mobx";
|
import { makeObservable, observable } from "mobx";
|
||||||
import { SubTitle } from "../../layout/sub-title";
|
import { SubTitle } from "../../layout/sub-title";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Input } from "../../input/input";
|
import { Input } from "../../input/input";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { Icon } from "../../icon/icon";
|
import { Icon } from "../../icon/icon";
|
||||||
import { initialNodeShellImage } from "../../../../common/cluster-types";
|
import { initialNodeShellImage } from "../../../../common/cluster-types";
|
||||||
|
|
||||||
@ -34,59 +34,42 @@ interface Props {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterNodeShellSetting extends React.Component<Props> {
|
export class ClusterNodeShellSetting extends React.Component<Props> {
|
||||||
@observable nodeShellImage = "";
|
@observable nodeShellImage = this.props.cluster.preferences?.nodeShellImage || "";
|
||||||
@observable imagePullSecret = "";
|
@observable imagePullSecret = this.props.cluster.preferences?.imagePullSecret || "";
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentWillUnmount() {
|
||||||
disposeOnUnmount(this,
|
this.props.cluster.preferences ??= {};
|
||||||
autorun(() => {
|
this.props.cluster.preferences.nodeShellImage = this.nodeShellImage || undefined;
|
||||||
this.nodeShellImage = this.props.cluster.nodeShellImage;
|
this.props.cluster.preferences.imagePullSecret = this.imagePullSecret || undefined;
|
||||||
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() {
|
render() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<section>
|
<section>
|
||||||
<SubTitle title="Node shell image" id="node-shell-image"/>
|
<SubTitle title="Node shell image" id="node-shell-image"/>
|
||||||
<Input
|
<Input
|
||||||
theme="round-black"
|
theme="round-black"
|
||||||
|
placeholder={`Default image: ${initialNodeShellImage}`}
|
||||||
value={this.nodeShellImage}
|
value={this.nodeShellImage}
|
||||||
onChange={this.onImageChange}
|
onChange={value => this.nodeShellImage = value}
|
||||||
onBlur={this.saveImage}
|
iconRight={
|
||||||
iconRight={<Icon small material="close" onClick={this.resetImage} tooltip="Reset"/>}
|
this.nodeShellImage
|
||||||
|
? (
|
||||||
|
<Icon
|
||||||
|
smallest
|
||||||
|
material="close"
|
||||||
|
onClick={() => this.nodeShellImage = ""}
|
||||||
|
tooltip="Reset"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<small className="hint">
|
<small className="hint">
|
||||||
Node shell image. Used for creating node shell pod.
|
Node shell image. Used for creating node shell pod.
|
||||||
@ -95,15 +78,25 @@ export class ClusterNodeShellSetting extends React.Component<Props> {
|
|||||||
<section>
|
<section>
|
||||||
<SubTitle title="Image pull secret" id="image-pull-secret"/>
|
<SubTitle title="Image pull secret" id="image-pull-secret"/>
|
||||||
<Input
|
<Input
|
||||||
placeholder={"Add a secret name..."}
|
placeholder="Specify a secret name..."
|
||||||
theme="round-black"
|
theme="round-black"
|
||||||
value={this.imagePullSecret}
|
value={this.imagePullSecret}
|
||||||
onChange={this.onSecretChange}
|
onChange={value => this.imagePullSecret = value}
|
||||||
onBlur={this.saveSecret}
|
iconRight={
|
||||||
iconRight={<Icon small material="close" onClick={this.clearSecret} tooltip="Clear"/>}
|
this.imagePullSecret
|
||||||
|
? (
|
||||||
|
<Icon
|
||||||
|
smallest
|
||||||
|
material="close"
|
||||||
|
onClick={() => this.imagePullSecret = ""}
|
||||||
|
tooltip="Clear"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<small className="hint">
|
<small className="hint">
|
||||||
Name of a pre-existing secret (optional). Used for pulling image from a private registry.
|
Name of a pre-existing secret. An optional setting. Used for pulling image from a private registry.
|
||||||
</small>
|
</small>
|
||||||
</section>
|
</section>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user