Skip to content

Commit

Permalink
Make download dir option consistent with other settings (#875)
Browse files Browse the repository at this point in the history
* make download dir option consitent with other settings

* make path to kubectl setting consistent

Co-authored-by: Lauri Nevala <lauri.nevala@gmail.com>
Signed-off-by: Sebastian Malton <sebastian@malton.name>

Co-authored-by: Sebastian Malton <smalton@mirantis.com>
Co-authored-by: Lauri Nevala <lauri.nevala@gmail.com>
  • Loading branch information
3 people authored Sep 23, 2020
1 parent 2f53e76 commit b88c0d4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
2 changes: 0 additions & 2 deletions src/common/user-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export class UserStore extends BaseStore<UserStoreModel> {
colorTheme: UserStore.defaultTheme,
downloadMirror: "default",
downloadKubectlBinaries: true, // Download kubectl binaries matching cluster version
downloadBinariesPath: this.getDefaultKubectlPath(),
kubectlBinariesPath: ""
};

get isNewVersion() {
Expand Down
10 changes: 7 additions & 3 deletions src/main/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const packageMirrors: Map<string, string> = new Map([
let bundledPath: string
const initScriptVersionString = "# lens-initscript v3\n"

if (isDevelopment || isTestEnv) {
if (isDevelopment || isTestEnv) {
const platformName = isWindows ? "windows" : process.platform
bundledPath = path.join(process.cwd(), "binaries", "client", platformName, process.arch, "kubectl")
} else {
Expand Down Expand Up @@ -110,7 +110,11 @@ export class Kubectl {
}

protected getDownloadDir() {
return userStore.preferences?.downloadBinariesPath || Kubectl.kubectlDir
if (userStore.preferences?.downloadBinariesPath) {
return path.join(userStore.preferences.downloadBinariesPath, "kubectl")
}

return Kubectl.kubectlDir
}

public async getPath(bundled = false): Promise<string> {
Expand Down Expand Up @@ -214,7 +218,7 @@ export class Kubectl {
});
isValid = !await this.checkBinary(this.path, false)
}
if(!isValid) {
if (!isValid) {
logger.debug(`Releasing lock for ${this.kubectlVersion}`)
release()
return false
Expand Down
52 changes: 21 additions & 31 deletions src/renderer/components/+preferences/kubectl-binaries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,22 @@ export const KubectlBinaries = observer(({ preferences }: { preferences: UserPre
{ value: "china", label: "China (Azure)" },
]


const save = () => {
preferences.downloadBinariesPath = downloadPath;
preferences.kubectlBinariesPath = binariesPath;
}

const renderPath = () => {
if (preferences.downloadKubectlBinaries) {
return null;
}
return (
<>
<SubTitle title="Path to Kubectl binary"/>
<Input
theme="round-black"
value={binariesPath}
validators={isPath}
onChange={setBinariesPath}
onBlur={save}
/>
<small className="hint">
<Trans>Default:</Trans>{" "}{Kubectl.bundledKubectlPath}
</small>
</>
);
}

return (
<>
<h2><Trans>Kubectl Binary</Trans></h2>
<small className="hint">
<Trans>Download kubectl binaries matching to Kubernetes cluster verison.</Trans>
</small>
<Checkbox
label={<Trans>Download kubectl binaries</Trans>}
value={preferences.downloadKubectlBinaries}
onChange={downloadKubectlBinaries => preferences.downloadKubectlBinaries = downloadKubectlBinaries}
/>
<small className="hint">
<Trans>Download kubectl binaries matching to Kubernetes cluster version.</Trans>
</small>
<SubTitle title="Download mirror" />
<Select
placeholder={<Trans>Download mirror for kubectl</Trans>}
Expand All @@ -64,20 +42,32 @@ export const KubectlBinaries = observer(({ preferences }: { preferences: UserPre
onChange={({ value }: SelectOption) => preferences.downloadMirror = value}
disabled={!preferences.downloadKubectlBinaries}
/>
<SubTitle title="Directory for binaries"/>
<SubTitle title="Directory for binaries" />
<Input
theme="round-black"
value={downloadPath}
placeholder={`Directory to download binaries into`}
placeholder={userStore.getDefaultKubectlPath()}
validators={isPath}
onChange={setDownloadPath}
onBlur={save}
disabled={!preferences.downloadKubectlBinaries}
/>
<small>
Default: {userStore.getDefaultKubectlPath()}
<small className="hint">
The directory to download binaries into.
</small>
<SubTitle title="Path to Kubectl binary" />
<Input
theme="round-black"
placeholder={Kubectl.bundledKubectlPath}
value={binariesPath}
validators={isPath}
onChange={setBinariesPath}
onBlur={save}
disabled={preferences.downloadKubectlBinaries}
/>
<small className="hint">
<Trans>The path to the kubectl binary on the system.</Trans>
</small>
{renderPath()}
</>
);
});
});

0 comments on commit b88c0d4

Please sign in to comment.