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

Add support for viewing 'User-supplied values' of helm release (#1862)

Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
osddeitf 2021-04-20 22:47:38 +07:00 committed by GitHub
parent a2be178191
commit 04d3cd5b14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 15 deletions

View File

@ -91,9 +91,9 @@ export class HelmReleaseManager {
return stdout; return stdout;
} }
public async getValues(name: string, namespace: string, pathToKubeconfig: string) { public async getValues(name: string, namespace: string, all: boolean, pathToKubeconfig: string) {
const helm = await helmCli.binaryPath(); const helm = await helmCli.binaryPath();
const { stdout, } = await promiseExec(`"${helm}" get values ${name} --all --output yaml --namespace ${namespace} --kubeconfig ${pathToKubeconfig}`).catch((error) => { throw(error.stderr);}); const { stdout, } = await promiseExec(`"${helm}" get values ${name} ${all? "--all": ""} --output yaml --namespace ${namespace} --kubeconfig ${pathToKubeconfig}`).catch((error) => { throw(error.stderr);});
return stdout; return stdout;
} }

View File

@ -66,12 +66,12 @@ class HelmService {
return await releaseManager.getRelease(releaseName, namespace, cluster); return await releaseManager.getRelease(releaseName, namespace, cluster);
} }
public async getReleaseValues(cluster: Cluster, releaseName: string, namespace: string) { public async getReleaseValues(cluster: Cluster, releaseName: string, namespace: string, all: boolean) {
const proxyKubeconfig = await cluster.getProxyKubeconfigPath(); const proxyKubeconfig = await cluster.getProxyKubeconfigPath();
logger.debug("Fetch release values"); logger.debug("Fetch release values");
return await releaseManager.getValues(releaseName, namespace, proxyKubeconfig); return await releaseManager.getValues(releaseName, namespace, all, proxyKubeconfig);
} }
public async getReleaseHistory(cluster: Cluster, releaseName: string, namespace: string) { public async getReleaseHistory(cluster: Cluster, releaseName: string, namespace: string) {

View File

@ -101,10 +101,10 @@ class HelmApiRoute extends LensApi {
} }
public async getReleaseValues(request: LensApiRequest) { public async getReleaseValues(request: LensApiRequest) {
const { cluster, params, response } = request; const { cluster, params, response, query } = request;
try { try {
const result = await helmService.getReleaseValues(cluster, params.release, params.namespace); const result = await helmService.getReleaseValues(cluster, params.release, params.namespace, query.has("all"));
this.respondText(response, result); this.respondText(response, result);
} catch (error) { } catch (error) {

View File

@ -112,8 +112,8 @@ export async function deleteRelease(name: string, namespace: string): Promise<Js
return apiBase.del(path); return apiBase.del(path);
} }
export async function getReleaseValues(name: string, namespace: string): Promise<string> { export async function getReleaseValues(name: string, namespace: string, all?: boolean): Promise<string> {
const path = `${endpoint({ name, namespace })}/values`; const path = `${endpoint({ name, namespace })}/values${all? "?all": ""}`;
return apiBase.get<string>(path); return apiBase.get<string>(path);
} }

View File

@ -25,6 +25,7 @@ import { SubTitle } from "../layout/sub-title";
import { secretsStore } from "../+config-secrets/secrets.store"; import { secretsStore } from "../+config-secrets/secrets.store";
import { Secret } from "../../api/endpoints"; import { Secret } from "../../api/endpoints";
import { getDetailsUrl } from "../kube-object"; import { getDetailsUrl } from "../kube-object";
import { Checkbox } from "../checkbox";
interface Props { interface Props {
release: HelmRelease; release: HelmRelease;
@ -35,6 +36,8 @@ interface Props {
export class ReleaseDetails extends Component<Props> { export class ReleaseDetails extends Component<Props> {
@observable details: IReleaseDetails; @observable details: IReleaseDetails;
@observable values = ""; @observable values = "";
@observable valuesLoading = false;
@observable userSuppliedOnly = false;
@observable saving = false; @observable saving = false;
@observable releaseSecret: Secret; @observable releaseSecret: Secret;
@ -72,7 +75,9 @@ export class ReleaseDetails extends Component<Props> {
const { release } = this.props; const { release } = this.props;
this.values = ""; this.values = "";
this.values = await getReleaseValues(release.getName(), release.getNs()); this.valuesLoading = true;
this.values = (await getReleaseValues(release.getName(), release.getNs(), !this.userSuppliedOnly)) ?? "";
this.valuesLoading = false;
} }
updateValues = async () => { updateValues = async () => {
@ -107,21 +112,34 @@ export class ReleaseDetails extends Component<Props> {
}; };
renderValues() { renderValues() {
const { values, saving } = this; const { values, valuesLoading, saving } = this;
return ( return (
<div className="values"> <div className="values">
<DrawerTitle title="Values"/> <DrawerTitle title="Values"/>
<div className="flex column gaps"> <div className="flex column gaps">
<AceEditor <Checkbox
mode="yaml" label="User-supplied values only"
value={values} value={this.userSuppliedOnly}
onChange={values => this.values = values} onChange={values => {
this.userSuppliedOnly = values;
this.loadValues();
}}
disabled={valuesLoading}
/> />
{valuesLoading
? <Spinner />
: <AceEditor
mode="yaml"
value={values}
onChange={values => this.values = values}
/>
}
<Button <Button
primary primary
label="Save" label="Save"
waiting={saving} waiting={saving}
disabled={valuesLoading}
onClick={this.updateValues} onClick={this.updateValues}
/> />
</div> </div>

View File

@ -89,7 +89,7 @@ export class UpgradeChartStore extends DockTabStore<IChartUpgradeData> {
async loadValues(tabId: TabId) { async loadValues(tabId: TabId) {
this.values.clearData(tabId); // reset this.values.clearData(tabId); // reset
const { releaseName, releaseNamespace } = this.getData(tabId); const { releaseName, releaseNamespace } = this.getData(tabId);
const values = await getReleaseValues(releaseName, releaseNamespace); const values = await getReleaseValues(releaseName, releaseNamespace, true);
this.values.setData(tabId, values); this.values.setData(tabId, values);
} }